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

Properly handle Buffer type of haraka_obj.body_text_encoded value #25

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
12 changes: 10 additions & 2 deletions email_body_utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -713,4 +721,4 @@ const EmailBodyUtility = function() {
convertPlainTextToHtml // (text)
};
}();
module.exports = EmailBodyUtility;
module.exports = EmailBodyUtility;