/** * @node imap-fetch * @name IMAP Fetch Email * @category email * @version 1.0.1 * @description Fetch the full content of an email from an IMAP server. * @icon download */ const configSchema = { type: 'object', properties: { credentialId: { type: 'string', title: 'IMAP Credential', description: 'Select the IMAP credential to use for authentication', dynamicOptions: { source: 'credentials', filter: { type: 'imap' } } }, mailbox: { type: 'string', title: 'Mailbox', description: 'The mailbox containing the email', default: 'INBOX' }, uid: { type: 'string', title: 'Email UID', description: 'The unique identifier of the email to fetch (can be provided from input)' }, includeRaw: { type: 'boolean', title: 'Include Raw', description: 'Include the raw email content in the output', default: false } }, required: ['credentialId'] }; const inputSchema = { type: 'object', properties: { uid: { type: 'string', description: 'Email UID to fetch' }, mailbox: { type: 'string', description: 'Override mailbox from input' } } }; const outputSchema = { type: 'object', properties: { uid: { type: 'string' }, subject: { type: 'string' }, from: { type: 'string' }, to: { type: 'string' }, date: { type: 'string' }, body: { type: 'string' }, raw: { type: 'string' } } }; const outputs = [ { name: 'main', displayName: 'Email Content', type: 'object', color: '#8b5cf6' } ]; module.exports = { configSchema, inputSchema, outputSchema, outputs, async execute(config, input, context) { const credentialId = config.credentialId; const mailbox = input.mailbox || config.mailbox || 'INBOX'; const uid = input.uid || config.uid; const includeRaw = config.includeRaw || false; if (!credentialId) { throw new Error('IMAP credential is required'); } if (!uid) { throw new Error('Email UID is required'); } // Fetch the email const fetchResult = smartbotic.imap.fetch({ credentialId, mailbox, uid }); if (!fetchResult.success) { throw new Error(`IMAP fetch failed: ${fetchResult.error}`); } const result = { uid: fetchResult.uid, subject: fetchResult.subject, from: fetchResult.from, to: fetchResult.to, date: fetchResult.date, body: fetchResult.body, mailbox }; if (includeRaw) { result.raw = fetchResult.raw; } return result; } };