From de65208c259280bbeafbdb2ba7ab9d32e10ab2b6 Mon Sep 17 00:00:00 2001 From: mathe42 <2pi_r2@gmx.de> Date: Fri, 22 Apr 2022 16:25:31 +0200 Subject: [PATCH] remove line breaks in encoded value --- encoding.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/encoding.ts b/encoding.ts index d2c4851..800eed2 100644 --- a/encoding.ts +++ b/encoding.ts @@ -32,10 +32,17 @@ export function quotedPrintableEncode(data: string, encLB = false) { }).join(""); let ret = ""; - const lines = Math.ceil(encodedData.length / 75) - 1; + const lines = Math.ceil(encodedData.length / 74) - 1; + let offset = 0 for (let i = 0; i < lines; i++) { - const old = encodedData.slice(i * 75, (i + 1) * 75); + let old = encodedData.slice(i * 74 + offset, (i + 1) * 74); + offset = 0 + + if(old[old.length-1] === '=' || old[old.length-2] === '=') { + old += encodedData[(i+1)*74] + offset = 1 + } if (old.endsWith("\r") || old.endsWith("\n")) { ret += old; @@ -45,7 +52,7 @@ export function quotedPrintableEncode(data: string, encLB = false) { } // Add rest with no new line - ret += encodedData.slice(lines * 75); + ret += encodedData.slice(lines * 74); return ret; }