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.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.moveEmailOperation = 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.moveEmailOperation = {
operation: {
name: 'Move',
value: 'moveEmail',
description: 'Move emails from one mailbox to another. Perfect for AI agents to organize emails automatically, archive processed messages, sort by category, or implement email workflows.',
},
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 move') }}",
description: 'UID of the email to move. 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 move multiple emails at once',
},
{
...SearchFieldParameters_1.parameterSelectMailbox,
displayName: 'Destination Mailbox',
description: 'Select the destination mailbox where emails will be moved. AI agents can specify target folders like: Archive, Processed, Spam, 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(`Moving email "${emailUid}" from "${sourceMailboxPath}" to "${destinationMailboxPath}"`);
await client.mailboxOpen(sourceMailboxPath, { readOnly: false });
const resp = await client.messageMove(emailUid, destinationMailboxPath, {
uid: true,
});
if (!resp) {
throw new n8n_workflow_1.NodeApiError(context.getNode(), {}, {
message: `Unable to move email UID ${emailUid} from ${sourceMailboxPath} to ${destinationMailboxPath}`,
});
}
const item_json = JSON.parse(JSON.stringify(resp));
item_json.operation = 'moveEmail';
item_json.sourceMailbox = sourceMailboxPath;
item_json.destinationMailbox = destinationMailboxPath;
item_json.emailUid = emailUid;
item_json.success = true;
returnData.push({
json: item_json,
});
return returnData;
},
};
//# sourceMappingURL=EmailMove.js.map