This commit is contained in:
Ryahn 2025-01-27 20:09:54 -05:00
parent ef822a1c3c
commit 98293e5e96

View File

@ -7,15 +7,23 @@ exports.register = function () {
if (!transaction) return next();
try {
// 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);
});
// 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);
const messageData = {
from: transaction.mail_from.address(),
@ -25,6 +33,11 @@ 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) {