From 343541981f8b23a3816ba25ce0829391f1f143d5 Mon Sep 17 00:00:00 2001 From: Brian Whitney Date: Wed, 19 Dec 2018 11:22:11 -0500 Subject: [PATCH] throws an error when formating is invalid --- src/core/lib/Mime.mjs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/core/lib/Mime.mjs b/src/core/lib/Mime.mjs index 5bdd59ce..0ac77fea 100644 --- a/src/core/lib/Mime.mjs +++ b/src/core/lib/Mime.mjs @@ -231,18 +231,21 @@ class Mime { * @returns {string} */ static _decodeMimeData(input, charEnc, contEnc) { - switch (contEnc) { - case "base64": - input = Utils.convertToByteArray(input, "base64"); - break; - case "quoted-printable": - input = decodeQuotedPrintable(input); + try { + switch (contEnc) { + case "base64": + input = Utils.convertToByteArray(input, "base64"); + break; + case "quoted-printable": + input = decodeQuotedPrintable(input); + } + if (charEnc && MIME_FORMAT.hasOwnProperty(charEnc.toLowerCase())) { + input = Utils.strToByteArray(cptable.utils.decode(MIME_FORMAT[charEnc.toLowerCase()], input)); + } + return input; + } catch (err) { + throw new OperationError("Invalid Mime Format"); } - if (charEnc && MIME_FORMAT.hasOwnProperty(charEnc.toLowerCase())) { - input = Utils.strToByteArray(cptable.utils.decode(MIME_FORMAT[charEnc.toLowerCase()], input)); - - } - return input; } /**