UNPKG

n8n-nodes-imap-ai

Version:

Simplified IMAP node for n8n with AI-agent support. Clean and modular email and mailbox management for automation workflows.

97 lines 3.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ImapMethods = void 0; const n8n_workflow_1 = require("n8n-workflow"); const imapflow_1 = require("imapflow"); exports.ImapMethods = { loadOptions: { async getMailboxes() { console.log('getMailboxes loadOptions method called'); const credentials = await this.getCredentials('imap'); console.log('Credentials obtained'); const client = new imapflow_1.ImapFlow({ host: credentials.host, port: credentials.port, secure: credentials.secure, auth: { user: credentials.user, pass: credentials.password, }, socketTimeout: 10 * 60 * 1000, connectionTimeout: 15 * 1000, greetingTimeout: 10 * 1000, }); try { await client.connect(); const mailboxes = await client.list(); return mailboxes .filter(mailbox => { var _a; return !((_a = mailbox.flags) === null || _a === void 0 ? void 0 : _a.has('\\Noselect')); }) .map(mailbox => ({ name: mailbox.name, value: mailbox.name, })) .sort((a, b) => a.name.localeCompare(b.name)); } catch (error) { throw new n8n_workflow_1.NodeApiError(this.getNode(), { message: `Failed to load mailboxes: ${error.message}`, }); } finally { try { await client.logout(); } catch (error) { } } }, }, listSearch: { async getMailboxes(filter) { console.log('getMailboxes listSearch method called with filter:', filter); const credentials = await this.getCredentials('imap'); const client = new imapflow_1.ImapFlow({ host: credentials.host, port: credentials.port, secure: credentials.secure, auth: { user: credentials.user, pass: credentials.password, }, socketTimeout: 10 * 60 * 1000, connectionTimeout: 15 * 1000, greetingTimeout: 10 * 1000, }); try { await client.connect(); const mailboxes = await client.list(); let filteredMailboxes = mailboxes.filter(mailbox => { var _a; return !((_a = mailbox.flags) === null || _a === void 0 ? void 0 : _a.has('\\Noselect')); }); if (filter) { filteredMailboxes = filteredMailboxes.filter(mailbox => mailbox.name.toLowerCase().includes(filter.toLowerCase())); } const results = filteredMailboxes .map(mailbox => ({ name: mailbox.name, value: mailbox.name, })) .sort((a, b) => a.name.localeCompare(b.name)); return { results, }; } catch (error) { throw new n8n_workflow_1.NodeApiError(this.getNode(), { message: `Failed to load mailboxes: ${error.message}`, }); } finally { try { await client.logout(); } catch (error) { } } }, }, }; //# sourceMappingURL=ImapMethods.js.map