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.

65 lines 3.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.copyEmailOperation = void 0; const n8n_workflow_1 = require("n8n-workflow"); const SearchFieldParameters_1 = require("../../../utils/SearchFieldParameters"); const PARAM_NAME_SOURCE_MAILBOX = 'sourceMailbox'; const PARAM_NAME_DESTINATION_MAILBOX = 'destinationMailbox'; exports.copyEmailOperation = { operation: { name: 'Copy', value: 'copyEmail', description: 'Copy emails from one mailbox to another while keeping the original. Perfect for AI agents to create backups, duplicate for processing, or organize emails across multiple folders.', }, parameters: [ { ...SearchFieldParameters_1.parameterSelectMailbox, displayName: 'Source Mailbox', description: 'Select the source mailbox where emails are currently located. AI agents can specify: INBOX, Sent, Drafts, or custom folder names.', name: PARAM_NAME_SOURCE_MAILBOX, }, { displayName: 'Email UID', name: 'emailUid', type: 'string', default: "={{ $fromAI('email_uid', 'UID of the email or comma-separated list of email UIDs to copy') }}", description: 'UID of the email to copy. AI can specify single UID or comma-separated list for bulk operations.', placeholder: '123 or 123,456,789', hint: 'You can use comma separated list of UIDs to copy multiple emails at once', }, { ...SearchFieldParameters_1.parameterSelectMailbox, displayName: 'Destination Mailbox', description: 'Select the destination mailbox where emails will be copied. AI agents can specify target folders like: Backup, Archive, Processing, or custom categories.', name: PARAM_NAME_DESTINATION_MAILBOX, }, ], async executeImapAction(context, itemIndex, client) { var _a; const returnData = []; const sourceMailboxPath = (0, SearchFieldParameters_1.getMailboxPathFromNodeParameter)(context, itemIndex, PARAM_NAME_SOURCE_MAILBOX); const destinationMailboxPath = (0, SearchFieldParameters_1.getMailboxPathFromNodeParameter)(context, itemIndex, PARAM_NAME_DESTINATION_MAILBOX); const emailUid = context.getNodeParameter('emailUid', itemIndex); (_a = context.logger) === null || _a === void 0 ? void 0 : _a.info(`Copying email "${emailUid}" from "${sourceMailboxPath}" to "${destinationMailboxPath}"`); await client.mailboxOpen(sourceMailboxPath, { readOnly: false }); const resp = await client.messageCopy(emailUid, destinationMailboxPath, { uid: true, }); if (!resp) { throw new n8n_workflow_1.NodeApiError(context.getNode(), {}, { message: `Unable to copy email UID ${emailUid} from ${sourceMailboxPath} to ${destinationMailboxPath}`, }); } const item_json = JSON.parse(JSON.stringify(resp)); item_json.operation = 'copyEmail'; item_json.sourceMailbox = sourceMailboxPath; item_json.destinationMailbox = destinationMailboxPath; item_json.emailUid = emailUid; item_json.success = true; returnData.push({ json: item_json, }); return returnData; }, }; //# sourceMappingURL=EmailCopy.js.map