mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(Email Trigger (IMAP) Node): Option to disable last message id tracking (#17964)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { mock } from 'jest-mock-extended';
|
import { mock } from 'jest-mock-extended';
|
||||||
import { type INodeTypeBaseDescription, type ITriggerFunctions } from 'n8n-workflow';
|
import type { INode, INodeTypeBaseDescription, ITriggerFunctions } from 'n8n-workflow';
|
||||||
|
|
||||||
import { type ICredentialsDataImap } from '@credentials/Imap.credentials';
|
import { type ICredentialsDataImap } from '@credentials/Imap.credentials';
|
||||||
|
|
||||||
@@ -42,6 +42,7 @@ describe('Test IMap V2', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
triggerFunctions.getCredentials.calledWith('imap').mockResolvedValue(credentials);
|
triggerFunctions.getCredentials.calledWith('imap').mockResolvedValue(credentials);
|
||||||
|
triggerFunctions.getNode.mockReturnValue(mock<INode>({ typeVersion: 2.1 }));
|
||||||
triggerFunctions.logger.debug = jest.fn();
|
triggerFunctions.logger.debug = jest.fn();
|
||||||
triggerFunctions.getNodeParameter.calledWith('options').mockReturnValue({
|
triggerFunctions.getNodeParameter.calledWith('options').mockReturnValue({
|
||||||
name: 'Mark as Read',
|
name: 'Mark as Read',
|
||||||
|
|||||||
@@ -177,6 +177,19 @@ const versionDescription: INodeTypeDescription = {
|
|||||||
default: 60,
|
default: 60,
|
||||||
description: 'Sets an interval (in minutes) to force a reconnection',
|
description: 'Sets an interval (in minutes) to force a reconnection',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Fetch Only New Emails',
|
||||||
|
name: 'trackLastMessageId',
|
||||||
|
type: 'boolean',
|
||||||
|
default: true,
|
||||||
|
description:
|
||||||
|
'Whether to fetch only new emails since the last run, or all emails that match the "Custom Email Rules" (["UNSEEN"] by default)',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
'@version': [{ _cnd: { gte: 2.1 } }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -247,6 +260,7 @@ export class EmailReadImapV2 implements INodeType {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async trigger(this: ITriggerFunctions): Promise<ITriggerResponse> {
|
async trigger(this: ITriggerFunctions): Promise<ITriggerResponse> {
|
||||||
|
const node = this.getNode();
|
||||||
const credentialsObject = await this.getCredentials('imap');
|
const credentialsObject = await this.getCredentials('imap');
|
||||||
const credentials = isCredentialsDataImap(credentialsObject) ? credentialsObject : undefined;
|
const credentials = isCredentialsDataImap(credentialsObject) ? credentialsObject : undefined;
|
||||||
if (!credentials) {
|
if (!credentials) {
|
||||||
@@ -258,6 +272,15 @@ export class EmailReadImapV2 implements INodeType {
|
|||||||
const activatedAt = DateTime.now();
|
const activatedAt = DateTime.now();
|
||||||
|
|
||||||
const staticData = this.getWorkflowStaticData('node');
|
const staticData = this.getWorkflowStaticData('node');
|
||||||
|
if (node.typeVersion <= 2) {
|
||||||
|
// before v 2.1 staticData.lastMessageUid was never set, preserve that behavior
|
||||||
|
staticData.lastMessageUid = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.trackLastMessageId === false) {
|
||||||
|
staticData.lastMessageUid = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.debug('Loaded static data for node "EmailReadImap"', { staticData });
|
this.logger.debug('Loaded static data for node "EmailReadImap"', { staticData });
|
||||||
|
|
||||||
let connection: ImapSimple;
|
let connection: ImapSimple;
|
||||||
@@ -387,7 +410,7 @@ export class EmailReadImapV2 implements INodeType {
|
|||||||
* by checking UIDValidity.
|
* by checking UIDValidity.
|
||||||
*/
|
*/
|
||||||
searchCriteria.push(['UID', `${staticData.lastMessageUid as number}:*`]);
|
searchCriteria.push(['UID', `${staticData.lastMessageUid as number}:*`]);
|
||||||
} else {
|
} else if (node.typeVersion > 2 && options.trackLastMessageId !== false) {
|
||||||
searchCriteria.push(['SINCE', activatedAt.toFormat('dd-LLL-yyyy')]);
|
searchCriteria.push(['SINCE', activatedAt.toFormat('dd-LLL-yyyy')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user