From d77fa0e57d55e3fc9a42d75e9a81d4f5aa3818c2 Mon Sep 17 00:00:00 2001 From: Stanley Nguyen Date: Wed, 16 Nov 2022 10:42:59 +0800 Subject: [PATCH] fix(get-recent-email): handle attachment body part --- gmail-tester.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gmail-tester.js b/gmail-tester.js index 2f7fba5..157e6f1 100644 --- a/gmail-tester.js +++ b/gmail-tester.js @@ -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(