From 8b2244bd16bf3edaf5b63b1c49b308404a87f2cc Mon Sep 17 00:00:00 2001 From: Ryahn Date: Mon, 27 Jan 2025 19:13:46 -0500 Subject: [PATCH] Fix null on body --- src/haraka-plugins/queue/store_message.js | 40 ++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/haraka-plugins/queue/store_message.js b/src/haraka-plugins/queue/store_message.js index 8864a9e..fb0709c 100644 --- a/src/haraka-plugins/queue/store_message.js +++ b/src/haraka-plugins/queue/store_message.js @@ -7,12 +7,32 @@ exports.register = function () { if (!transaction) return next(); try { + // Get body content more reliably + let body = ''; + + // Check if we have a message body + if (transaction.body) { + if (transaction.body.bodytext) { + body = transaction.body.bodytext; + } else if (transaction.body.children) { + // Handle multipart messages + body = transaction.body.children.map(child => { + if (child.bodytext) return child.bodytext; + return ''; + }).join('\n'); + } + } + + // Get headers safely + const headers = transaction.header ? transaction.header.headers_decoded : {}; + const subject = transaction.header ? transaction.header.get('subject') : ''; + const messageData = { from: transaction.mail_from.address(), to: transaction.rcpt_to.map((addr) => addr.address()).join(", "), - subject: transaction.header.get("subject"), - body: transaction.body.bodytext, - headers: transaction.header.headers_decoded, + subject: subject, + body: body, + headers: headers, domain: transaction.rcpt_to[0].host, }; @@ -24,5 +44,17 @@ exports.register = function () { } }; - plugin.register_hook("queue", "store_message"); + // Add data hook to ensure body is parsed + plugin.register_hook('data_post', 'parse_body'); + plugin.register_hook('queue', 'store_message'); }; + +// Add body parser +exports.parse_body = function (next, connection) { + const transaction = connection.transaction; + if (!transaction) return next(); + + // Force body parsing + transaction.parse_body = true; + next(); +}; \ No newline at end of file