From 47f1d14b66b94ee9d0713a60e8837eef35fb56e1 Mon Sep 17 00:00:00 2001 From: GURAASEES SINGH TANEJA <160568211+GuraaseesSingh@users.noreply.github.com> Date: Fri, 12 Sep 2025 19:17:24 +0530 Subject: [PATCH] fix(Gmail Trigger Node): Handle self-sent emails in inbox (#19351) Co-authored-by: riascho <123465523+riascho@users.noreply.github.com> --- .../nodes/Google/Gmail/GmailTrigger.node.ts | 7 ++- .../Google/Gmail/test/GmailTrigger.test.ts | 52 +++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/packages/nodes-base/nodes/Google/Gmail/GmailTrigger.node.ts b/packages/nodes-base/nodes/Google/Gmail/GmailTrigger.node.ts index 73d0ca9b19..98ea9dc063 100644 --- a/packages/nodes-base/nodes/Google/Gmail/GmailTrigger.node.ts +++ b/packages/nodes-base/nodes/Google/Gmail/GmailTrigger.node.ts @@ -326,8 +326,11 @@ export class GmailTrigger implements INodeType { continue; } } - - if (node.typeVersion > 1.2 && fullMessage.labelIds?.includes('SENT')) { + if ( + node.typeVersion > 1.2 && + fullMessage.labelIds?.includes('SENT') && + !fullMessage.labelIds?.includes('INBOX') + ) { continue; } diff --git a/packages/nodes-base/nodes/Google/Gmail/test/GmailTrigger.test.ts b/packages/nodes-base/nodes/Google/Gmail/test/GmailTrigger.test.ts index 35da637dd5..ff26a2b0aa 100644 --- a/packages/nodes-base/nodes/Google/Gmail/test/GmailTrigger.test.ts +++ b/packages/nodes-base/nodes/Google/Gmail/test/GmailTrigger.test.ts @@ -379,4 +379,56 @@ describe('GmailTrigger', () => { ], ]); }); + + it('should not skip emails that were sent to own account', async () => { + const messageListResponse: MessageListResponse = { + messages: [createListMessage({ id: '1' }), createListMessage({ id: '2' })], + resultSizeEstimate: 2, + }; + nock(baseUrl) + .get('/gmail/v1/users/me/labels') + .reply(200, { + labels: [ + { id: 'INBOX', name: 'INBOX' }, + { id: 'SENT', name: 'SENT' }, + ], + }); + nock(baseUrl).get(new RegExp('/gmail/v1/users/me/messages?.*')).reply(200, messageListResponse); + nock(baseUrl) + .get(new RegExp('/gmail/v1/users/me/messages/1?.*')) + .reply(200, createMessage({ id: '1', labelIds: ['INBOX', 'SENT'] })); + nock(baseUrl) + .get(new RegExp('/gmail/v1/users/me/messages/2?.*')) + .reply(200, createMessage({ id: '2', labelIds: ['SENT'] })); + + const { response } = await testPollingTriggerNode(GmailTrigger); + expect(response).toEqual([ + [ + { + binary: undefined, + json: { + attachements: undefined, + date: '2024-08-31T00:00:00.000Z', + from: { + html: 'from@example.com', + text: 'from@example.com', + value: [{ address: 'from@example.com', name: 'From' }], + }, + headerlines: undefined, + headers: { headerKey: 'headerValue' }, + html: '
test
', + id: '1', + labelIds: ['INBOX', 'SENT'], + sizeEstimate: 4, + threadId: 'testThreadId', + to: { + html: 'to@example.com', + text: 'to@example.com', + value: [{ address: 'to@example.com', name: 'To' }], + }, + }, + }, + ], + ]); + }); });