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

fix(get-recent-email): handle attachment body part #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stanleynguyen
Copy link

Sometimes, the attachments could be of type text/plain or text/html and mistaken for a email body part while being an attachment (Please see attached screenshot).

Screenshot 2022-11-16 at 10 43 59 AM

I'm proposing that we should apply a blanket check to skip processing the body part if it doesn't have a body

Comment on lines +76 to 83
if (!part.body.data) {
// body part could be an attachment of type text/plain or text/html
// and the parsing code below will break, hence skipping here
continue;
}

if (part.mimeType === "text/plain") {
email_body.text = Buffer.from(part.body.data, "base64").toString(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts on this? Isn't this a more readable format?

Suggested change
if (!part.body.data) {
// body part could be an attachment of type text/plain or text/html
// and the parsing code below will break, hence skipping here
continue;
}
if (part.mimeType === "text/plain") {
email_body.text = Buffer.from(part.body.data, "base64").toString(
if (part.body.data) {
if (part.mimeType === "text/plain") {
email_body.text = Buffer.from(part.body.data, "base64").toString(
(...)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer returning early for error (in this case - missing body data) but please make the final call as u're the code owner 🙏

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

Successfully merging this pull request may close these issues.

None yet

2 participants