mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +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 { type INodeTypeBaseDescription, type ITriggerFunctions } from 'n8n-workflow';
|
||||
import type { INode, INodeTypeBaseDescription, ITriggerFunctions } from 'n8n-workflow';
|
||||
|
||||
import { type ICredentialsDataImap } from '@credentials/Imap.credentials';
|
||||
|
||||
@@ -42,6 +42,7 @@ describe('Test IMap V2', () => {
|
||||
};
|
||||
|
||||
triggerFunctions.getCredentials.calledWith('imap').mockResolvedValue(credentials);
|
||||
triggerFunctions.getNode.mockReturnValue(mock<INode>({ typeVersion: 2.1 }));
|
||||
triggerFunctions.logger.debug = jest.fn();
|
||||
triggerFunctions.getNodeParameter.calledWith('options').mockReturnValue({
|
||||
name: 'Mark as Read',
|
||||
|
||||
@@ -177,6 +177,19 @@ const versionDescription: INodeTypeDescription = {
|
||||
default: 60,
|
||||
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> {
|
||||
const node = this.getNode();
|
||||
const credentialsObject = await this.getCredentials('imap');
|
||||
const credentials = isCredentialsDataImap(credentialsObject) ? credentialsObject : undefined;
|
||||
if (!credentials) {
|
||||
@@ -258,6 +272,15 @@ export class EmailReadImapV2 implements INodeType {
|
||||
const activatedAt = DateTime.now();
|
||||
|
||||
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 });
|
||||
|
||||
let connection: ImapSimple;
|
||||
@@ -387,7 +410,7 @@ export class EmailReadImapV2 implements INodeType {
|
||||
* by checking UIDValidity.
|
||||
*/
|
||||
searchCriteria.push(['UID', `${staticData.lastMessageUid as number}:*`]);
|
||||
} else {
|
||||
} else if (node.typeVersion > 2 && options.trackLastMessageId !== false) {
|
||||
searchCriteria.push(['SINCE', activatedAt.toFormat('dd-LLL-yyyy')]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user