diff --git a/src/haraka-plugins/queue/store_message.js b/src/haraka-plugins/queue/store_message.js index 0e945af..8df2417 100644 --- a/src/haraka-plugins/queue/store_message.js +++ b/src/haraka-plugins/queue/store_message.js @@ -7,24 +7,21 @@ exports.register = function () { if (!transaction) return next(); try { - // Get the full message body + // Get the body content by processing the message stream buffers let body = ''; - if (transaction.message_stream) { - // Convert Buffer to string and handle JSON stringification properly - if (Buffer.isBuffer(transaction.message_stream)) { - body = transaction.message_stream.toString('utf8'); - } else if (typeof transaction.message_stream === 'object') { - body = JSON.stringify(transaction.message_stream); - } else { - body = String(transaction.message_stream); + if (transaction.message_stream && transaction.message_stream._queue) { + // Convert the buffer to string + const fullMessage = Buffer.from(transaction.message_stream._queue[0]).toString('utf8'); + + // Split on double newline to separate headers and body + const parts = fullMessage.split('\r\n\r\n'); + if (parts.length > 1) { + // Get everything after the headers + body = parts.slice(1).join('\r\n\r\n').trim(); } } - // Debug logging - connection.logdebug(plugin, 'Message Stream Type:', typeof transaction.message_stream); - connection.logdebug(plugin, 'Message Stream:', transaction.message_stream); - const messageData = { from: transaction.mail_from.address(), to: transaction.rcpt_to.map((addr) => addr.address()).join(", "), @@ -33,11 +30,6 @@ exports.register = function () { headers: transaction.header ? transaction.header.headers_decoded : {}, }; - // Debug logging - connection.logdebug(plugin, 'Message Data:'); - connection.logdebug(plugin, `Body type: ${typeof body}`); - connection.logdebug(plugin, `Body content: ${body.substring(0, 100)}...`); // First 100 chars - await MessageService.store(messageData); next(); } catch (error) {