n8n-nodes-imap-ai
Version:
Simplified IMAP node for n8n with AI-agent support. Clean and modular email and mailbox management for automation workflows.
69 lines • 2.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parameterSelectMailbox = void 0;
exports.loadMailboxList = loadMailboxList;
exports.getMailboxPathFromNodeParameter = getMailboxPathFromNodeParameter;
const CredentialsSelector_1 = require("./CredentialsSelector");
const ImapUtils_1 = require("./ImapUtils");
async function loadMailboxList() {
const credentials = (await (0, CredentialsSelector_1.getImapCredentials)(this));
const client = (0, ImapUtils_1.createImapClient)(credentials, this.logger);
await client.connect();
const mailboxes = await client.list();
client.close();
return {
results: mailboxes.map((mailbox) => ({
name: mailbox.path,
value: mailbox.path,
})),
};
}
const DEFAULT_MAILBOX_PARAMETER_NAME = 'mailboxPath';
exports.parameterSelectMailbox = {
displayName: 'Mailbox',
name: DEFAULT_MAILBOX_PARAMETER_NAME,
type: 'resourceLocator',
default: {
mode: 'list',
value: 'INBOX',
},
description: 'Select the mailbox',
required: true,
modes: [
{
displayName: 'List',
name: 'list',
type: 'list',
typeOptions: {
searchListMethod: 'loadMailboxList',
searchable: false,
searchFilterRequired: false,
},
},
{
displayName: 'Path',
name: 'path',
type: 'string',
hint: 'Full path to mailbox in the format same as returned by List Mailboxes operation',
validation: [],
placeholder: 'Full path to mailbox',
},
],
};
function getMailboxPathFromNodeParameter(context, itemIndex, paramName = DEFAULT_MAILBOX_PARAMETER_NAME) {
try {
const mailboxPathObj = context.getNodeParameter(paramName, itemIndex);
if (!mailboxPathObj) {
return '';
}
if ('value' in mailboxPathObj === false) {
return '';
}
const mailboxPath = mailboxPathObj.value;
return mailboxPath;
}
catch (error) {
return '';
}
}
//# sourceMappingURL=SearchFieldParameters.js.map