mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(Email Trigger (IMAP) Node): Migrate from imap-simple to @n8n/imap (#8899)
Co-authored-by: Jonathan Bennetts <jonathan.bennetts@gmail.com>
This commit is contained in:
committed by
GitHub
parent
28261047c3
commit
9f87cc25a0
@@ -16,8 +16,8 @@ import type {
|
||||
} from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import type { ImapSimple, ImapSimpleOptions, Message } from 'imap-simple';
|
||||
import { connect as imapConnect, getParts } from 'imap-simple';
|
||||
import type { ImapSimple, ImapSimpleOptions, Message } from '@n8n/imap';
|
||||
import { connect as imapConnect, getParts } from '@n8n/imap';
|
||||
import type { Source as ParserSource } from 'mailparser';
|
||||
import { simpleParser } from 'mailparser';
|
||||
|
||||
@@ -255,12 +255,9 @@ export class EmailReadImapV1 implements INodeType {
|
||||
if (!isEmpty(tlsOptions)) {
|
||||
config.imap.tlsOptions = tlsOptions;
|
||||
}
|
||||
const conn = imapConnect(config).then(async (entry) => {
|
||||
return entry;
|
||||
});
|
||||
(await conn).getBoxes((_err, _boxes) => {});
|
||||
const connection = await imapConnect(config);
|
||||
await connection.getBoxes();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return {
|
||||
status: 'Error',
|
||||
message: error.message,
|
||||
@@ -333,7 +330,7 @@ export class EmailReadImapV1 implements INodeType {
|
||||
.then(async (partData) => {
|
||||
// Return it in the format n8n expects
|
||||
return await this.helpers.prepareBinaryData(
|
||||
partData as Buffer,
|
||||
Buffer.from(partData),
|
||||
attachmentPart.disposition.params.filename as string,
|
||||
);
|
||||
});
|
||||
@@ -370,7 +367,7 @@ export class EmailReadImapV1 implements INodeType {
|
||||
const results = await imapConnection.search(searchCriteria, fetchOptions);
|
||||
|
||||
const newEmails: INodeExecutionData[] = [];
|
||||
let newEmail: INodeExecutionData, messageHeader, messageBody;
|
||||
let newEmail: INodeExecutionData;
|
||||
let attachments: IBinaryData[];
|
||||
let propertyName: string;
|
||||
|
||||
@@ -442,11 +439,9 @@ export class EmailReadImapV1 implements INodeType {
|
||||
},
|
||||
};
|
||||
|
||||
messageHeader = message.parts.filter((part) => {
|
||||
return part.which === 'HEADER';
|
||||
});
|
||||
const messageHeader = message.parts.filter((part) => part.which === 'HEADER');
|
||||
|
||||
messageBody = messageHeader[0].body;
|
||||
const messageBody = messageHeader[0].body as Record<string, string[]>;
|
||||
for (propertyName of Object.keys(messageBody as IDataObject)) {
|
||||
if (messageBody[propertyName].length) {
|
||||
if (topLevelProperties.includes(propertyName)) {
|
||||
@@ -532,7 +527,7 @@ export class EmailReadImapV1 implements INodeType {
|
||||
tls: credentials.secure as boolean,
|
||||
authTimeout: 20000,
|
||||
},
|
||||
onmail: async () => {
|
||||
onMail: async () => {
|
||||
if (connection) {
|
||||
if (staticData.lastMessageUid !== undefined) {
|
||||
searchCriteria.push(['UID', `${staticData.lastMessageUid as number}:*`]);
|
||||
|
||||
Reference in New Issue
Block a user