2023-09-26 (C) Questetra, Inc. (MIT License) 3 2 This item removes categories from an email message in Outlook. Multiple categories can be removed at once. この工程は、Outlook のメールからカテゴリを外します。一度に複数のカテゴリを解除可能です。 https://support.questetra.com/bpmn-icons/service-task-outlook-message-category-remove/ https://support.questetra.com/ja/bpmn-icons/service-task-outlook-message-category-remove/ iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAA/RJREFUWEfN l1tsDFEYx/+z7W7X7rZFS1nLA42kCU0QEg9oS4IgfXF5ERVxefAg7n1o0bhkoy6RkIhEiMSt4pII xYNu9cElrqUqhApFabub7W679z1yzsys2Z2ZnWlTYV52Zuec7/t95/y/73zD4R9fXL/8V34tAbjd kjklwr2L/yWNAFxwjhWeta3rA6j8uifFsbZlkBo4x+7RGpge4E/EYqRa9hTepwdRBxhQ1Gp86hDK AIPqXIRShpAD/BXn6hDJADqcP9k4AsWjjLq04A8TTKj9CW8wLhlPSqVZkgLQTrQsxw+MAacvd5ip BWe6cfd9UGrWBaejVPzjjykd0dNJFOBJexg763vgWp+Pps9hVN/rYfburMnDT38cFXUeLC4yY9ss mxIArReJFJUAJEc/qcCIeYVZsgU5sigX77uiOPm4F0cX56KuOYAVF91snK/GjjZ3FMXHfqFiqgVn lw1TAQDgdDDfPACf7w1Sb/4aO6wm7bUORgk6e/k9duRkIEaAH74YbCYOw4YY1AHAa0EEkFW60D47 TBn8a0KANk8U0ThQmJcJg4QrHCNw9/EABTYeoKs3BqvJgOwsLg0ALdmOUgGgnUafVO1EgEiMYMaJ TpSMz4LZyOHamwCaN41EViY/dcBbwM4MHQDHH/YiECHYPtvGHNJnuuxUYPRq+BTCjnpehE0b8vHD F8fyC26UF5lRVZaN/Q0+VAkiTRFUEoAs/cQVWHreja2zbJg5zsTmP/oSRu0DP66uHK6VsYn32257 cbjJLx/vdAgZXSnPfxGA0tN9Xz3NwgxcehXAh+4oqsuy2fPrjghOP+1j9wcX5sATIGj8FMLy4iEJ h4ea/Nh+25sWQFUDPSGCwtoOnCgfygxsueVF65YCpnJ6NbaFUHKqi93TNLQaOVao4gS48LIPK6dY oAKgTwPUcChKcP9jiKmfilEUoBjSZ08M9z4EsW66lTl//j2C8nPdTCudVaMHBhDYa4dZULraZtMU vN4SxArJclMBXnkdYFPyrYY0AHw1VC1E1OiSInPCd77FgPkTzWzPmzsi7P+brUFcbg5git2ImxV5 GJOTAV+IYFWdGzfeBrUAJIWIWlMQojRyegK+2jQSO+q9LAuUrl1zs1FdloNMA/DwSxhrr3rQsrlA eQuSSjEDSN/3iQAvvkfw7FtYNQVzzQYsm8xnABUi1Y1chEqHEb8KsmwQPVmMHDy7RyfKsypBygta xpec68atd5IjWYieDk1tSGSHkl5H+sclt2b/WUsmhqGzOdEfNR2ptyn9KxD9bcsHD8IlRK76qabd 8uhIUeWtGIxPs1TLrHWjjQs3R3iV8nGa2OtB/jjtn9r6Nfo39MDfMN80fiMAAAAASUVORK5CYII= { // 認証設定を作成し、指定 const oauth2 = httpClient.createAuthSettingOAuth2( 'Outlook', 'https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize', 'https://login.microsoftonline.com/organizations/oauth2/v2.0/token', 'https://graph.microsoft.com/Mail.ReadWrite offline_access', 'client_id', 'client_secret', 'access_token' ); configs.putObject('conf_OAuth2', oauth2); // メール ID を設定 const messageIdDef = engine.createDataDefinition('メール ID', 1, 'q_MessageId', 'STRING_TEXTFIELD'); engine.setData(messageIdDef, messageId); configs.putObject('conf_MessageId', messageIdDef); // カテゴリを設定 configs.put('conf_Category', categoryStr); }; /** * 異常系のテスト * @param func * @param errorMsg */ const assertError = (func, errorMsg) => { try { func(); fail(); } catch (e) { expect(e.toString()).toEqual(errorMsg); } }; /** * メール ID が空であればエラー */ test('Message ID is empty', () => { prepareConfigs(null, '赤の分類'); assertError(main, 'Message ID is blank.'); }); /** * カテゴリが空であればエラー */ test('No categories', () => { prepareConfigs('messageId-1', ''); assertError(main, 'Empty lines are not allowed for category.'); }); /** * カテゴリが改行のみであればエラー */ test('No categories - line break only', () => { prepareConfigs('messageId-1', '\n'); assertError(main, 'Empty lines are not allowed for category.'); }); /** * カテゴリの途中に空行を含む場合はエラー */ test('Categories include an empty line', () => { prepareConfigs('messageId-1', '赤の分類\n\n青の分類'); assertError(main, 'Empty lines are not allowed for category.'); }); /** * メッセージ取得の GET リクエストのテスト * @param {Object} request * @param request.url * @param request.method * @param messageId */ const assertGetMessageRequest = ({url, method}, messageId) => { const expectedUrl = `https://graph.microsoft.com/v1.0/me/messages/${encodeURI(messageId)}` + `?${encodeURIComponent('$select')}=categories`; expect(url).toEqual(expectedUrl); expect(method).toEqual('GET'); }; /** * メール取得の GET リクエストで失敗 */ test('Fail in GET message request', () => { const messageId = 'messageId-1'; prepareConfigs(messageId, '赤の分類'); httpClient.setRequestHandler((request) => { assertGetMessageRequest(request, messageId); return httpClient.createHttpResponse(400, 'application/json', `{}`); }); assertError(main, 'Failed to get message. status: 400'); }); /** * メッセージ更新の PATCH リクエストのテスト * @param {Object} request * @param request.url * @param request.method * @param messageId * @param categories */ const assertUpdateMessageRequest = ({url, method, body}, messageId, categories) => { const expectedUrl = `https://graph.microsoft.com/v1.0/me/messages/${encodeURI(messageId)}`; expect(url).toEqual(expectedUrl); expect(method).toEqual('PATCH'); const bodyObj = JSON.parse(body); expect(bodyObj.categories).toEqual(categories); }; const SAMPLE_MESSAGE = { "categories": [ "赤の分類", "青の分類", "緑の分類" ] }; /** * メール更新の PATCH リクエストで失敗 */ test('Fail in PATCH message request', () => { const messageId = 'messageId-1'; prepareConfigs(messageId, '赤の分類'); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetMessageRequest(request, messageId); reqCount++; return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(SAMPLE_MESSAGE)); } assertUpdateMessageRequest(request, messageId, ['青の分類', '緑の分類']); return httpClient.createHttpResponse(400, 'application/json', `{}`); }); assertError(main, 'Failed to update message. status: 400'); }); /** * 成功 * カテゴリを 1 つだけ解除 */ test('Succeed - remove one category', () => { const messageId = 'messageId-1'; const dataDefs = prepareConfigs(messageId, '赤の分類\n'); // カテゴリの末尾の改行は無視される let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetMessageRequest(request, messageId); reqCount++; return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(SAMPLE_MESSAGE)); } assertUpdateMessageRequest(request, messageId, ['青の分類', '緑の分類']); return httpClient.createHttpResponse(200, 'application/json', '{}'); }); expect(main()).toEqual(undefined); }); /** * 成功 * カテゴリを複数解除し、カテゴリ設定が 1 つもなくなる場合 */ test('Succeed - remove all categories', () => { const messageId = 'messageId-2'; const dataDefs = prepareConfigs(messageId, '赤の分類\n緑の分類\n青の分類'); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetMessageRequest(request, messageId); reqCount++; return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(SAMPLE_MESSAGE)); } assertUpdateMessageRequest(request, messageId, []); return httpClient.createHttpResponse(200, 'application/json', '{}'); }); expect(main()).toEqual(undefined); }); /** * 成功 * メールに設定されていないカテゴリのみを指定した場合、メールを更新せずに正常終了 */ test('Succeed - message does not have the specified category', () => { const messageId = 'messageId-2'; const dataDefs = prepareConfigs(messageId, 'オレンジの分類'); httpClient.setRequestHandler((request) => { assertGetMessageRequest(request, messageId); return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(SAMPLE_MESSAGE)); }); expect(main()).toEqual(undefined); }); /** * 成功 * メールに設定されているカテゴリ、メールに設定されていないカテゴリを両方指定した場合 */ test('Succeed - message includes one of the specified categories', () => { const messageId = 'messageId-3'; const dataDefs = prepareConfigs(messageId, '青の分類\nオレンジの分類'); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assertGetMessageRequest(request, messageId); reqCount++; return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(SAMPLE_MESSAGE)); } assertUpdateMessageRequest(request, messageId, ['赤の分類', '緑の分類']); return httpClient.createHttpResponse(200, 'application/json', '{}'); }); expect(main()).toEqual(undefined); }); ]]>