Moved quotedprintable to own library, completed a little work on IMF parsing

This commit is contained in:
bwhitn 2018-11-20 22:12:38 -05:00
parent 7ae0b08b4d
commit ed17ed2919
3 changed files with 45 additions and 24 deletions

View file

@ -9,6 +9,7 @@
*/
import Operation from "../Operation";
import {decodeQuotedPrintable} from "../lib/QuotedPrintable"
/**
* From Quoted Printable operation
@ -43,25 +44,7 @@ class FromQuotedPrintable extends Operation {
* @returns {byteArray}
*/
run(input, args) {
const str = input.replace(/=(?:\r?\n|$)/g, "");
const encodedBytesCount = (str.match(/=[\da-fA-F]{2}/g) || []).length,
bufferLength = str.length - encodedBytesCount * 2,
buffer = new Array(bufferLength);
let chr, hex,
bufferPos = 0;
for (let i = 0, len = str.length; i < len; i++) {
chr = str.charAt(i);
if (chr === "=" && (hex = str.substr(i + 1, 2)) && /[\da-fA-F]{2}/.test(hex)) {
buffer[bufferPos++] = parseInt(hex, 16);
i += 2;
continue;
}
buffer[bufferPos++] = chr.charCodeAt(0);
}
return buffer;
return decodeQuotedPrintable(input);
}
}