Fix body not parsing
This commit is contained in:
parent
e409fe9bfc
commit
e8785a5bbc
@ -7,21 +7,12 @@ exports.register = function () {
|
||||
if (!transaction) return next();
|
||||
|
||||
try {
|
||||
// Get body content more reliably
|
||||
// Get the full message body as a string
|
||||
let body = '';
|
||||
console.log(transaction.body);
|
||||
|
||||
// Check if we have a message body
|
||||
if (transaction.body) {
|
||||
if (transaction.body.bodytext) {
|
||||
body = transaction.body.bodytext;
|
||||
} else if (transaction.body.children) {
|
||||
// Handle multipart messages
|
||||
body = transaction.body.children.map(child => {
|
||||
if (child.bodytext) return child.bodytext;
|
||||
return '';
|
||||
}).join('\n');
|
||||
}
|
||||
if (transaction.message_stream) {
|
||||
// Convert message stream to string
|
||||
body = transaction.message_stream.toString();
|
||||
}
|
||||
|
||||
// Get headers safely
|
||||
@ -36,6 +27,13 @@ exports.register = function () {
|
||||
headers: headers,
|
||||
};
|
||||
|
||||
// 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}`);
|
||||
|
||||
await MessageService.store(messageData);
|
||||
next();
|
||||
} catch (error) {
|
||||
@ -44,17 +42,6 @@ exports.register = function () {
|
||||
}
|
||||
};
|
||||
|
||||
// Add data hook to ensure body is parsed
|
||||
plugin.register_hook('data_post', 'parse_body');
|
||||
plugin.register_hook('queue', 'store_message');
|
||||
};
|
||||
|
||||
// Add body parser
|
||||
exports.parse_body = function (next, connection) {
|
||||
const transaction = connection.transaction;
|
||||
if (!transaction) return next();
|
||||
|
||||
// Force body parsing
|
||||
transaction.parse_body = true;
|
||||
next();
|
||||
// Register hooks - use data_post instead of queue
|
||||
plugin.register_hook('data_post', 'store_message');
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user