From 459b1491c9b94d443fdbb591a339c398d31c6ad8 Mon Sep 17 00:00:00 2001 From: Alexander Grimalovsky Date: Wed, 1 Jun 2022 23:11:48 +0300 Subject: [PATCH] Properly Handle Buffer type of haraka_obj.body_text_encoded value for Haraka 2.8.26+ --- email_body_utility.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/email_body_utility.js b/email_body_utility.js index a9b4767..1af01fd 100755 --- a/email_body_utility.js +++ b/email_body_utility.js @@ -355,7 +355,15 @@ const EmailBodyUtility = function() { // grab each of the available values var bodytext = haraka_obj.bodytext; - var haraka_body_text_encoded = _formatQuotedPrintableBody(haraka_obj.body_text_encoded); + + // haraka_obj.body_text_encoded is of type Buffer since 2.8.26 and of type String before this version + var _haraka_body_text_encoded = ''; + if (haraka_obj.body_text_encoded instanceof Buffer) { + _haraka_body_text_encoded = haraka_obj.body_text_encoded.slice(0, haraka_obj.body_text_encoded_pos).toString('binary'); + } else { + _haraka_body_text_encoded = haraka_obj.body_text_encoded; + } + var haraka_body_text_encoded = _formatQuotedPrintableBody(_haraka_body_text_encoded); // set has_valid_encoding has_valid_encoding = !!haraka_obj.body_encoding && !haraka_obj.body_encoding.includes('broken') && !!haraka_obj.bodytext; @@ -713,4 +721,4 @@ const EmailBodyUtility = function() { convertPlainTextToHtml // (text) }; }(); -module.exports = EmailBodyUtility; \ No newline at end of file +module.exports = EmailBodyUtility;