Content is undefined if the email contains an attachment
Opened this issue · 1 comments
GTP95 commented
Greetings,
I noticed that when I parse an email that contains an attachment, the content
property is undefined
(while instead, it works correctly if the email has no attachment). My code is like this (it's actually split between two files, but it gives you an idea):
const parsedEmail = parse(email)
console.log("Email's content: ", parsedEmailObject.content);
if (parsedEmailObject.content != null) {
//Extract email's body only if it actually exists
const bodyAsHTML = new TextDecoder().decode(
objectToUInt8array(parsedEmailObject.content)
);
console.log("HTML body: ", bodyAsHTML); // TODO: what if email isn't in HTML format? How do I detect this? Probably it is enough to inspect the 'contentType' parameter
const bodyAsText = extractEmailBodyFromHTML(bodyAsHTML);
console.log("Body: ", bodyAsText);
domEmail.body(bodyAsText);
} else domEmail.body(" ");
If the email doesn't have attachmments, this code correctly extracts the email's body, while if it has attachments, it fails due to parsedEmailObject.content
being undefined. My questions are:
- How should I extract the email's body when the email has one or more attachments?
- How do I extract the attachments?
Thank you for your help,
GTP
GTP95 commented
Update: by looking at the source I saw that there is a finalize()
method that should emit the body, I tried calling it after the parse()
method but the result didn't change.