Enhance getMailBody function to handle nested message parts and improve content extraction
This commit is contained in:
parent
c9d95b4df7
commit
73b801af2c
1 changed files with 21 additions and 6 deletions
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue