Skip to content

Commit

Permalink
remove line breaks in encoded value
Browse files Browse the repository at this point in the history
  • Loading branch information
mathe42 committed Apr 22, 2022
1 parent fb59cef commit de65208
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

0 comments on commit de65208

Please sign in to comment.