Fix body beings stored as [object]
This commit is contained in:
parent
e8785a5bbc
commit
41a73b5e4f
@ -7,32 +7,36 @@ exports.register = function () {
|
||||
if (!transaction) return next();
|
||||
|
||||
try {
|
||||
// Get the full message body as a string
|
||||
// Get the full message body
|
||||
let body = '';
|
||||
|
||||
if (transaction.message_stream) {
|
||||
// Convert message stream to string
|
||||
body = transaction.message_stream.toString();
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
// Get headers safely
|
||||
const headers = transaction.header ? transaction.header.headers_decoded : {};
|
||||
const subject = transaction.header ? transaction.header.get('subject') : '';
|
||||
// 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(),
|
||||
to: transaction.rcpt_to.map((addr) => addr.address()).join(", "),
|
||||
subject: subject,
|
||||
subject: transaction.header ? transaction.header.get('subject') : '',
|
||||
body: body,
|
||||
headers: headers,
|
||||
headers: transaction.header ? transaction.header.headers_decoded : {},
|
||||
};
|
||||
|
||||
// Debug logging
|
||||
connection.logdebug(plugin, 'Message Data:');
|
||||
connection.logdebug(plugin, `From: ${messageData.from}`);
|
||||
connection.logdebug(plugin, `To: ${messageData.to}`);
|
||||
connection.logdebug(plugin, `Subject: ${messageData.subject}`);
|
||||
connection.logdebug(plugin, `Body length: ${body.length}`);
|
||||
connection.logdebug(plugin, `Body type: ${typeof body}`);
|
||||
connection.logdebug(plugin, `Body content: ${body.substring(0, 100)}...`); // First 100 chars
|
||||
|
||||
await MessageService.store(messageData);
|
||||
next();
|
||||
@ -42,6 +46,5 @@ exports.register = function () {
|
||||
}
|
||||
};
|
||||
|
||||
// Register hooks - use data_post instead of queue
|
||||
plugin.register_hook('data_post', 'store_message');
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user