From 5c445314f88ee4c9d93c47b9c08dc81a8cc0a650 Mon Sep 17 00:00:00 2001 From: Elias Meire Date: Wed, 18 Dec 2024 16:09:23 +0100 Subject: [PATCH] test(Gmail Node): Add test coverage (no-changelog) (#12278) --- packages/nodes-base/jest.config.js | 3 + .../Google/Gmail/test/v2/GmailV2.node.test.ts | 396 ++++++ .../Google/Gmail/test/v2/drafts.workflow.json | 386 ++++++ .../Google/Gmail/test/v2/fixtures/labels.json | 14 + .../Gmail/test/v2/fixtures/messages.json | 240 ++++ .../Google/Gmail/test/v2/labels.workflow.json | 163 +++ .../Gmail/test/v2/messages.workflow.json | 1151 ++++++++++++++++ .../Gmail/test/v2/threads.workflow.json | 1174 +++++++++++++++++ .../nodes/Google/Gmail/v2/GmailV2.node.ts | 103 +- .../nodes/Google/Gmail/v2/loadOptions.ts | 75 ++ .../test/nodes/FakeCredentialsMap.ts | 19 + packages/nodes-base/test/nodes/Helpers.ts | 2 +- 12 files changed, 3636 insertions(+), 90 deletions(-) create mode 100644 packages/nodes-base/nodes/Google/Gmail/test/v2/GmailV2.node.test.ts create mode 100644 packages/nodes-base/nodes/Google/Gmail/test/v2/drafts.workflow.json create mode 100644 packages/nodes-base/nodes/Google/Gmail/test/v2/fixtures/labels.json create mode 100644 packages/nodes-base/nodes/Google/Gmail/test/v2/fixtures/messages.json create mode 100644 packages/nodes-base/nodes/Google/Gmail/test/v2/labels.workflow.json create mode 100644 packages/nodes-base/nodes/Google/Gmail/test/v2/messages.workflow.json create mode 100644 packages/nodes-base/nodes/Google/Gmail/test/v2/threads.workflow.json create mode 100644 packages/nodes-base/nodes/Google/Gmail/v2/loadOptions.ts diff --git a/packages/nodes-base/jest.config.js b/packages/nodes-base/jest.config.js index 860b43c630..721030d49c 100644 --- a/packages/nodes-base/jest.config.js +++ b/packages/nodes-base/jest.config.js @@ -1,3 +1,6 @@ +// Avoid tests failing because of difference between local and GitHub actions timezone +process.env.TZ = 'UTC'; + /** @type {import('jest').Config} */ module.exports = { ...require('../../jest.config'), diff --git a/packages/nodes-base/nodes/Google/Gmail/test/v2/GmailV2.node.test.ts b/packages/nodes-base/nodes/Google/Gmail/test/v2/GmailV2.node.test.ts new file mode 100644 index 0000000000..b14fe8132c --- /dev/null +++ b/packages/nodes-base/nodes/Google/Gmail/test/v2/GmailV2.node.test.ts @@ -0,0 +1,396 @@ +/* eslint-disable n8n-nodes-base/node-param-display-name-miscased */ +import { mock, mockDeep } from 'jest-mock-extended'; +import { jsonParse, type ILoadOptionsFunctions, type INode } from 'n8n-workflow'; +import nock from 'nock'; + +import { testWorkflows } from '@test/nodes/Helpers'; + +import labels from './fixtures/labels.json'; +import messages from './fixtures/messages.json'; +import { getGmailAliases, getLabels, getThreadMessages } from '../../v2/loadOptions'; + +describe('Test Gmail Node v2', () => { + beforeAll(() => { + jest + .useFakeTimers({ doNotFake: ['setImmediate', 'nextTick'] }) + .setSystemTime(new Date('2024-12-16 12:34:56.789Z')); + + nock.disableNetConnect(); + }); + + afterAll(() => { + nock.restore(); + jest.resetAllMocks(); + }); + + describe('Messages', () => { + const gmailNock = nock('https://www.googleapis.com/gmail'); + + beforeAll(() => { + gmailNock.get('/v1/users/me/messages').query({ maxResults: 2 }).reply(200, { + messages, + }); + gmailNock + .get('/v1/users/me/messages') + .query({ + includeSpamTrash: 'true', + labelIds: 'CHAT', + q: 'test from:Test Sender after:1734393600 before:1735171200', + readStatus: 'both', + dataPropertyAttachmentsPrefixName: 'attachment_', + downloadAttachments: 'true', + maxResults: '2', + }) + .reply(200, { messages }); + gmailNock + .get('/v1/users/me/messages/a1b2c3d4e5f6g7h8') + .query({ + maxResults: '2', + format: 'metadata', + metadataHeaders: ['From', 'To', 'Cc', 'Bcc', 'Subject'], + }) + .reply(200, messages[0]); + gmailNock + .get('/v1/users/me/messages/a1b2c3d4e5f6g7h8') + .query({ + includeSpamTrash: 'true', + labelIds: 'CHAT', + q: 'test from:Test Sender after:1734393600 before:1735171200', + readStatus: 'both', + dataPropertyAttachmentsPrefixName: 'attachment_', + downloadAttachments: 'true', + maxResults: '2', + format: 'raw', + }) + .reply(200, { + ...messages[0], + raw: 'TUlNRS1WZXJzaW9uOiAxLjANCkRhdGU6IEZyaSwgMTMgRGVjIDIwMjQgMTE6MTU6MDEgKzAxMDANCk1lc3NhZ2UtSUQ6IDxDQUVHQVByb3d1ZEduS1h4cXJoTWpPdXhhbVRoN3lBcmp3UDdPRDlVQnEtSnBrYjBYOXdAbWFpbC5nbWFpbC5jb20-DQpTdWJqZWN0OiBUZXN0IGRyYWZ0DQpGcm9tOiBub2RlIHFhIDxub2RlOHFhQGdtYWlsLmNvbT4NClRvOiB0ZXN0QGdtYWlsLmNvbQ0KQ29udGVudC1UeXBlOiBtdWx0aXBhcnQvYWx0ZXJuYXRpdmU7IGJvdW5kYXJ5PSIwMDAwMDAwMDAwMDA5ZDU4YjYwNjI5MjQxYTIyIg0KDQotLTAwMDAwMDAwMDAwMDlkNThiNjA2MjkyNDFhMjINCkNvbnRlbnQtVHlwZTogdGV4dC9wbGFpbjsgY2hhcnNldD0iVVRGLTgiDQoNCmRyYWZ0IGJvZHkNCg0KLS0wMDAwMDAwMDAwMDA5ZDU4YjYwNjI5MjQxYTIyDQpDb250ZW50LVR5cGU6IHRleHQvaHRtbDsgY2hhcnNldD0iVVRGLTgiDQoNCjxkaXYgZGlyPSJsdHIiPmRyYWZ0IGJvZHk8YnI-PC9kaXY-DQoNCi0tMDAwMDAwMDAwMDAwOWQ1OGI2MDYyOTI0MWEyMi0t', + }); + gmailNock + .get('/v1/users/me/messages/z9y8x7w6v5u4t3s2') + .query({ + includeSpamTrash: 'true', + labelIds: 'CHAT', + q: 'test from:Test Sender after:1734393600 before:1735171200', + readStatus: 'both', + dataPropertyAttachmentsPrefixName: 'attachment_', + downloadAttachments: 'true', + maxResults: '2', + format: 'raw', + }) + .reply(200, { + ...messages[1], + raw: 'TUlNRS1WZXJzaW9uOiAxLjANCkRhdGU6IEZyaSwgMTMgRGVjIDIwMjQgMTE6MTU6MDEgKzAxMDANCk1lc3NhZ2UtSUQ6IDxDQUVHQVByb3d1ZEduS1h4cXJoTWpPdXhhbVRoN3lBcmp3UDdPRDlVQnEtSnBrYjBYOXdAbWFpbC5nbWFpbC5jb20-DQpTdWJqZWN0OiBUZXN0IGRyYWZ0DQpGcm9tOiBub2RlIHFhIDxub2RlOHFhQGdtYWlsLmNvbT4NClRvOiB0ZXN0QGdtYWlsLmNvbQ0KQ29udGVudC1UeXBlOiBtdWx0aXBhcnQvYWx0ZXJuYXRpdmU7IGJvdW5kYXJ5PSIwMDAwMDAwMDAwMDA5ZDU4YjYwNjI5MjQxYTIyIg0KDQotLTAwMDAwMDAwMDAwMDlkNThiNjA2MjkyNDFhMjINCkNvbnRlbnQtVHlwZTogdGV4dC9wbGFpbjsgY2hhcnNldD0iVVRGLTgiDQoNCmRyYWZ0IGJvZHkNCg0KLS0wMDAwMDAwMDAwMDA5ZDU4YjYwNjI5MjQxYTIyDQpDb250ZW50LVR5cGU6IHRleHQvaHRtbDsgY2hhcnNldD0iVVRGLTgiDQoNCjxkaXYgZGlyPSJsdHIiPmRyYWZ0IGJvZHk8YnI-PC9kaXY-DQoNCi0tMDAwMDAwMDAwMDAwOWQ1OGI2MDYyOTI0MWEyMi0t', + }); + gmailNock + .get('/v1/users/me/messages/z9y8x7w6v5u4t3s2') + .query({ + maxResults: '2', + format: 'metadata', + metadataHeaders: ['From', 'To', 'Cc', 'Bcc', 'Subject'], + }) + .reply(200, messages[0]); + gmailNock.get('/v1/users/me/labels').reply(200, { + labels, + }); + gmailNock.get('/v1/users/me/profile').times(2).reply(200, { emailAddress: 'test@n8n.io' }); + gmailNock + .post('/v1/users/me/messages/send') + .query({ format: 'metadata' }) + .reply(200, messages[0]); + gmailNock.post('/v1/users/me/messages/send').reply(200, messages[0]); + gmailNock + .post('/v1/users/me/messages/send') + .query({ userId: 'me', uploadType: 'media' }) + .reply(200, messages[0]); + gmailNock + .post('/v1/users/me/messages/test/modify', (body) => 'addLabelIds' in body) + .reply(200, messages[0]); + gmailNock + .post('/v1/users/me/messages/test/modify', (body) => 'removeLabelIds' in body) + .reply(200, messages[0]); + gmailNock.delete('/v1/users/me/messages/test').reply(200, messages[0]); + gmailNock + .get('/v1/users/me/messages/test') + .query({ + format: 'metadata', + metadataHeaders: ['From', 'To', 'Cc', 'Bcc', 'Subject'], + }) + .reply(200, messages[0]); + gmailNock.get('/v1/users/me/labels').reply(200, { labels }); + gmailNock + .get('/v1/users/me/messages/test') + .query({ format: 'raw' }) + .reply(200, { raw: 'test email content' }); + gmailNock + .post('/v1/users/me/messages/test/modify', { removeLabelIds: ['UNREAD'] }) + .reply(200, messages[0]); + gmailNock + .post('/v1/users/me/messages/test/modify', { addLabelIds: ['UNREAD'] }) + .reply(200, messages[0]); + gmailNock + .get('/v1/users/me/messages/test') + .query({ + format: 'metadata', + }) + .reply(200, messages[0]); + }); + + testWorkflows(['nodes/Google/Gmail/test/v2/messages.workflow.json']); + + it('should make the correct network calls', () => { + gmailNock.done(); + }); + }); + + describe('Labels', () => { + const gmailNock = nock('https://www.googleapis.com/gmail'); + + beforeAll(() => { + gmailNock + .post('/v1/users/me/labels', { + labelListVisibility: 'labelShow', + messageListVisibility: 'show', + name: 'Test Label Name', + }) + .reply(200, labels[0]); + gmailNock.delete('/v1/users/me/labels/test-label-id').reply(200, labels[0]); + gmailNock.get('/v1/users/me/labels/test-label-id').reply(200, labels[0]); + gmailNock.get('/v1/users/me/labels').reply(200, { + labels, + }); + }); + + testWorkflows(['nodes/Google/Gmail/test/v2/labels.workflow.json']); + + it('should make the correct network calls', () => { + gmailNock.done(); + }); + }); + + describe('Drafts', () => { + const gmailNock = nock('https://www.googleapis.com/gmail'); + + beforeAll(() => { + gmailNock + .filteringRequestBody((body) => { + try { + const parsedBody = jsonParse<{ message: { raw: string; threadId: string } }>(body); + const mail = Buffer.from(parsedBody.message.raw, 'base64').toString('utf-8'); + + // Remove dynamic fields from mail + parsedBody.message.raw = Buffer.from( + mail + .replace(/boundary=".*"/g, 'boundary="--test-boundary"') + .replace(/----.*/g, '----test-boundary') + .replace(/Message-ID:.*/g, 'Message-ID: test-message-id'), + 'utf-8', + ).toString('base64'); + + return JSON.stringify(parsedBody); + } catch (error) { + return body; + } + }) + .post('/v1/users/me/drafts', { + message: { + raw: 'Q29udGVudC1UeXBlOiBtdWx0aXBhcnQvbWl4ZWQ7IGJvdW5kYXJ5PSItLXRlc3QtYm91bmRhcnkiDQpGcm9tOiB0ZXN0LWFsaWFzQG44bi5pbw0KVG86IHRlc3QtdG9AbjhuLmlvDQpDYzogdGVzdC1jY0BuOG4uaW8NCkJjYzogdGVzdC1iY2NAbjhuLmlvDQpSZXBseS1UbzogdGVzdC1yZXBseUBuOG4uaW8NClN1YmplY3Q6IFRlc3QgRHJhZnQgU3ViamVjdA0KTWVzc2FnZS1JRDogdGVzdC1tZXNzYWdlLWlkDQpEYXRlOiBNb24sIDE2IERlYyAyMDI0IDEyOjM0OjU2ICswMDAwDQpNSU1FLVZlcnNpb246IDEuMA0KDQotLS0tdGVzdC1ib3VuZGFyeQ0KQ29udGVudC1UeXBlOiB0ZXh0L3BsYWluOyBjaGFyc2V0PXV0Zi04DQpDb250ZW50LVRyYW5zZmVyLUVuY29kaW5nOiA3Yml0DQoNClRlc3QgRHJhZnQgTWVzc2FnZQ0KLS0tLXRlc3QtYm91bmRhcnkNCkNvbnRlbnQtVHlwZTogYXBwbGljYXRpb24vanNvbjsgbmFtZT1maWxlLmpzb24NCkNvbnRlbnQtVHJhbnNmZXItRW5jb2Rpbmc6IGJhc2U2NA0KQ29udGVudC1EaXNwb3NpdGlvbjogYXR0YWNobWVudDsgZmlsZW5hbWU9ZmlsZS5qc29uDQoNClczc2lZbWx1WVhKNUlqcDBjblZsZlYwPQ0KLS0tLXRlc3QtYm91bmRhcnkNCg==', + threadId: 'test-thread-id', + }, + }) + .query({ userId: 'me', uploadType: 'media' }) + .reply(200, messages[0]); + gmailNock.delete('/v1/users/me/drafts/test-draft-id').reply(200, messages[0]); + gmailNock + .get('/v1/users/me/drafts/test-draft-id') + .query({ format: 'raw' }) + .reply(200, { + message: { + ...messages[0], + raw: 'TUlNRS1WZXJzaW9uOiAxLjANCkRhdGU6IEZyaSwgMTMgRGVjIDIwMjQgMTE6MTU6MDEgKzAxMDANCk1lc3NhZ2UtSUQ6IDxDQUVHQVByb3d1ZEduS1h4cXJoTWpPdXhhbVRoN3lBcmp3UDdPRDlVQnEtSnBrYjBYOXdAbWFpbC5nbWFpbC5jb20-DQpTdWJqZWN0OiBUZXN0IGRyYWZ0DQpGcm9tOiBub2RlIHFhIDxub2RlOHFhQGdtYWlsLmNvbT4NClRvOiB0ZXN0QGdtYWlsLmNvbQ0KQ29udGVudC1UeXBlOiBtdWx0aXBhcnQvYWx0ZXJuYXRpdmU7IGJvdW5kYXJ5PSIwMDAwMDAwMDAwMDA5ZDU4YjYwNjI5MjQxYTIyIg0KDQotLTAwMDAwMDAwMDAwMDlkNThiNjA2MjkyNDFhMjINCkNvbnRlbnQtVHlwZTogdGV4dC9wbGFpbjsgY2hhcnNldD0iVVRGLTgiDQoNCmRyYWZ0IGJvZHkNCg0KLS0wMDAwMDAwMDAwMDA5ZDU4YjYwNjI5MjQxYTIyDQpDb250ZW50LVR5cGU6IHRleHQvaHRtbDsgY2hhcnNldD0iVVRGLTgiDQoNCjxkaXYgZGlyPSJsdHIiPmRyYWZ0IGJvZHk8YnI-PC9kaXY-DQoNCi0tMDAwMDAwMDAwMDAwOWQ1OGI2MDYyOTI0MWEyMi0t', + }, + }); + gmailNock + .get('/v1/users/me/drafts') + .query({ + dataPropertyAttachmentsPrefixName: 'attachment_', + downloadAttachments: true, + includeSpamTrash: true, + maxResults: 100, + }) + .reply(200, { drafts: messages }); + gmailNock + .get('/v1/users/me/drafts/a1b2c3d4e5f6g7h8') + .query({ + dataPropertyAttachmentsPrefixName: 'attachment_', + downloadAttachments: true, + includeSpamTrash: true, + maxResults: 100, + format: 'raw', + }) + .reply(200, { + message: { + ...messages[0], + raw: 'TUlNRS1WZXJzaW9uOiAxLjANCkRhdGU6IEZyaSwgMTMgRGVjIDIwMjQgMTE6MTU6MDEgKzAxMDANCk1lc3NhZ2UtSUQ6IDxDQUVHQVByb3d1ZEduS1h4cXJoTWpPdXhhbVRoN3lBcmp3UDdPRDlVQnEtSnBrYjBYOXdAbWFpbC5nbWFpbC5jb20-DQpTdWJqZWN0OiBUZXN0IGRyYWZ0DQpGcm9tOiBub2RlIHFhIDxub2RlOHFhQGdtYWlsLmNvbT4NClRvOiB0ZXN0QGdtYWlsLmNvbQ0KQ29udGVudC1UeXBlOiBtdWx0aXBhcnQvYWx0ZXJuYXRpdmU7IGJvdW5kYXJ5PSIwMDAwMDAwMDAwMDA5ZDU4YjYwNjI5MjQxYTIyIg0KDQotLTAwMDAwMDAwMDAwMDlkNThiNjA2MjkyNDFhMjINCkNvbnRlbnQtVHlwZTogdGV4dC9wbGFpbjsgY2hhcnNldD0iVVRGLTgiDQoNCmRyYWZ0IGJvZHkNCg0KLS0wMDAwMDAwMDAwMDA5ZDU4YjYwNjI5MjQxYTIyDQpDb250ZW50LVR5cGU6IHRleHQvaHRtbDsgY2hhcnNldD0iVVRGLTgiDQoNCjxkaXYgZGlyPSJsdHIiPmRyYWZ0IGJvZHk8YnI-PC9kaXY-DQoNCi0tMDAwMDAwMDAwMDAwOWQ1OGI2MDYyOTI0MWEyMi0t', + }, + }); + gmailNock + .get('/v1/users/me/drafts/z9y8x7w6v5u4t3s2') + .query({ + dataPropertyAttachmentsPrefixName: 'attachment_', + downloadAttachments: true, + includeSpamTrash: true, + maxResults: 100, + format: 'raw', + }) + .reply(200, { + message: { + ...messages[1], + raw: 'TUlNRS1WZXJzaW9uOiAxLjANCkRhdGU6IEZyaSwgMTMgRGVjIDIwMjQgMTE6MTU6MDEgKzAxMDANCk1lc3NhZ2UtSUQ6IDxDQUVHQVByb3d1ZEduS1h4cXJoTWpPdXhhbVRoN3lBcmp3UDdPRDlVQnEtSnBrYjBYOXdAbWFpbC5nbWFpbC5jb20-DQpTdWJqZWN0OiBUZXN0IGRyYWZ0DQpGcm9tOiBub2RlIHFhIDxub2RlOHFhQGdtYWlsLmNvbT4NClRvOiB0ZXN0QGdtYWlsLmNvbQ0KQ29udGVudC1UeXBlOiBtdWx0aXBhcnQvYWx0ZXJuYXRpdmU7IGJvdW5kYXJ5PSIwMDAwMDAwMDAwMDA5ZDU4YjYwNjI5MjQxYTIyIg0KDQotLTAwMDAwMDAwMDAwMDlkNThiNjA2MjkyNDFhMjINCkNvbnRlbnQtVHlwZTogdGV4dC9wbGFpbjsgY2hhcnNldD0iVVRGLTgiDQoNCmRyYWZ0IGJvZHkNCg0KLS0wMDAwMDAwMDAwMDA5ZDU4YjYwNjI5MjQxYTIyDQpDb250ZW50LVR5cGU6IHRleHQvaHRtbDsgY2hhcnNldD0iVVRGLTgiDQoNCjxkaXYgZGlyPSJsdHIiPmRyYWZ0IGJvZHk8YnI-PC9kaXY-DQoNCi0tMDAwMDAwMDAwMDAwOWQ1OGI2MDYyOTI0MWEyMi0t', + }, + }); + }); + + testWorkflows(['nodes/Google/Gmail/test/v2/drafts.workflow.json']); + + it('should make the correct network calls', () => { + gmailNock.done(); + }); + }); + + describe('Threads', () => { + const gmailNock = nock('https://www.googleapis.com/gmail'); + + beforeAll(() => { + gmailNock.get('/v1/users/me/threads').query({ maxResults: 2 }).reply(200, { + threads: messages, + }); + gmailNock + .get('/v1/users/me/threads') + .query((query) => { + return ( + query.includeSpamTrash === 'true' && + query.labelIds === 'CHAT' && + !!query.q && + query.q.includes('has:attachment') && + query.q.includes('before:') && + query.q.includes('after:') + ); + }) + .reply(200, { threads: messages }); + gmailNock + .post('/v1/users/me/threads/test-thread-id/modify', { addLabelIds: ['CHAT'] }) + .reply(200, messages[0]); + gmailNock + .post('/v1/users/me/threads/test-thread-id/modify', { removeLabelIds: ['CHAT'] }) + .reply(200, messages[0]); + gmailNock.delete('/v1/users/me/threads/test-thread-id').reply(200, messages[0]); + gmailNock + .get('/v1/users/me/threads/test-thread-id') + .query({ + format: 'metadata', + metadataHeaders: ['From', 'To', 'Cc', 'Bcc', 'Subject'], + }) + .reply(200, messages[0]); + gmailNock.get('/v1/users/me/labels').times(2).reply(200, { labels }); + gmailNock + .get('/v1/users/me/threads/test-thread-id') + .query({ format: 'full' }) + .reply(200, messages[0]); + gmailNock.post('/v1/users/me/threads/test-thread-id/trash').reply(200, messages[0]); + gmailNock.post('/v1/users/me/threads/test-thread-id/untrash').reply(200, messages[0]); + gmailNock + .get('/v1/users/me/messages/test%20snippet') + .query({ + userId: 'me', + uploadType: 'media', + format: 'metadata', + }) + .reply(200, messages[0]); + gmailNock.get('/v1/users/me/profile').reply(200, { emailAddress: 'test@n8n.io' }); + gmailNock + .post('/v1/users/me/messages/send') + .query({ userId: 'me', uploadType: 'media', format: 'metadata' }) + .reply(200, messages[0]); + }); + + testWorkflows(['nodes/Google/Gmail/test/v2/threads.workflow.json']); + + it('should make the correct network calls', () => { + gmailNock.done(); + }); + }); + + describe('loadOptions', () => { + describe('getLabels', () => { + it('should return a list of Gmail labels', async () => { + const loadOptionsFunctions = mockDeep({ + getNode: jest.fn(() => mock()), + helpers: mock({ + requestWithAuthentication: jest + .fn() + // 2 pages of labels + .mockImplementationOnce(async () => ({ labels, nextPageToken: 'nextPageToken' })) + .mockImplementationOnce(async () => ({ labels })), + }), + }); + + expect(await getLabels.call(loadOptionsFunctions)).toEqual([ + { name: 'CHAT', value: 'CHAT' }, + { name: 'CHAT', value: 'CHAT' }, + { name: 'SENT', value: 'SENT' }, + { name: 'SENT', value: 'SENT' }, + ]); + }); + }); + + describe('getThreadMessages', () => { + it('should return a list of Gmail thread messages', async () => { + const loadOptionsFunctions = mockDeep({ + getNode: jest.fn(() => mock()), + helpers: mock({ + requestWithAuthentication: jest.fn(async () => ({ messages })), + }), + }); + + expect(await getThreadMessages.call(loadOptionsFunctions)).toEqual([ + { + name: "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + value: 'a1b2c3d4e5f6g7h8', + }, + { + name: 'Your friend John just shared a new photo with you! Check it out now.', + value: 'z9y8x7w6v5u4t3s2', + }, + ]); + }); + }); + + describe('getGmailAliases', () => { + it('should return a list of Gmail aliases', async () => { + const loadOptionsFunctions = mockDeep({ + getNode: jest.fn(() => mock()), + helpers: mock({ + requestWithAuthentication: jest.fn(async () => ({ + sendAs: [ + { isDefault: false, sendAsEmail: 'alias1@n8n.io' }, + { isDefault: true, sendAsEmail: 'alias2@n8n.io' }, + ], + })), + }), + }); + + expect(await getGmailAliases.call(loadOptionsFunctions)).toEqual([ + { + name: 'alias1@n8n.io', + value: 'alias1@n8n.io', + }, + { + name: 'alias2@n8n.io (Default)', + value: 'alias2@n8n.io', + }, + ]); + }); + }); + }); +}); diff --git a/packages/nodes-base/nodes/Google/Gmail/test/v2/drafts.workflow.json b/packages/nodes-base/nodes/Google/Gmail/test/v2/drafts.workflow.json new file mode 100644 index 0000000000..8000286e88 --- /dev/null +++ b/packages/nodes-base/nodes/Google/Gmail/test/v2/drafts.workflow.json @@ -0,0 +1,386 @@ +{ + "name": "My workflow 130", + "nodes": [ + { + "parameters": {}, + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [-60, 100], + "id": "636b40bc-2c98-4b9a-8ce2-9d1322294518", + "name": "When clicking ‘Test workflow’" + }, + { + "parameters": { + "resource": "draft", + "operation": "get", + "messageId": "test-draft-id", + "options": {} + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [440, 200], + "id": "8802fdb5-2741-407b-82a4-ccedc4055076", + "name": "Gmail - Drafts - Get", + "webhookId": "3b8b38e0-2f4b-40bc-8b67-37e7ea95cb60", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "resource": "draft", + "operation": "delete", + "messageId": "test-draft-id" + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [440, 20], + "id": "ed979c3a-b2ea-413e-be63-0392cc1714a5", + "name": "Gmail - Drafts - Delete", + "webhookId": "3b8b38e0-2f4b-40bc-8b67-37e7ea95cb60", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "resource": "draft", + "subject": "Test Draft Subject", + "message": "Test Draft Message", + "options": { + "attachmentsUi": { + "attachmentsBinary": [ + { + "property": "data" + } + ] + }, + "bccList": "test-bcc@n8n.io", + "ccList": "test-cc@n8n.io", + "fromAlias": "=test-alias@n8n.io", + "replyTo": "test-reply@n8n.io", + "threadId": "test-thread-id", + "sendTo": "test-to@n8n.io" + } + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [840, -180], + "id": "45758452-3b5b-478d-aece-001e117ce69d", + "name": "Gmail - Drafts - Create", + "webhookId": "3b8b38e0-2f4b-40bc-8b67-37e7ea95cb60", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "resource": "draft", + "operation": "getAll", + "returnAll": true, + "options": { + "dataPropertyAttachmentsPrefixName": "attachment_", + "downloadAttachments": true, + "includeSpamTrash": true + } + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [440, 400], + "id": "bae81586-7641-4fdc-81a4-0006b289bf9d", + "name": "Gmail - Drafts - Get Many", + "webhookId": "3b8b38e0-2f4b-40bc-8b67-37e7ea95cb60", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "assignments": { + "assignments": [ + { + "id": "491590a8-27a6-4d14-b342-493947775d16", + "name": "binary", + "value": true, + "type": "boolean" + } + ] + }, + "options": {} + }, + "type": "n8n-nodes-base.set", + "typeVersion": 3.4, + "position": [420, -180], + "id": "d630c018-1d7b-4779-a280-9f4a21c6a764", + "name": "Edit Fields" + }, + { + "parameters": { + "operation": "toJson", + "options": {} + }, + "type": "n8n-nodes-base.convertToFile", + "typeVersion": 1.1, + "position": [640, -180], + "id": "fc3bdb76-c278-44f6-9aac-153b79c8177b", + "name": "Convert to File" + } + ], + "pinData": { + "Gmail - Drafts - Create": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "ABC12345+EXAMPLE123456789" }, + { + "name": "X-Received", + "value": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Thu, 5 Dec 2024 08:30:00 -0800" }, + { "name": "From", "value": "Holiday Deals " }, + { "name": "To", "value": "exampleuser@gmail.com" }, + { "name": "Message-ID", "value": "<12345abc67890@promotion.example.com>" }, + { "name": "Subject", "value": "Exclusive Holiday Discounts!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000" + } + } + ], + "Gmail - Drafts - Delete": [{ "json": { "success": true } }], + "Gmail - Drafts - Get": [ + { + "json": { + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "sizeEstimate": 67890, + "headers": { + "mime-version": "MIME-Version: 1.0", + "date": "Date: Fri, 13 Dec 2024 11:15:01 +0100", + "message-id": "Message-ID: ", + "subject": "Subject: Test draft", + "from": "From: node qa ", + "to": "To: test@gmail.com", + "content-type": "Content-Type: multipart/alternative; boundary=\"0000000000009d58b60629241a22\"" + }, + "html": "
draft body
\n", + "text": "draft body\n", + "textAsHtml": "

draft body

", + "subject": "Test draft", + "date": "2024-12-13T10:15:01.000Z", + "to": { + "value": [{ "address": "test@gmail.com", "name": "" }], + "html": "test@gmail.com", + "text": "test@gmail.com" + }, + "from": { + "value": [{ "address": "node8qa@gmail.com", "name": "node qa" }], + "html": "node qa <node8qa@gmail.com>", + "text": "\"node qa\" " + }, + "messageId": "a1b2c3d4e5f6g7h8" + } + } + ], + "Gmail - Drafts - Get Many": [ + { + "json": { + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "sizeEstimate": 67890, + "headers": { + "mime-version": "MIME-Version: 1.0", + "date": "Date: Fri, 13 Dec 2024 11:15:01 +0100", + "message-id": "Message-ID: ", + "subject": "Subject: Test draft", + "from": "From: node qa ", + "to": "To: test@gmail.com", + "content-type": "Content-Type: multipart/alternative; boundary=\"0000000000009d58b60629241a22\"" + }, + "html": "
draft body
\n", + "text": "draft body\n", + "textAsHtml": "

draft body

", + "subject": "Test draft", + "date": "2024-12-13T10:15:01.000Z", + "to": { + "value": [{ "address": "test@gmail.com", "name": "" }], + "html": "test@gmail.com", + "text": "test@gmail.com" + }, + "from": { + "value": [{ "address": "node8qa@gmail.com", "name": "node qa" }], + "html": "node qa <node8qa@gmail.com>", + "text": "\"node qa\" " + }, + "messageId": "a1b2c3d4e5f6g7h8" + } + }, + { + "json": { + "threadId": "z9y8x7w6v5u4t3s2", + "labelIds": ["UNREAD", "CATEGORY_SOCIAL", "INBOX"], + "sizeEstimate": 54321, + "headers": { + "mime-version": "MIME-Version: 1.0", + "date": "Date: Fri, 13 Dec 2024 11:15:01 +0100", + "message-id": "Message-ID: ", + "subject": "Subject: Test draft", + "from": "From: node qa ", + "to": "To: test@gmail.com", + "content-type": "Content-Type: multipart/alternative; boundary=\"0000000000009d58b60629241a22\"" + }, + "html": "
draft body
\n", + "text": "draft body\n", + "textAsHtml": "

draft body

", + "subject": "Test draft", + "date": "2024-12-13T10:15:01.000Z", + "to": { + "value": [{ "address": "test@gmail.com", "name": "" }], + "html": "test@gmail.com", + "text": "test@gmail.com" + }, + "from": { + "value": [{ "address": "node8qa@gmail.com", "name": "node qa" }], + "html": "node qa <node8qa@gmail.com>", + "text": "\"node qa\" " + }, + "messageId": "z9y8x7w6v5u4t3s2" + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Gmail - Drafts - Get Many", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Drafts - Get", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Drafts - Delete", + "type": "main", + "index": 0 + }, + { + "node": "Edit Fields", + "type": "main", + "index": 0 + } + ] + ] + }, + "Edit Fields": { + "main": [ + [ + { + "node": "Convert to File", + "type": "main", + "index": 0 + } + ] + ] + }, + "Convert to File": { + "main": [ + [ + { + "node": "Gmail - Drafts - Create", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "84fb11a4-4166-45bd-bd9f-60fa378d9e68", + "meta": { + "instanceId": "27cc9b56542ad45b38725555722c50a1c3fee1670bbb67980558314ee08517c4" + }, + "id": "09KDcfGmfDrLInDE", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Google/Gmail/test/v2/fixtures/labels.json b/packages/nodes-base/nodes/Google/Gmail/test/v2/fixtures/labels.json new file mode 100644 index 0000000000..7d211dc09c --- /dev/null +++ b/packages/nodes-base/nodes/Google/Gmail/test/v2/fixtures/labels.json @@ -0,0 +1,14 @@ +[ + { + "id": "CHAT", + "name": "CHAT", + "messageListVisibility": "hide", + "labelListVisibility": "labelHide", + "type": "system" + }, + { + "id": "SENT", + "name": "SENT", + "type": "system" + } +] diff --git a/packages/nodes-base/nodes/Google/Gmail/test/v2/fixtures/messages.json b/packages/nodes-base/nodes/Google/Gmail/test/v2/fixtures/messages.json new file mode 100644 index 0000000000..cb669eb88d --- /dev/null +++ b/packages/nodes-base/nodes/Google/Gmail/test/v2/fixtures/messages.json @@ -0,0 +1,240 @@ +[ + { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { + "name": "Delivered-To", + "value": "exampleuser@gmail.com" + }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "X-Google-Smtp-Source", + "value": "ABC12345+EXAMPLE123456789" + }, + { + "name": "X-Received", + "value": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com" + }, + { + "name": "Return-Path", + "value": "" + }, + { + "name": "Date", + "value": "Thu, 5 Dec 2024 08:30:00 -0800" + }, + { + "name": "From", + "value": "Holiday Deals " + }, + { + "name": "To", + "value": "exampleuser@gmail.com" + }, + { + "name": "Message-ID", + "value": "<12345abc67890@promotion.example.com>" + }, + { + "name": "Subject", + "value": "Exclusive Holiday Discounts!" + }, + { + "name": "MIME-Version", + "value": "1.0" + }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + ], + "body": { + "size": 0 + }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { + "name": "Content-Type", + "value": "text/plain; charset=utf-8" + }, + { + "name": "Content-Transfer-Encoding", + "value": "quoted-printable" + } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=\"utf-8\"" + }, + { + "name": "Content-Transfer-Encoding", + "value": "quoted-printable" + } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000" + }, + { + "id": "z9y8x7w6v5u4t3s2", + "threadId": "z9y8x7w6v5u4t3s2", + "labelIds": ["UNREAD", "CATEGORY_SOCIAL", "INBOX"], + "snippet": "Your friend John just shared a new photo with you! Check it out now.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { + "name": "Delivered-To", + "value": "exampleuser2@gmail.com" + }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id def456ghi789; Fri, 6 Dec 2024 09:45:00 -0800 (PST)" + }, + { + "name": "X-Google-Smtp-Source", + "value": "XYZ67890+EXAMPLE0987654321" + }, + { + "name": "X-Received", + "value": "by 198.51.100.2 with SMTP id 67890def12345; Fri, 6 Dec 2024 09:45:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733490900; cv=none; d=example2.com; s=arc-20241206; b=HIJKLMN987654=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example2.com; s=arc-20241206; bh=EXAMPLEHASH67890=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example2.com; dkim=pass header.i=@social.example2.com; spf=pass smtp.mailfrom=notifications@social.example2.com; dmarc=pass header.from=example2.com" + }, + { + "name": "Return-Path", + "value": "" + }, + { + "name": "Date", + "value": "Fri, 6 Dec 2024 09:45:00 -0800" + }, + { + "name": "From", + "value": "John's Photos " + }, + { + "name": "To", + "value": "exampleuser2@gmail.com" + }, + { + "name": "Message-ID", + "value": "<67890def12345@social.example2.com>" + }, + { + "name": "Subject", + "value": "John shared a new photo with you!" + }, + { + "name": "MIME-Version", + "value": "1.0" + }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_67890_12345.1733490900000\"" + } + ], + "body": { + "size": 0 + }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { + "name": "Content-Type", + "value": "text/plain; charset=utf-8" + }, + { + "name": "Content-Transfer-Encoding", + "value": "quoted-printable" + } + ], + "body": { + "size": 4321, + "data": "U2VlIHRoZSBhdHRhY2hlZCBwaG90byBhbmQgcmVwbHkgdG8gSm9obi4gV2UgaG9wZSB5b3UgbGlrZSBpdCE=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { + "name": "Content-Type", + "value": "text/html; charset=\"utf-8\"" + }, + { + "name": "Content-Transfer-Encoding", + "value": "quoted-printable" + } + ], + "body": { + "size": 8765, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+U2VlIHRoZSBhdHRhY2hlZCBwaG90byBhbmQgcmVwbHkgdG8gPGI+Sm9obi48L2I+IFdlIGhvcGUgeW91IGxpa2UgaXQhPC9kaXY+" + } + } + ] + }, + "sizeEstimate": 54321, + "historyId": "98765", + "internalDate": "1733490900000" + } +] diff --git a/packages/nodes-base/nodes/Google/Gmail/test/v2/labels.workflow.json b/packages/nodes-base/nodes/Google/Gmail/test/v2/labels.workflow.json new file mode 100644 index 0000000000..fecfce191c --- /dev/null +++ b/packages/nodes-base/nodes/Google/Gmail/test/v2/labels.workflow.json @@ -0,0 +1,163 @@ +{ + "name": "My workflow 130", + "nodes": [ + { + "parameters": {}, + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [-60, 100], + "id": "636b40bc-2c98-4b9a-8ce2-9d1322294518", + "name": "When clicking ‘Test workflow’" + }, + { + "parameters": { + "resource": "label", + "operation": "create", + "name": "Test Label Name", + "options": {} + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [220, -180], + "id": "45758452-3b5b-478d-aece-001e117ce69d", + "name": "Gmail - Labels - Create", + "webhookId": "3b8b38e0-2f4b-40bc-8b67-37e7ea95cb60", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "resource": "label", + "operation": "delete", + "labelId": "test-label-id" + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [220, 20], + "id": "ed979c3a-b2ea-413e-be63-0392cc1714a5", + "name": "Gmail - Labels - Delete", + "webhookId": "3b8b38e0-2f4b-40bc-8b67-37e7ea95cb60", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "resource": "label", + "operation": "get", + "labelId": "test-label-id" + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [220, 200], + "id": "8802fdb5-2741-407b-82a4-ccedc4055076", + "name": "Gmail - Labels - Get", + "webhookId": "3b8b38e0-2f4b-40bc-8b67-37e7ea95cb60", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "resource": "label", + "limit": 2 + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [220, 400], + "id": "bae81586-7641-4fdc-81a4-0006b289bf9d", + "name": "Gmail - Labels - Get Many", + "webhookId": "3b8b38e0-2f4b-40bc-8b67-37e7ea95cb60", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + } + ], + "pinData": { + "Gmail - Labels - Create": [ + { + "json": { + "id": "CHAT", + "name": "CHAT", + "messageListVisibility": "hide", + "labelListVisibility": "labelHide", + "type": "system" + } + } + ], + "Gmail - Labels - Delete": [{ "json": { "success": true } }], + "Gmail - Labels - Get": [ + { + "json": { + "id": "CHAT", + "name": "CHAT", + "messageListVisibility": "hide", + "labelListVisibility": "labelHide", + "type": "system" + } + } + ], + "Gmail - Labels - Get Many": [ + { + "json": { + "id": "CHAT", + "name": "CHAT", + "messageListVisibility": "hide", + "labelListVisibility": "labelHide", + "type": "system" + } + }, + { "json": { "id": "SENT", "name": "SENT", "type": "system" } } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Gmail - Labels - Create", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Labels - Delete", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Labels - Get", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Labels - Get Many", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "", + "meta": { + "instanceId": "27cc9b56542ad45b38725555722c50a1c3fee1670bbb67980558314ee08517c4" + }, + "tags": [] +} diff --git a/packages/nodes-base/nodes/Google/Gmail/test/v2/messages.workflow.json b/packages/nodes-base/nodes/Google/Gmail/test/v2/messages.workflow.json new file mode 100644 index 0000000000..ba64983183 --- /dev/null +++ b/packages/nodes-base/nodes/Google/Gmail/test/v2/messages.workflow.json @@ -0,0 +1,1151 @@ +{ + "name": "Gmail test - messages", + "nodes": [ + { + "parameters": {}, + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [0, 0], + "id": "765640dd-529f-4319-a435-a1b5411cf761", + "name": "When clicking ‘Test workflow’" + }, + { + "parameters": { + "operation": "getAll", + "limit": 2, + "filters": {} + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [780, -600], + "id": "51f7694c-0d4c-4f84-9e4f-8a8fe8db18c9", + "name": "Gmail - Messages - All (simplified)", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "operation": "getAll", + "limit": 2, + "simple": false, + "filters": { + "includeSpamTrash": true, + "labelIds": ["CHAT"], + "q": "test", + "readStatus": "both", + "receivedAfter": "2024-12-17T00:00:00", + "receivedBefore": "2024-12-26T00:00:00", + "sender": "Test Sender" + }, + "options": { + "dataPropertyAttachmentsPrefixName": "attachment_", + "downloadAttachments": true + } + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [780, -400], + "id": "2ea8db65-5e60-47dc-bdca-1981bee1b63e", + "name": "Gmail - Messages - All", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "sendTo": "test@n8n.io", + "subject": "Test Subject", + "message": "Test Message", + "options": { + "appendAttribution": true, + "attachmentsUi": { + "attachmentsBinary": [{}, {}] + }, + "bccList": "test-bcc@n8n.io", + "ccList": "test-cc@n8n.io", + "senderName": "Test Sender", + "replyTo": "test-reply-to@n8n.io", + "replyToSenderOnly": true + } + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [1060, 1380], + "id": "da96a339-2df5-465f-a253-5302160ef921", + "name": "Gmail - Messages - Send", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "operation": "sendAndWait", + "sendTo": "test@n8n.io", + "subject": "Test Subject", + "message": "Test Message" + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [780, 1580], + "id": "b12181b3-a98d-44ba-bb71-a22ce4e4c663", + "name": "Gmail - Messages - Send and Wait for Approval", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "operation": "addLabels", + "messageId": "test", + "labelIds": ["CHAT"] + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [780, -220], + "id": "2f83b7ac-3e7a-466d-b269-88928da60d3a", + "name": "Gmail - Messages - Add Label", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "operation": "delete", + "messageId": "test" + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [780, 180], + "id": "aba867fa-bf92-4ba9-b96f-c0f74d37c144", + "name": "Gmail - Messages - Delete", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "operation": "get", + "messageId": "test" + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [780, 380], + "id": "029494b2-caf2-4a1e-b496-1ab3ac96987a", + "name": "Gmail - Messages - Get (simplified)", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "operation": "get", + "messageId": "test", + "simple": false, + "options": {} + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [780, 580], + "id": "86a77799-6d7b-4dd6-9afa-be3cd64e82df", + "name": "Gmail - Messages - Get", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "operation": "markAsRead", + "messageId": "test" + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [780, 760], + "id": "aedc33d9-cc57-4bc1-8811-8aa5fe02a363", + "name": "Gmail - Messages - Mark as Read", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "operation": "markAsUnread", + "messageId": "test" + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [780, 980], + "id": "a463ad5e-3fac-40c9-b9bf-0705d28aa68d", + "name": "Gmail - Messages - Mark as Unread", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "operation": "removeLabels", + "messageId": "test", + "labelIds": ["CHAT"] + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [780, -20], + "id": "97996089-0116-4c86-b24c-5848661efc9c", + "name": "Gmail - Messages - Remove Label", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "operation": "reply", + "messageId": "test", + "message": "Test reply", + "options": { + "appendAttribution": false, + "bccList": "test-bcc@n8n.io", + "senderName": "Test Sender Name", + "replyToSenderOnly": false + } + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [780, 1200], + "id": "aa43df3d-5de3-4663-9211-401e3040a4de", + "name": "Gmail - Messages - Reply", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "operation": "toJson", + "options": {} + }, + "type": "n8n-nodes-base.convertToFile", + "typeVersion": 1.1, + "position": [920, 1380], + "id": "6820a547-12dc-4146-8483-a43adf695b40", + "name": "Attachment" + }, + { + "parameters": { + "assignments": { + "assignments": [ + { + "id": "0a4e38fe-ed38-400e-afb1-9d430f167d54", + "name": "attachment", + "value": true, + "type": "boolean" + } + ] + }, + "options": {} + }, + "type": "n8n-nodes-base.set", + "typeVersion": 3.4, + "position": [780, 1380], + "id": "72bd5e27-dd43-48ad-be97-634caf883dd5", + "name": "Edit Fields" + } + ], + "pinData": { + "Gmail - Messages - All (simplified)": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000", + "labels": [], + "Delivered-To": "exampleuser@gmail.com", + "Received": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)", + "X-Google-Smtp-Source": "ABC12345+EXAMPLE123456789", + "X-Received": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)", + "ARC-Seal": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=", + "ARC-Message-Signature": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=", + "ARC-Authentication-Results": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com", + "Return-Path": "", + "Date": "Thu, 5 Dec 2024 08:30:00 -0800", + "From": "Holiday Deals ", + "To": "exampleuser@gmail.com", + "Message-ID": "<12345abc67890@promotion.example.com>", + "Subject": "Exclusive Holiday Discounts!", + "MIME-Version": "1.0", + "Content-Type": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + }, + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000", + "labels": [], + "Delivered-To": "exampleuser@gmail.com", + "Received": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)", + "X-Google-Smtp-Source": "ABC12345+EXAMPLE123456789", + "X-Received": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)", + "ARC-Seal": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=", + "ARC-Message-Signature": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=", + "ARC-Authentication-Results": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com", + "Return-Path": "", + "Date": "Thu, 5 Dec 2024 08:30:00 -0800", + "From": "Holiday Deals ", + "To": "exampleuser@gmail.com", + "Message-ID": "<12345abc67890@promotion.example.com>", + "Subject": "Exclusive Holiday Discounts!", + "MIME-Version": "1.0", + "Content-Type": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + } + ], + "Gmail - Messages - All": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "sizeEstimate": 67890, + "headers": { + "mime-version": "MIME-Version: 1.0", + "date": "Date: Fri, 13 Dec 2024 11:15:01 +0100", + "message-id": "Message-ID: ", + "subject": "Subject: Test draft", + "from": "From: node qa ", + "to": "To: test@gmail.com", + "content-type": "Content-Type: multipart/alternative; boundary=\"0000000000009d58b60629241a22\"" + }, + "html": "
draft body
\n", + "text": "draft body\n", + "textAsHtml": "

draft body

", + "subject": "Test draft", + "date": "2024-12-13T10:15:01.000Z", + "to": { + "value": [{ "address": "test@gmail.com", "name": "" }], + "html": "test@gmail.com", + "text": "test@gmail.com" + }, + "from": { + "value": [{ "address": "node8qa@gmail.com", "name": "node qa" }], + "html": "node qa <node8qa@gmail.com>", + "text": "\"node qa\" " + }, + "messageId": "" + } + }, + { + "json": { + "id": "z9y8x7w6v5u4t3s2", + "threadId": "z9y8x7w6v5u4t3s2", + "labelIds": ["UNREAD", "CATEGORY_SOCIAL", "INBOX"], + "sizeEstimate": 54321, + "headers": { + "mime-version": "MIME-Version: 1.0", + "date": "Date: Fri, 13 Dec 2024 11:15:01 +0100", + "message-id": "Message-ID: ", + "subject": "Subject: Test draft", + "from": "From: node qa ", + "to": "To: test@gmail.com", + "content-type": "Content-Type: multipart/alternative; boundary=\"0000000000009d58b60629241a22\"" + }, + "html": "
draft body
\n", + "text": "draft body\n", + "textAsHtml": "

draft body

", + "subject": "Test draft", + "date": "2024-12-13T10:15:01.000Z", + "to": { + "value": [{ "address": "test@gmail.com", "name": "" }], + "html": "test@gmail.com", + "text": "test@gmail.com" + }, + "from": { + "value": [{ "address": "node8qa@gmail.com", "name": "node qa" }], + "html": "node qa <node8qa@gmail.com>", + "text": "\"node qa\" " + }, + "messageId": "" + } + } + ], + "Gmail - Messages - Send": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "ABC12345+EXAMPLE123456789" }, + { + "name": "X-Received", + "value": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Thu, 5 Dec 2024 08:30:00 -0800" }, + { "name": "From", "value": "Holiday Deals " }, + { "name": "To", "value": "exampleuser@gmail.com" }, + { "name": "Message-ID", "value": "<12345abc67890@promotion.example.com>" }, + { "name": "Subject", "value": "Exclusive Holiday Discounts!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000" + } + } + ], + "Gmail - Messages - Send and Wait for Approval": [{ "json": {} }], + "Gmail - Messages - Add Label": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "ABC12345+EXAMPLE123456789" }, + { + "name": "X-Received", + "value": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Thu, 5 Dec 2024 08:30:00 -0800" }, + { "name": "From", "value": "Holiday Deals " }, + { "name": "To", "value": "exampleuser@gmail.com" }, + { "name": "Message-ID", "value": "<12345abc67890@promotion.example.com>" }, + { "name": "Subject", "value": "Exclusive Holiday Discounts!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000" + } + } + ], + "Gmail - Messages - Delete": [{ "json": { "success": true } }], + "Gmail - Messages - Get (simplified)": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000", + "labels": [], + "Delivered-To": "exampleuser@gmail.com", + "Received": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)", + "X-Google-Smtp-Source": "ABC12345+EXAMPLE123456789", + "X-Received": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)", + "ARC-Seal": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=", + "ARC-Message-Signature": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=", + "ARC-Authentication-Results": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com", + "Return-Path": "", + "Date": "Thu, 5 Dec 2024 08:30:00 -0800", + "From": "Holiday Deals ", + "To": "exampleuser@gmail.com", + "Message-ID": "<12345abc67890@promotion.example.com>", + "Subject": "Exclusive Holiday Discounts!", + "MIME-Version": "1.0", + "Content-Type": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + } + ], + "Gmail - Messages - Get": [ + { "json": { "headers": { "": "��-zf���'���" }, "html": false } } + ], + "Gmail - Messages - Mark as Read": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "ABC12345+EXAMPLE123456789" }, + { + "name": "X-Received", + "value": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Thu, 5 Dec 2024 08:30:00 -0800" }, + { "name": "From", "value": "Holiday Deals " }, + { "name": "To", "value": "exampleuser@gmail.com" }, + { "name": "Message-ID", "value": "<12345abc67890@promotion.example.com>" }, + { "name": "Subject", "value": "Exclusive Holiday Discounts!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000" + } + } + ], + "Gmail - Messages - Mark as Unread": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "ABC12345+EXAMPLE123456789" }, + { + "name": "X-Received", + "value": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Thu, 5 Dec 2024 08:30:00 -0800" }, + { "name": "From", "value": "Holiday Deals " }, + { "name": "To", "value": "exampleuser@gmail.com" }, + { "name": "Message-ID", "value": "<12345abc67890@promotion.example.com>" }, + { "name": "Subject", "value": "Exclusive Holiday Discounts!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000" + } + } + ], + "Gmail - Messages - Remove Label": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "ABC12345+EXAMPLE123456789" }, + { + "name": "X-Received", + "value": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Thu, 5 Dec 2024 08:30:00 -0800" }, + { "name": "From", "value": "Holiday Deals " }, + { "name": "To", "value": "exampleuser@gmail.com" }, + { "name": "Message-ID", "value": "<12345abc67890@promotion.example.com>" }, + { "name": "Subject", "value": "Exclusive Holiday Discounts!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000" + } + } + ], + "Gmail - Messages - Reply": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "ABC12345+EXAMPLE123456789" }, + { + "name": "X-Received", + "value": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Thu, 5 Dec 2024 08:30:00 -0800" }, + { "name": "From", "value": "Holiday Deals " }, + { "name": "To", "value": "exampleuser@gmail.com" }, + { "name": "Message-ID", "value": "<12345abc67890@promotion.example.com>" }, + { "name": "Subject", "value": "Exclusive Holiday Discounts!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000" + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Gmail - Messages - All (simplified)", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Messages - All", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Messages - Send and Wait for Approval", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Messages - Add Label", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Messages - Delete", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Messages - Get (simplified)", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Messages - Get", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Messages - Mark as Read", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Messages - Mark as Unread", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Messages - Remove Label", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Messages - Reply", + "type": "main", + "index": 0 + }, + { + "node": "Edit Fields", + "type": "main", + "index": 0 + } + ] + ] + }, + "Attachment": { + "main": [ + [ + { + "node": "Gmail - Messages - Send", + "type": "main", + "index": 0 + } + ] + ] + }, + "Edit Fields": { + "main": [ + [ + { + "node": "Attachment", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "f497669f-aced-4f80-8e59-381d1c9422c7", + "meta": { + "instanceId": "27cc9b56542ad45b38725555722c50a1c3fee1670bbb67980558314ee08517c4" + }, + "id": "jOoDfyAYzh3NAli3", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Google/Gmail/test/v2/threads.workflow.json b/packages/nodes-base/nodes/Google/Gmail/test/v2/threads.workflow.json new file mode 100644 index 0000000000..e92d016877 --- /dev/null +++ b/packages/nodes-base/nodes/Google/Gmail/test/v2/threads.workflow.json @@ -0,0 +1,1174 @@ +{ + "name": "My workflow 130", + "nodes": [ + { + "parameters": {}, + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [20, 920], + "id": "cfa1d2b9-9706-48a2-9dd4-39e4c3c0ccb4", + "name": "When clicking ‘Test workflow’" + }, + { + "parameters": { + "resource": "thread", + "limit": 2, + "filters": {} + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [800, 320], + "id": "7b925004-8583-4f43-b1f0-6a37331cabf4", + "name": "Gmail - Threads - All (simplified)", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "resource": "thread", + "limit": 2, + "filters": { + "includeSpamTrash": true, + "labelIds": ["CHAT"], + "q": "has:attachment", + "readStatus": "unread", + "receivedAfter": "2024-12-05T00:00:00", + "receivedBefore": "2024-12-27T00:00:00" + } + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [800, 520], + "id": "22fa66e3-ac89-4289-82c7-e3be3c271d04", + "name": "Gmail - Threads - All", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "resource": "thread", + "operation": "addLabels", + "threadId": "test-thread-id", + "labelIds": ["CHAT"] + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [800, 700], + "id": "b94b2e79-a47d-4e05-a74b-957a9efe46a5", + "name": "Gmail - Threads - Add Label", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "resource": "thread", + "operation": "removeLabels", + "threadId": "test-thread-id", + "labelIds": ["CHAT"] + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [800, 900], + "id": "5322c0f6-e040-4bb4-9014-041662e7a173", + "name": "Gmail - Threads - Remove Label", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "resource": "thread", + "operation": "delete", + "threadId": "test-thread-id" + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [800, 1100], + "id": "6f7139f1-9236-4d35-b7ba-48f3e00d11ec", + "name": "Gmail - Threads - Delete", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "resource": "thread", + "operation": "get", + "threadId": "test-thread-id", + "options": {} + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [800, 1300], + "id": "4e7bccd2-e663-4824-b870-bb5fe7ad6c57", + "name": "Gmail - Threads - Get (simplified)", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "resource": "thread", + "operation": "get", + "threadId": "test-thread-id", + "simple": false, + "options": { + "returnOnlyMessages": true + } + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [800, 1500], + "id": "4084a6fd-6770-4aa2-ac4e-6108f9b159a2", + "name": "Gmail - Threads - Get", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "resource": "thread", + "operation": "reply", + "threadId": "test-thread-id", + "messageId": "=test snippet", + "message": "Test reply", + "options": { + "attachmentsUi": { + "attachmentsBinary": [ + { + "property": "data" + } + ] + }, + "bccList": "test-bcc@n8n.io", + "ccList": "test-cc@n8n.io", + "senderName": "Test Sender Name", + "replyToSenderOnly": true + } + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [1120, 2080], + "id": "d5b44033-655a-4e18-99c7-6ee19140967b", + "name": "Gmail - Threads - Reply", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "resource": "thread", + "operation": "trash", + "threadId": "test-thread-id" + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [800, 1680], + "id": "1503c357-043c-45f5-bbe8-1d7141a84546", + "name": "Gmail - Threads - Trash", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "resource": "thread", + "operation": "untrash", + "threadId": "test-thread-id" + }, + "type": "n8n-nodes-base.gmail", + "typeVersion": 2.1, + "position": [800, 1880], + "id": "38c02fc0-2e8e-4a6b-a045-eb45f2811c0a", + "name": "Gmail - Threads - Untrash", + "webhookId": "f3cbddc1-3cfa-4217-aa73-f0e5a9309661", + "credentials": { + "gmailOAuth2": { + "id": "22", + "name": "Gmail 0auth" + } + } + }, + { + "parameters": { + "assignments": { + "assignments": [ + { + "id": "0a4e38fe-ed38-400e-afb1-9d430f167d54", + "name": "attachment", + "value": true, + "type": "boolean" + } + ] + }, + "options": {} + }, + "type": "n8n-nodes-base.set", + "typeVersion": 3.4, + "position": [800, 2080], + "id": "d6a20bfa-4bee-4aef-b1b0-198ed73d1b3f", + "name": "Edit Fields1" + }, + { + "parameters": { + "operation": "toJson", + "options": {} + }, + "type": "n8n-nodes-base.convertToFile", + "typeVersion": 1.1, + "position": [960, 2080], + "id": "47d4a53b-6019-444b-9746-f957704cd4e0", + "name": "Attachment1" + } + ], + "pinData": { + "Gmail - Threads - All (simplified)": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "ABC12345+EXAMPLE123456789" }, + { + "name": "X-Received", + "value": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Thu, 5 Dec 2024 08:30:00 -0800" }, + { "name": "From", "value": "Holiday Deals " }, + { "name": "To", "value": "exampleuser@gmail.com" }, + { "name": "Message-ID", "value": "<12345abc67890@promotion.example.com>" }, + { "name": "Subject", "value": "Exclusive Holiday Discounts!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000" + } + }, + { + "json": { + "id": "z9y8x7w6v5u4t3s2", + "threadId": "z9y8x7w6v5u4t3s2", + "labelIds": ["UNREAD", "CATEGORY_SOCIAL", "INBOX"], + "snippet": "Your friend John just shared a new photo with you! Check it out now.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser2@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id def456ghi789; Fri, 6 Dec 2024 09:45:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "XYZ67890+EXAMPLE0987654321" }, + { + "name": "X-Received", + "value": "by 198.51.100.2 with SMTP id 67890def12345; Fri, 6 Dec 2024 09:45:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733490900; cv=none; d=example2.com; s=arc-20241206; b=HIJKLMN987654=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example2.com; s=arc-20241206; bh=EXAMPLEHASH67890=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example2.com; dkim=pass header.i=@social.example2.com; spf=pass smtp.mailfrom=notifications@social.example2.com; dmarc=pass header.from=example2.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Fri, 6 Dec 2024 09:45:00 -0800" }, + { "name": "From", "value": "John's Photos " }, + { "name": "To", "value": "exampleuser2@gmail.com" }, + { "name": "Message-ID", "value": "<67890def12345@social.example2.com>" }, + { "name": "Subject", "value": "John shared a new photo with you!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_67890_12345.1733490900000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 4321, + "data": "U2VlIHRoZSBhdHRhY2hlZCBwaG90byBhbmQgcmVwbHkgdG8gSm9obi4gV2UgaG9wZSB5b3UgbGlrZSBpdCE=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 8765, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+U2VlIHRoZSBhdHRhY2hlZCBwaG90byBhbmQgcmVwbHkgdG8gPGI+Sm9obi48L2I+IFdlIGhvcGUgeW91IGxpa2UgaXQhPC9kaXY+" + } + } + ] + }, + "sizeEstimate": 54321, + "historyId": "98765", + "internalDate": "1733490900000" + } + } + ], + "Gmail - Threads - All": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "ABC12345+EXAMPLE123456789" }, + { + "name": "X-Received", + "value": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Thu, 5 Dec 2024 08:30:00 -0800" }, + { "name": "From", "value": "Holiday Deals " }, + { "name": "To", "value": "exampleuser@gmail.com" }, + { "name": "Message-ID", "value": "<12345abc67890@promotion.example.com>" }, + { "name": "Subject", "value": "Exclusive Holiday Discounts!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000" + } + }, + { + "json": { + "id": "z9y8x7w6v5u4t3s2", + "threadId": "z9y8x7w6v5u4t3s2", + "labelIds": ["UNREAD", "CATEGORY_SOCIAL", "INBOX"], + "snippet": "Your friend John just shared a new photo with you! Check it out now.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser2@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id def456ghi789; Fri, 6 Dec 2024 09:45:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "XYZ67890+EXAMPLE0987654321" }, + { + "name": "X-Received", + "value": "by 198.51.100.2 with SMTP id 67890def12345; Fri, 6 Dec 2024 09:45:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733490900; cv=none; d=example2.com; s=arc-20241206; b=HIJKLMN987654=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example2.com; s=arc-20241206; bh=EXAMPLEHASH67890=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example2.com; dkim=pass header.i=@social.example2.com; spf=pass smtp.mailfrom=notifications@social.example2.com; dmarc=pass header.from=example2.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Fri, 6 Dec 2024 09:45:00 -0800" }, + { "name": "From", "value": "John's Photos " }, + { "name": "To", "value": "exampleuser2@gmail.com" }, + { "name": "Message-ID", "value": "<67890def12345@social.example2.com>" }, + { "name": "Subject", "value": "John shared a new photo with you!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_67890_12345.1733490900000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 4321, + "data": "U2VlIHRoZSBhdHRhY2hlZCBwaG90byBhbmQgcmVwbHkgdG8gSm9obi4gV2UgaG9wZSB5b3UgbGlrZSBpdCE=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 8765, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+U2VlIHRoZSBhdHRhY2hlZCBwaG90byBhbmQgcmVwbHkgdG8gPGI+Sm9obi48L2I+IFdlIGhvcGUgeW91IGxpa2UgaXQhPC9kaXY+" + } + } + ] + }, + "sizeEstimate": 54321, + "historyId": "98765", + "internalDate": "1733490900000" + } + } + ], + "Gmail - Threads - Add Label": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "ABC12345+EXAMPLE123456789" }, + { + "name": "X-Received", + "value": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Thu, 5 Dec 2024 08:30:00 -0800" }, + { "name": "From", "value": "Holiday Deals " }, + { "name": "To", "value": "exampleuser@gmail.com" }, + { "name": "Message-ID", "value": "<12345abc67890@promotion.example.com>" }, + { "name": "Subject", "value": "Exclusive Holiday Discounts!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000" + } + } + ], + "Gmail - Threads - Remove Label": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "ABC12345+EXAMPLE123456789" }, + { + "name": "X-Received", + "value": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Thu, 5 Dec 2024 08:30:00 -0800" }, + { "name": "From", "value": "Holiday Deals " }, + { "name": "To", "value": "exampleuser@gmail.com" }, + { "name": "Message-ID", "value": "<12345abc67890@promotion.example.com>" }, + { "name": "Subject", "value": "Exclusive Holiday Discounts!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000" + } + } + ], + "Gmail - Threads - Delete": [{ "json": { "success": true } }], + "Gmail - Threads - Get (simplified)": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "ABC12345+EXAMPLE123456789" }, + { + "name": "X-Received", + "value": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Thu, 5 Dec 2024 08:30:00 -0800" }, + { "name": "From", "value": "Holiday Deals " }, + { "name": "To", "value": "exampleuser@gmail.com" }, + { "name": "Message-ID", "value": "<12345abc67890@promotion.example.com>" }, + { "name": "Subject", "value": "Exclusive Holiday Discounts!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000", + "messages": [] + } + } + ], + "Gmail - Threads - Get": [], + "Gmail - Threads - Reply": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "ABC12345+EXAMPLE123456789" }, + { + "name": "X-Received", + "value": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Thu, 5 Dec 2024 08:30:00 -0800" }, + { "name": "From", "value": "Holiday Deals " }, + { "name": "To", "value": "exampleuser@gmail.com" }, + { "name": "Message-ID", "value": "<12345abc67890@promotion.example.com>" }, + { "name": "Subject", "value": "Exclusive Holiday Discounts!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000" + } + } + ], + "Gmail - Threads - Trash": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "ABC12345+EXAMPLE123456789" }, + { + "name": "X-Received", + "value": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Thu, 5 Dec 2024 08:30:00 -0800" }, + { "name": "From", "value": "Holiday Deals " }, + { "name": "To", "value": "exampleuser@gmail.com" }, + { "name": "Message-ID", "value": "<12345abc67890@promotion.example.com>" }, + { "name": "Subject", "value": "Exclusive Holiday Discounts!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000" + } + } + ], + "Gmail - Threads - Untrash": [ + { + "json": { + "id": "a1b2c3d4e5f6g7h8", + "threadId": "a1b2c3d4e5f6g7h8", + "labelIds": ["UNREAD", "CATEGORY_PROMOTIONS", "INBOX"], + "snippet": "Don't miss our exclusive holiday discounts on all items! Act now before the sale ends.", + "payload": { + "partId": "", + "mimeType": "multipart/alternative", + "filename": "", + "headers": [ + { "name": "Delivered-To", "value": "exampleuser@gmail.com" }, + { + "name": "Received", + "value": "by 2001:db8::abcd with SMTP id xyz123abc456; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { "name": "X-Google-Smtp-Source", "value": "ABC12345+EXAMPLE123456789" }, + { + "name": "X-Received", + "value": "by 192.0.2.1 with SMTP id 12345abc67890; Thu, 5 Dec 2024 08:30:00 -0800 (PST)" + }, + { + "name": "ARC-Seal", + "value": "i=1; a=rsa-sha256; t=1733405400; cv=none; d=example.com; s=arc-20241205; b=ABCDEFG123456=" + }, + { + "name": "ARC-Message-Signature", + "value": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=arc-20241205; bh=EXAMPLEHASH12345=" + }, + { + "name": "ARC-Authentication-Results", + "value": "i=1; mx.example.com; dkim=pass header.i=@promotion.example.com; spf=pass smtp.mailfrom=promo@promotion.example.com; dmarc=pass header.from=example.com" + }, + { "name": "Return-Path", "value": "" }, + { "name": "Date", "value": "Thu, 5 Dec 2024 08:30:00 -0800" }, + { "name": "From", "value": "Holiday Deals " }, + { "name": "To", "value": "exampleuser@gmail.com" }, + { "name": "Message-ID", "value": "<12345abc67890@promotion.example.com>" }, + { "name": "Subject", "value": "Exclusive Holiday Discounts!" }, + { "name": "MIME-Version", "value": "1.0" }, + { + "name": "Content-Type", + "value": "multipart/alternative; boundary=\"----=_Part_12345_67890.1733405400000\"" + } + ], + "body": { "size": 0 }, + "parts": [ + { + "partId": "0", + "mimeType": "text/plain", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/plain; charset=utf-8" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 1234, + "data": "VGhpcyBpcyBhbiBleGFtcGxlIG1lc3NhZ2UuIFRoYW5rIHlvdSBmb3Igc2hvcHBpbmcgd2l0aCB1cy4=" + } + }, + { + "partId": "1", + "mimeType": "text/html", + "filename": "", + "headers": [ + { "name": "Content-Type", "value": "text/html; charset=\"utf-8\"" }, + { "name": "Content-Transfer-Encoding", "value": "quoted-printable" } + ], + "body": { + "size": 5678, + "data": "PGRpdiBzdHlsZT0nZm9udC1mYW1pbHk6IEFyaWFsLCBzYW5zLXNlcmlmOyc+VGhpcyBpcyBhbiBleGFtcGxlIGh0bWwgbWVzc2FnZS4gPGI+VGhhbmsgeW91IGZvciBzaG9wcGluZyB3aXRoIHVzLjwvYj48L2Rpdj4=" + } + } + ] + }, + "sizeEstimate": 67890, + "historyId": "54321", + "internalDate": "1733405400000" + } + } + ] + }, + "connections": { + "When clicking ‘Test workflow’": { + "main": [ + [ + { + "node": "Gmail - Threads - All (simplified)", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Threads - All", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Threads - Add Label", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Threads - Delete", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Threads - Get (simplified)", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Threads - Get", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Threads - Trash", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Threads - Untrash", + "type": "main", + "index": 0 + }, + { + "node": "Gmail - Threads - Remove Label", + "type": "main", + "index": 0 + }, + { + "node": "Edit Fields1", + "type": "main", + "index": 0 + } + ] + ] + }, + "Edit Fields1": { + "main": [ + [ + { + "node": "Attachment1", + "type": "main", + "index": 0 + } + ] + ] + }, + "Attachment1": { + "main": [ + [ + { + "node": "Gmail - Threads - Reply", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "84fb11a4-4166-45bd-bd9f-60fa378d9e68", + "meta": { + "instanceId": "27cc9b56542ad45b38725555722c50a1c3fee1670bbb67980558314ee08517c4" + }, + "id": "09KDcfGmfDrLInDE", + "tags": [] +} diff --git a/packages/nodes-base/nodes/Google/Gmail/v2/GmailV2.node.ts b/packages/nodes-base/nodes/Google/Gmail/v2/GmailV2.node.ts index 0be7c6507d..84cd8013b2 100644 --- a/packages/nodes-base/nodes/Google/Gmail/v2/GmailV2.node.ts +++ b/packages/nodes-base/nodes/Google/Gmail/v2/GmailV2.node.ts @@ -1,9 +1,7 @@ import type { - IExecuteFunctions, IDataObject, - ILoadOptionsFunctions, + IExecuteFunctions, INodeExecutionData, - INodePropertyOptions, INodeType, INodeTypeBaseDescription, INodeTypeDescription, @@ -15,7 +13,16 @@ import { WAIT_INDEFINITELY, } from 'n8n-workflow'; +import { draftFields, draftOperations } from './DraftDescription'; +import { labelFields, labelOperations } from './LabelDescription'; +import { messageFields, messageOperations } from './MessageDescription'; +import { threadFields, threadOperations } from './ThreadDescription'; import type { IEmail } from '../../../../utils/sendAndWait/interfaces'; +import { + createEmail, + getSendAndWaitProperties, + sendAndWaitWebhook, +} from '../../../../utils/sendAndWait/utils'; import { encodeEmail, googleApiRequest, @@ -29,20 +36,7 @@ import { simplifyOutput, unescapeSnippets, } from '../GenericFunctions'; - -import { messageFields, messageOperations } from './MessageDescription'; - -import { labelFields, labelOperations } from './LabelDescription'; - -import { draftFields, draftOperations } from './DraftDescription'; - -import { threadFields, threadOperations } from './ThreadDescription'; - -import { - getSendAndWaitProperties, - createEmail, - sendAndWaitWebhook, -} from '../../../../utils/sendAndWait/utils'; +import { getGmailAliases, getLabels, getThreadMessages } from './loadOptions'; const versionDescription: INodeTypeDescription = { displayName: 'Gmail', @@ -187,78 +181,9 @@ export class GmailV2 implements INodeType { methods = { loadOptions: { - // Get all the labels to display them to user so that they can - // select them easily - async getLabels(this: ILoadOptionsFunctions): Promise { - const returnData: INodePropertyOptions[] = []; - - const labels = await googleApiRequestAllItems.call( - this, - 'labels', - 'GET', - '/gmail/v1/users/me/labels', - ); - - for (const label of labels) { - returnData.push({ - name: label.name, - value: label.id, - }); - } - - return returnData.sort((a, b) => { - if (a.name < b.name) { - return -1; - } - if (a.name > b.name) { - return 1; - } - return 0; - }); - }, - - async getThreadMessages(this: ILoadOptionsFunctions): Promise { - const returnData: INodePropertyOptions[] = []; - - const id = this.getNodeParameter('threadId', 0) as string; - const { messages } = await googleApiRequest.call( - this, - 'GET', - `/gmail/v1/users/me/threads/${id}`, - {}, - { format: 'minimal' }, - ); - - for (const message of messages || []) { - returnData.push({ - name: message.snippet, - value: message.id, - }); - } - - return returnData; - }, - - async getGmailAliases(this: ILoadOptionsFunctions): Promise { - const returnData: INodePropertyOptions[] = []; - const { sendAs } = await googleApiRequest.call( - this, - 'GET', - '/gmail/v1/users/me/settings/sendAs', - ); - - for (const alias of sendAs || []) { - const displayName = alias.isDefault - ? `${alias.sendAsEmail} (Default)` - : alias.sendAsEmail; - returnData.push({ - name: displayName, - value: alias.sendAsEmail, - }); - } - - return returnData; - }, + getLabels, + getThreadMessages, + getGmailAliases, }, }; diff --git a/packages/nodes-base/nodes/Google/Gmail/v2/loadOptions.ts b/packages/nodes-base/nodes/Google/Gmail/v2/loadOptions.ts new file mode 100644 index 0000000000..6c5a7df9aa --- /dev/null +++ b/packages/nodes-base/nodes/Google/Gmail/v2/loadOptions.ts @@ -0,0 +1,75 @@ +import type { ILoadOptionsFunctions, INodePropertyOptions } from 'n8n-workflow'; + +import { googleApiRequest, googleApiRequestAllItems } from '../GenericFunctions'; + +/** + * Get all the labels to display them to user so that they can select them easily + */ +export async function getLabels(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + + const labels = await googleApiRequestAllItems.call( + this, + 'labels', + 'GET', + '/gmail/v1/users/me/labels', + ); + + for (const label of labels) { + returnData.push({ + name: label.name, + value: label.id, + }); + } + + return returnData.sort((a, b) => { + if (a.name < b.name) { + return -1; + } + if (a.name > b.name) { + return 1; + } + return 0; + }); +} + +export async function getThreadMessages( + this: ILoadOptionsFunctions, +): Promise { + const returnData: INodePropertyOptions[] = []; + + const id = this.getNodeParameter('threadId', 0) as string; + const { messages } = await googleApiRequest.call( + this, + 'GET', + `/gmail/v1/users/me/threads/${id}`, + {}, + { format: 'minimal' }, + ); + + for (const message of messages || []) { + returnData.push({ + name: message.snippet, + value: message.id, + }); + } + + return returnData; +} + +export async function getGmailAliases( + this: ILoadOptionsFunctions, +): Promise { + const returnData: INodePropertyOptions[] = []; + const { sendAs } = await googleApiRequest.call(this, 'GET', '/gmail/v1/users/me/settings/sendAs'); + + for (const alias of sendAs || []) { + const displayName = alias.isDefault ? `${alias.sendAsEmail} (Default)` : alias.sendAsEmail; + returnData.push({ + name: displayName, + value: alias.sendAsEmail, + }); + } + + return returnData; +} diff --git a/packages/nodes-base/test/nodes/FakeCredentialsMap.ts b/packages/nodes-base/test/nodes/FakeCredentialsMap.ts index 788dbcadb6..4daacbfd07 100644 --- a/packages/nodes-base/test/nodes/FakeCredentialsMap.ts +++ b/packages/nodes-base/test/nodes/FakeCredentialsMap.ts @@ -125,6 +125,25 @@ BQIDAQAB accessToken: 'testToken', baseUrl: 'https://api.telegram.org', }, + gmailOAuth2: { + grantType: 'authorizationCode', + authUrl: 'https://accounts.google.com/o/oauth2/v2/auth', + accessTokenUrl: 'https://oauth2.googleapis.com/token', + clientId: 'CLIENTID', + clientSecret: 'CLIENTSECRET', + scope: + 'https://www.googleapis.com/auth/gmail.labels https://www.googleapis.com/auth/gmail.addons.current.action.compose https://www.googleapis.com/auth/gmail.addons.current.message.action https://mail.google.com/ https://www.googleapis.com/auth/gmail.modify https://www.googleapis.com/auth/gmail.compose', + authQueryParameters: 'access_type=offline&prompt=consent', + authentication: 'body', + oauthTokenData: { + access_token: 'ACCESSTOKEN', + refresh_token: 'REFRESHTOKEN', + scope: + 'https://www.googleapis.com/auth/gmail.labels https://www.googleapis.com/auth/gmail.addons.current.action.compose https://www.googleapis.com/auth/gmail.addons.current.message.action https://mail.google.com/ https://www.googleapis.com/auth/gmail.modify https://www.googleapis.com/auth/gmail.compose', + token_type: 'bearer', + expires_in: 86400, + }, + }, notionApi: { apiKey: 'key123', }, diff --git a/packages/nodes-base/test/nodes/Helpers.ts b/packages/nodes-base/test/nodes/Helpers.ts index 829f21e303..a2ebee1370 100644 --- a/packages/nodes-base/test/nodes/Helpers.ts +++ b/packages/nodes-base/test/nodes/Helpers.ts @@ -332,7 +332,7 @@ export const equalityTest = async (testData: WorkflowTestData, types: INodeTypes return expect(resultData, msg).toEqual(testData.output.nodeData[nodeName]); }); - expect(result.finished).toEqual(true); + expect(result.finished || result.status === 'waiting').toEqual(true); }; const preparePinData = (pinData: IDataObject) => {