diff --git a/src/core/lib/Mime.mjs b/src/core/lib/Mime.mjs index 7d96f2c1..549a7f20 100644 --- a/src/core/lib/Mime.mjs +++ b/src/core/lib/Mime.mjs @@ -6,7 +6,6 @@ import OperationError from "../errors/OperationError"; import cptable from "../vendor/js-codepage/cptable.js"; -import {fromBase64} from "../lib/Base64"; import {decodeQuotedPrintable} from "../lib/QuotedPrintable"; import {MIME_FORMAT} from "../lib/ChrEnc"; import Utils from "../Utils"; @@ -58,7 +57,7 @@ class Mime { } name = name.concat(Mime.getFileExt(fileObj.type)); } - retval.push(new File([fileObj.data], name, {type: fileObj.type})); + retval.push(new File([Uint8Array.from(fileObj.data)], name, {type: fileObj.type})); }); return retval; } @@ -91,7 +90,7 @@ class Mime { const newLineLength = this.rn ? 2 : 1; let contType = "text/plain", fileName = null, - charEnc = "us-ascii", + charEnc = null, contDispoObj = null, contTypeObj = null; if (parentObj.header.hasOwnProperty("content-type")) { @@ -109,6 +108,10 @@ class Mime { } if (contTypeObj.hasOwnProperty("charset")) { charEnc = contTypeObj.charset; + } else { + if (contType.startsWith("text/")) { + charEnc = "us-ascii"; + } } if (fileName == null && contTypeObj.hasOwnProperty("name")) { fileName = contTypeObj.name; @@ -196,10 +199,11 @@ class Mime { static _decodeMimeData(input, charEnc, contEnc) { switch (contEnc) { case "base64": - input = fromBase64(input); + input = Utils.convertToByteArray(input, "base64"); + //input = fromBase64(input); break; case "quoted-printable": - input = Utils.byteArrayToUtf8(decodeQuotedPrintable(input)); + input = decodeQuotedPrintable(input); } if (charEnc && MIME_FORMAT.hasOwnProperty(charEnc.toLowerCase())) { input = cptable.utils.decode(MIME_FORMAT[charEnc.toLowerCase()], input); @@ -253,15 +257,16 @@ class Mime { */ _splitMultipart(input, boundary, newLineLength) { const output = []; - const boundaryStr = "--".concat(boundary, this.rn ? "\r\n" : "\n"); - const last = input.indexOf("--".concat(boundary, "--")) - newLineLength; + const newline = this.rn ? "\r\n" : "\n"; + const boundaryStr = newline.concat("--", boundary); + const last = input.indexOf(newline.concat("--", boundary, "--")); for (;;) { let start = input.indexOf(boundaryStr, start); if (start < 0) { break; } start += boundaryStr.length; - const end = input.indexOf(boundaryStr, start) - newLineLength; + const end = input.indexOf(boundaryStr, start); if (end <= start) { break; } diff --git a/src/core/operations/DecodeMimeEncodedWords.mjs b/src/core/operations/DecodeMimeEncodedWords.mjs index 80f0c711..9997d740 100644 --- a/src/core/operations/DecodeMimeEncodedWords.mjs +++ b/src/core/operations/DecodeMimeEncodedWords.mjs @@ -20,7 +20,7 @@ class DecodeMimeEncodedWords extends Operation { this.name = "Decode Mime Encoded Words"; this.module = "Default"; this.description = ["Parser an IMF formatted messages following RFC5322.", - "

", "Parses an IMF formated message. These often have the file extention ".eml"e; and contain the email headers and body. The output will be a file list of the headers and mime parts.", + "

", "Decodes Mime encoded words that are found in IMF messages.", ].join("\n"); this.infoURL = "https://tools.ietf.org/html/rfc2047"; this.inputType = "string"; diff --git a/src/core/operations/ParseIMF.mjs b/src/core/operations/ParseIMF.mjs index 848706f6..72a49cba 100644 --- a/src/core/operations/ParseIMF.mjs +++ b/src/core/operations/ParseIMF.mjs @@ -9,7 +9,7 @@ import Mime from "../lib/Mime"; import Utils from "../Utils"; /** - * + * Operation for parsing IMF messages into file list. */ class ParseIMF extends Operation { @@ -18,11 +18,12 @@ class ParseIMF extends Operation { */ constructor() { super(); + this.name = "Parse Internet Message Format"; this.module = "Default"; this.description = ["Parse an IMF formatted messages following RFC5322.", "

", - "Parses an IMF formated message. These often have the file extention ".eml"e; and contain the email headers and body. The output will be a file list of the root header and decoded mime parts.", + "Parses an IMF formated message like those sent in SMTP. These often have the file extention ".eml"e; and contain the email headers and body. The output will be a file list of the root header and decoded mime parts." ].join("\n"); this.infoURL = "https://tools.ietf.org/html/rfc5322"; this.inputType = "string"; @@ -30,7 +31,7 @@ class ParseIMF extends Operation { this.presentType = "html"; this.args = [ { - "name": "Decode Encoded-Words", + "name": "Decode Mime Encoded Words", "type": "boolean", "value": false } @@ -38,14 +39,11 @@ class ParseIMF extends Operation { } /** - * - * - * - * - * + * @param {string} + * @param {Object[]} + * @returns {File[]} */ run(input, args) { - //let mimeObj = new Mime(input); return new Mime(input).decodeMime(args[0]); }