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