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',
|
||||
icon: 'file:gmail.svg',
|
||||
group: ['trigger'],
|
||||
version: [1, 1.1],
|
||||
version: [1, 1.1, 1.2],
|
||||
description:
|
||||
'Fetches emails from Gmail and starts the workflow on specified polling intervals.',
|
||||
subtitle: '={{"Gmail Trigger"}}',
|
||||
|
@ -106,6 +106,13 @@ export class GmailTrigger implements INodeType {
|
|||
default: false,
|
||||
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',
|
||||
name: 'labelIds',
|
||||
|
@ -284,6 +291,15 @@ export class GmailTrigger implements INodeType {
|
|||
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++) {
|
||||
responseData[i] = await googleApiRequest.call(
|
||||
this,
|
||||
|
@ -292,8 +308,12 @@ export class GmailTrigger implements INodeType {
|
|||
{},
|
||||
qs,
|
||||
);
|
||||
|
||||
if (!simple) {
|
||||
if (!includeDrafts) {
|
||||
if (responseData[i].labelIds.includes('DRAFT')) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!simple && responseData?.length) {
|
||||
const dataPropertyNameDownload =
|
||||
(options.dataPropertyAttachmentsPrefixName as string) || 'attachment_';
|
||||
|
||||
|
@ -303,9 +323,14 @@ export class GmailTrigger implements INodeType {
|
|||
dataPropertyNameDownload,
|
||||
);
|
||||
}
|
||||
withoutDrafts.push(responseData[i]);
|
||||
}
|
||||
|
||||
if (simple) {
|
||||
if (!includeDrafts) {
|
||||
responseData = withoutDrafts;
|
||||
}
|
||||
|
||||
if (simple && responseData?.length) {
|
||||
responseData = this.helpers.returnJsonArray(
|
||||
await simplifyOutput.call(this, responseData as IDataObject[]),
|
||||
);
|
||||
|
@ -324,17 +349,14 @@ export class GmailTrigger implements INodeType {
|
|||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (!responseData?.length) {
|
||||
nodeStaticData.lastTimeChecked = endDate;
|
||||
return null;
|
||||
}
|
||||
|
||||
const emailsWithInvalidDate = new Set<string>();
|
||||
|
||||
const getEmailDateAsSeconds = (email: IDataObject): number => {
|
||||
let date;
|
||||
|
||||
if (email.internalDate) {
|
||||
date = +(email.internalDate as string) / 1000;
|
||||
} else if (email.date) {
|
||||
|
|
Loading…
Reference in a new issue