From fa49a55d7d8a38e7b75cb369cb3fba4b86592adc Mon Sep 17 00:00:00 2001 From: Rob Swindell <rob@synchro.net> Date: Sun, 24 Jan 2021 21:38:17 -0800 Subject: [PATCH] Support base64-decoding in get_msg_body() The mail server no longer decodes base64-encoded messages itself (i.e. due to support of single-part MIME binary file attachments). So detect a base64-encoded message body and decode it for external mail processors here. --- exec/load/mailproc_util.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/exec/load/mailproc_util.js b/exec/load/mailproc_util.js index 49b4dcab32..3d42e85622 100644 --- a/exec/load/mailproc_util.js +++ b/exec/load/mailproc_util.js @@ -115,17 +115,20 @@ function convert_msg_header(hdr_array) // Parses the body portion of the complete message text into an array function get_msg_body(msgtxt) { - var body = new Array(); + var body = ""; var hdr = true; + var base64 = parse_msg_header(msgtxt)["content-transfer-encoding"] == "base64"; for(i in msgtxt) { if(hdr && msgtxt[i].length==0) { // Header terminator hdr = false; continue; } - if(!hdr) - body.push(msgtxt[i]); + if(!hdr) { + var line = base64 ? base64_decode(msgtxt[i]) : (msgtxt[i] + "\n"); + if(line != null) + body += line; + } } - return(body); + return(body.split('\n')); } - -- GitLab