fix(Gmail Trigger Node): Filter sent emails from trigger results (#17691)

This commit is contained in:
Ria Scholz
2025-07-29 09:37:05 +02:00
committed by GitHub
parent 43f267535d
commit 4bab296075
2 changed files with 113 additions and 1 deletions

View File

@@ -33,7 +33,7 @@ export class GmailTrigger implements INodeType {
name: 'gmailTrigger', name: 'gmailTrigger',
icon: 'file:gmail.svg', icon: 'file:gmail.svg',
group: ['trigger'], group: ['trigger'],
version: [1, 1.1, 1.2], version: [1, 1.1, 1.2, 1.3],
description: description:
'Fetches emails from Gmail and starts the workflow on specified polling intervals.', 'Fetches emails from Gmail and starts the workflow on specified polling intervals.',
subtitle: '={{"Gmail Trigger"}}', subtitle: '={{"Gmail Trigger"}}',
@@ -327,6 +327,10 @@ export class GmailTrigger implements INodeType {
} }
} }
if (node.typeVersion > 1.2 && fullMessage.labelIds?.includes('SENT')) {
continue;
}
if (!simple) { if (!simple) {
const dataPropertyNameDownload = const dataPropertyNameDownload =
options.dataPropertyAttachmentsPrefixName || 'attachment_'; options.dataPropertyAttachmentsPrefixName || 'attachment_';

View File

@@ -271,4 +271,112 @@ describe('GmailTrigger', () => {
expect(response).toMatchSnapshot(); expect(response).toMatchSnapshot();
}); });
it('should skip DRAFTS when option is set', 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: 'DRAFT', name: 'DRAFT' },
],
});
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: ['DRAFT'] }));
nock(baseUrl)
.get(new RegExp('/gmail/v1/users/me/messages/2?.*'))
.reply(200, createMessage({ id: '2', labelIds: ['INBOX'] }));
const { response } = await testPollingTriggerNode(GmailTrigger, {
node: { parameters: { filters: { includeDrafts: false } } },
});
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: '<p>test</p>',
id: '2',
labelIds: ['INBOX'],
sizeEstimate: 4,
threadId: 'testThreadId',
to: {
html: 'to@example.com',
text: 'to@example.com',
value: [{ address: 'to@example.com', name: 'To' }],
},
},
},
],
]);
});
it('should skip emails with SENT label', 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'] }));
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: '<p>test</p>',
id: '1',
labelIds: ['INBOX'],
sizeEstimate: 4,
threadId: 'testThreadId',
to: {
html: 'to@example.com',
text: 'to@example.com',
value: [{ address: 'to@example.com', name: 'To' }],
},
},
},
],
]);
});
}); });