From 2342806576e9c0053af17fdb73f18687ce820963 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sun, 10 Apr 2016 22:04:22 -0600 Subject: [PATCH] Fallback decoding --- core/ftn_mail_packet.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/ftn_mail_packet.js b/core/ftn_mail_packet.js index 25d2d6be..c602593e 100644 --- a/core/ftn_mail_packet.js +++ b/core/ftn_mail_packet.js @@ -469,7 +469,14 @@ function Packet(options) { // Decode |messageBodyBuffer| using |encoding| defaulted or detected above // // :TODO: Look into \xec thing more - document - const messageLines = iconv.decode(messageBodyBuffer, encoding).replace(/\xec/g, '').split(/\r\n|[\n\v\f\r\x85\u2028\u2029]/g); + let decoded; + try { + decoded = iconv.decode(messageBodyBuffer, encoding); + } catch(e) { + decoded = iconv.decode(messageBodyBuffer, 'ascii'); + } + //const messageLines = iconv.decode(messageBodyBuffer, encoding).replace(/\xec/g, '').split(/\r\n|[\n\v\f\r\x85\u2028\u2029]/g); + const messageLines = decoded.replace(/\xec/g, '').split(/\r\n|[\n\v\f\r\x85\u2028\u2029]/g); let endOfMessage = true; messageLines.forEach(line => {