Fix null on body
This commit is contained in:
parent
8f4146af51
commit
8b2244bd16
@ -7,12 +7,32 @@ exports.register = function () {
|
|||||||
if (!transaction) return next();
|
if (!transaction) return next();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Get body content more reliably
|
||||||
|
let 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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get headers safely
|
||||||
|
const headers = transaction.header ? transaction.header.headers_decoded : {};
|
||||||
|
const subject = transaction.header ? transaction.header.get('subject') : '';
|
||||||
|
|
||||||
const messageData = {
|
const messageData = {
|
||||||
from: transaction.mail_from.address(),
|
from: transaction.mail_from.address(),
|
||||||
to: transaction.rcpt_to.map((addr) => addr.address()).join(", "),
|
to: transaction.rcpt_to.map((addr) => addr.address()).join(", "),
|
||||||
subject: transaction.header.get("subject"),
|
subject: subject,
|
||||||
body: transaction.body.bodytext,
|
body: body,
|
||||||
headers: transaction.header.headers_decoded,
|
headers: headers,
|
||||||
domain: transaction.rcpt_to[0].host,
|
domain: transaction.rcpt_to[0].host,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -24,5 +44,17 @@ exports.register = function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
plugin.register_hook("queue", "store_message");
|
// 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();
|
||||||
};
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user