More fixes
This commit is contained in:
parent
98293e5e96
commit
350b2f5f7a
@ -7,23 +7,20 @@ 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') {
|
|
||||||
body = JSON.stringify(transaction.message_stream);
|
|
||||||
} else {
|
|
||||||
body = String(transaction.message_stream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debug logging
|
// Split on double newline to separate headers and body
|
||||||
connection.logdebug(plugin, 'Message Stream Type:', typeof transaction.message_stream);
|
const parts = fullMessage.split('\r\n\r\n');
|
||||||
connection.logdebug(plugin, 'Message Stream:', transaction.message_stream);
|
if (parts.length > 1) {
|
||||||
|
// Get everything after the headers
|
||||||
|
body = parts.slice(1).join('\r\n\r\n').trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const messageData = {
|
const messageData = {
|
||||||
from: transaction.mail_from.address(),
|
from: transaction.mail_from.address(),
|
||||||
@ -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) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user