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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gmail-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ async function _get_recent_email(credentials, token, options = {}) {
if (part.parts) {
parts = parts.concat(part.parts);
}

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(
Comment on lines +76 to 83
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 🙏

Expand Down