mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 13:27:31 -08:00
🐛 Fix attempt to reconnect and make IMAP node stable (#1667)
This commit is contained in:
parent
3fe52c84d5
commit
73da7998cf
|
@ -354,35 +354,48 @@ export class EmailReadImap implements INodeType {
|
||||||
return newEmails;
|
return newEmails;
|
||||||
};
|
};
|
||||||
|
|
||||||
let connection: ImapSimple;
|
const establishConnection = (): Promise<ImapSimple> => {
|
||||||
|
const config: ImapSimpleOptions = {
|
||||||
|
imap: {
|
||||||
|
user: credentials.user as string,
|
||||||
|
password: credentials.password as string,
|
||||||
|
host: credentials.host as string,
|
||||||
|
port: credentials.port as number,
|
||||||
|
tls: credentials.secure as boolean,
|
||||||
|
authTimeout: 20000,
|
||||||
|
},
|
||||||
|
onmail: async () => {
|
||||||
|
if (connection) {
|
||||||
|
const returnData = await getNewEmails(connection, searchCriteria);
|
||||||
|
|
||||||
const config: ImapSimpleOptions = {
|
if (returnData.length) {
|
||||||
imap: {
|
this.emit([returnData]);
|
||||||
user: credentials.user as string,
|
}
|
||||||
password: credentials.password as string,
|
}
|
||||||
host: credentials.host as string,
|
},
|
||||||
port: credentials.port as number,
|
};
|
||||||
tls: credentials.secure as boolean,
|
|
||||||
authTimeout: 20000,
|
|
||||||
},
|
|
||||||
onmail: async () => {
|
|
||||||
const returnData = await getNewEmails(connection, searchCriteria);
|
|
||||||
|
|
||||||
if (returnData.length) {
|
if (options.allowUnauthorizedCerts === true) {
|
||||||
this.emit([returnData]);
|
config.imap.tlsOptions = {
|
||||||
}
|
rejectUnauthorized: false,
|
||||||
},
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connect to the IMAP server and open the mailbox
|
||||||
|
// that we get informed whenever a new email arrives
|
||||||
|
return imapConnect(config).then(async conn => {
|
||||||
|
conn.on('error', async err => {
|
||||||
|
if (err.code.toUpperCase() === 'ECONNRESET') {
|
||||||
|
connection = await establishConnection();
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
return conn;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options.allowUnauthorizedCerts === true) {
|
let connection: ImapSimple = await establishConnection();
|
||||||
config.imap.tlsOptions = {
|
|
||||||
rejectUnauthorized: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect to the IMAP server and open the mailbox
|
|
||||||
// that we get informed whenever a new email arrives
|
|
||||||
connection = await imapConnect(config);
|
|
||||||
await connection.openBox(mailbox);
|
await connection.openBox(mailbox);
|
||||||
|
|
||||||
// When workflow and so node gets set to inactive close the connectoin
|
// When workflow and so node gets set to inactive close the connectoin
|
||||||
|
|
Loading…
Reference in a new issue