Enhance getMailBody function to handle nested message parts and improve content extraction

This commit is contained in:
mic 2025-04-10 22:29:25 +02:00
parent c9d95b4df7
commit 73b801af2c

View file

@ -112,6 +112,9 @@ export async function getMailBody(fullMessage){
let text = ''; let text = '';
let html = ''; let html = '';
// console.log(">>>>>>>>>> fullMessage.contentType.trim().toLowerCase(): " + fullMessage.contentType.trim().toLowerCase());
// console.log(">>>>>>>>>> fullMessage.body: " + fullMessage.body);
if (fullMessage.contentType.trim().toLowerCase() === "text/plain") { if (fullMessage.contentType.trim().toLowerCase() === "text/plain") {
text = fullMessage.body; text = fullMessage.body;
} }
@ -119,12 +122,24 @@ export async function getMailBody(fullMessage){
html = fullMessage.body; html = fullMessage.body;
} }
for (let part of fullMessage.parts) { if((text == undefined || text == null || text == '') && (html == undefined || html == null || html == '')) {
if (part.contentType.trim().toLowerCase() === "text/plain") { for (let part of fullMessage.parts) {
text = part.body; if (part.contentType.trim().toLowerCase() === "text/plain") {
} text = part.body;
if (part.contentType.trim().toLowerCase() === "text/html") { }
html = part.body; if (part.contentType.trim().toLowerCase() === "text/html") {
html = part.body;
}
if((text == undefined || text == null || text == '') && (html == undefined || html == null || html == '')) {
for (let subpart of part.parts) {
if (subpart.contentType.trim().toLowerCase() === "text/plain") {
text = subpart.body;
}
if (subpart.contentType.trim().toLowerCase() === "text/html") {
html = subpart.body;
}
}
}
} }
} }