Try this fix

This commit is contained in:
Ryahn 2025-01-27 20:09:06 -05:00
parent 41a73b5e4f
commit ef822a1c3c

View File

@ -7,23 +7,15 @@ exports.register = function () {
if (!transaction) return next();
try {
// Get the full message body
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);
}
}
// Debug logging
connection.logdebug(plugin, 'Message Stream Type:', typeof transaction.message_stream);
connection.logdebug(plugin, 'Message Stream:', transaction.message_stream);
// Get the raw email content
const body = await new Promise((resolve, reject) => {
let messageContent = '';
transaction.message_stream.on('data', chunk => {
messageContent += chunk.toString();
});
transaction.message_stream.on('end', () => resolve(messageContent));
transaction.message_stream.on('error', reject);
});
const messageData = {
from: transaction.mail_from.address(),
@ -33,11 +25,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) {