mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
feat(Gmail Trigger Node): Add filter option to include drafts (#11441)
This commit is contained in:
parent
a6070afdda
commit
7a2be77f38
|
@ -24,7 +24,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],
|
version: [1, 1.1, 1.2],
|
||||||
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"}}',
|
||||||
|
@ -106,6 +106,13 @@ export class GmailTrigger implements INodeType {
|
||||||
default: false,
|
default: false,
|
||||||
description: 'Whether to include messages from SPAM and TRASH in the results',
|
description: 'Whether to include messages from SPAM and TRASH in the results',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Include Drafts',
|
||||||
|
name: 'includeDrafts',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: 'Whether to include email drafts in the results',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Label Names or IDs',
|
displayName: 'Label Names or IDs',
|
||||||
name: 'labelIds',
|
name: 'labelIds',
|
||||||
|
@ -284,6 +291,15 @@ export class GmailTrigger implements INodeType {
|
||||||
qs.format = 'raw';
|
qs.format = 'raw';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let includeDrafts;
|
||||||
|
if (node.typeVersion > 1.1) {
|
||||||
|
includeDrafts = (qs.includeDrafts as boolean) ?? false;
|
||||||
|
} else {
|
||||||
|
includeDrafts = (qs.includeDrafts as boolean) ?? true;
|
||||||
|
}
|
||||||
|
delete qs.includeDrafts;
|
||||||
|
const withoutDrafts = [];
|
||||||
|
|
||||||
for (let i = 0; i < responseData.length; i++) {
|
for (let i = 0; i < responseData.length; i++) {
|
||||||
responseData[i] = await googleApiRequest.call(
|
responseData[i] = await googleApiRequest.call(
|
||||||
this,
|
this,
|
||||||
|
@ -292,8 +308,12 @@ export class GmailTrigger implements INodeType {
|
||||||
{},
|
{},
|
||||||
qs,
|
qs,
|
||||||
);
|
);
|
||||||
|
if (!includeDrafts) {
|
||||||
if (!simple) {
|
if (responseData[i].labelIds.includes('DRAFT')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!simple && responseData?.length) {
|
||||||
const dataPropertyNameDownload =
|
const dataPropertyNameDownload =
|
||||||
(options.dataPropertyAttachmentsPrefixName as string) || 'attachment_';
|
(options.dataPropertyAttachmentsPrefixName as string) || 'attachment_';
|
||||||
|
|
||||||
|
@ -303,9 +323,14 @@ export class GmailTrigger implements INodeType {
|
||||||
dataPropertyNameDownload,
|
dataPropertyNameDownload,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
withoutDrafts.push(responseData[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (simple) {
|
if (!includeDrafts) {
|
||||||
|
responseData = withoutDrafts;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (simple && responseData?.length) {
|
||||||
responseData = this.helpers.returnJsonArray(
|
responseData = this.helpers.returnJsonArray(
|
||||||
await simplifyOutput.call(this, responseData as IDataObject[]),
|
await simplifyOutput.call(this, responseData as IDataObject[]),
|
||||||
);
|
);
|
||||||
|
@ -324,17 +349,14 @@ export class GmailTrigger implements INodeType {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!responseData?.length) {
|
if (!responseData?.length) {
|
||||||
nodeStaticData.lastTimeChecked = endDate;
|
nodeStaticData.lastTimeChecked = endDate;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const emailsWithInvalidDate = new Set<string>();
|
const emailsWithInvalidDate = new Set<string>();
|
||||||
|
|
||||||
const getEmailDateAsSeconds = (email: IDataObject): number => {
|
const getEmailDateAsSeconds = (email: IDataObject): number => {
|
||||||
let date;
|
let date;
|
||||||
|
|
||||||
if (email.internalDate) {
|
if (email.internalDate) {
|
||||||
date = +(email.internalDate as string) / 1000;
|
date = +(email.internalDate as string) / 1000;
|
||||||
} else if (email.date) {
|
} else if (email.date) {
|
||||||
|
|
Loading…
Reference in a new issue