Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content is undefined if the email contains an attachment #58

Open
GTP95 opened this issue Aug 24, 2022 · 1 comment
Open

Content is undefined if the email contains an attachment #58

GTP95 opened this issue Aug 24, 2022 · 1 comment

Comments

@GTP95
Copy link

GTP95 commented Aug 24, 2022

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:

  1. How should I extract the email's body when the email has one or more attachments?
  2. How do I extract the attachments?

Thank you for your help,

GTP

@GTP95
Copy link
Author

GTP95 commented Aug 25, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant