Try this fix
This commit is contained in:
parent
41a73b5e4f
commit
ef822a1c3c
@ -7,23 +7,15 @@ exports.register = function () {
|
|||||||
if (!transaction) return next();
|
if (!transaction) return next();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get the full message body
|
// Get the raw email content
|
||||||
let body = '';
|
const body = await new Promise((resolve, reject) => {
|
||||||
|
let messageContent = '';
|
||||||
if (transaction.message_stream) {
|
transaction.message_stream.on('data', chunk => {
|
||||||
// Convert Buffer to string and handle JSON stringification properly
|
messageContent += chunk.toString();
|
||||||
if (Buffer.isBuffer(transaction.message_stream)) {
|
});
|
||||||
body = transaction.message_stream.toString('utf8');
|
transaction.message_stream.on('end', () => resolve(messageContent));
|
||||||
} else if (typeof transaction.message_stream === 'object') {
|
transaction.message_stream.on('error', reject);
|
||||||
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 = {
|
const messageData = {
|
||||||
from: transaction.mail_from.address(),
|
from: transaction.mail_from.address(),
|
||||||
@ -33,11 +25,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) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user