More fixes

This commit is contained in:
Ryahn 2025-01-27 20:11:47 -05:00
parent 98293e5e96
commit 350b2f5f7a

View File

@ -7,24 +7,21 @@ exports.register = function () {
if (!transaction) return next(); if (!transaction) return next();
try { try {
// Get the full message body // Get the body content by processing the message stream buffers
let body = ''; let body = '';
if (transaction.message_stream) { if (transaction.message_stream && transaction.message_stream._queue) {
// Convert Buffer to string and handle JSON stringification properly // Convert the buffer to string
if (Buffer.isBuffer(transaction.message_stream)) { const fullMessage = Buffer.from(transaction.message_stream._queue[0]).toString('utf8');
body = transaction.message_stream.toString('utf8');
} else if (typeof transaction.message_stream === 'object') { // Split on double newline to separate headers and body
body = JSON.stringify(transaction.message_stream); const parts = fullMessage.split('\r\n\r\n');
} else { if (parts.length > 1) {
body = String(transaction.message_stream); // 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 = { const messageData = {
from: transaction.mail_from.address(), from: transaction.mail_from.address(),
to: transaction.rcpt_to.map((addr) => addr.address()).join(", "), to: transaction.rcpt_to.map((addr) => addr.address()).join(", "),
@ -33,11 +30,6 @@ exports.register = function () {
headers: transaction.header ? transaction.header.headers_decoded : {}, 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); await MessageService.store(messageData);
next(); next();
} catch (error) { } catch (error) {