diff --git a/dist/services/MimeVerificationService/constants.d.ts b/dist/services/MimeVerificationService/constants.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..4a520bb69e428ac729347a6bc91e3fee91e9ec06 --- /dev/null +++ b/dist/services/MimeVerificationService/constants.d.ts @@ -0,0 +1,3 @@ +export declare const ELEMENT_NODE = 1; +export declare const TEXT_NODE = 3; +export declare const DOCUMENT_NODE = 9; diff --git a/dist/services/MimeVerificationService/constants.js b/dist/services/MimeVerificationService/constants.js new file mode 100644 index 0000000000000000000000000000000000000000..e9c1bf0cc929a004edaad04629ecf623d53ba94f --- /dev/null +++ b/dist/services/MimeVerificationService/constants.js @@ -0,0 +1,6 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.DOCUMENT_NODE = exports.TEXT_NODE = exports.ELEMENT_NODE = void 0; +exports.ELEMENT_NODE = 1; +exports.TEXT_NODE = 3; +exports.DOCUMENT_NODE = 9; diff --git a/dist/services/MimeVerificationService/utils.d.ts b/dist/services/MimeVerificationService/utils.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..993e9cc6f11d443593822f81c1eb3c2eed666cfb --- /dev/null +++ b/dist/services/MimeVerificationService/utils.d.ts @@ -0,0 +1,4 @@ +export declare const printHtmlChildren: (node: Node, printFunction: (node: Node) => string, depth: number) => string; +export declare const printHtmlNode: (node: Node, printFunction: (node: Node) => string, depth: number) => string; +export declare const pruneHtmlNode: (node: Node, pruneElement: (element: HTMLElement) => boolean) => boolean; +export declare const printOutlookElement: (node: Node) => string; diff --git a/dist/services/MimeVerificationService/utils.js b/dist/services/MimeVerificationService/utils.js new file mode 100644 index 0000000000000000000000000000000000000000..3410d139686e69d5dab17a43b417567fc1706b29 --- /dev/null +++ b/dist/services/MimeVerificationService/utils.js @@ -0,0 +1,103 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.printOutlookElement = exports.pruneHtmlNode = exports.printHtmlNode = exports.printHtmlChildren = void 0; +const stringUtils_1 = require("../../utils/stringUtils"); +const __1 = require("../.."); +const constants_1 = require("./constants"); +exports.printHtmlChildren = (node, printFunction, depth) => { + let child = node.firstChild; + if (!child) { + return ""; + } + if (child == node.lastChild && child.nodeType == constants_1.TEXT_NODE) { + return exports.printHtmlNode(child, printFunction, depth); + } + else { + let result = ""; + while (child) { + result = result.concat(exports.printHtmlNode(child, printFunction, depth)); + child = child.nextSibling; + } + return result; + } +}; +exports.printHtmlNode = (node, printFunction, depth) => { + let result = ""; + if (printFunction) { + result = printFunction(node); + if (result) { + return result; + } + } + switch (node.nodeType) { + case constants_1.TEXT_NODE: + result += "<TEXT>"; + result += stringUtils_1.removeSpacesAndLinebreaks(node.textContent); + result += "</TEXT>"; + result += "\n"; + break; + case constants_1.DOCUMENT_NODE: + result += exports.printHtmlChildren(node, printFunction, depth); + break; + case constants_1.ELEMENT_NODE: + result += "<" + node.nodeName; + Array.from(node.attributes) + .sort((a, b) => a.name.localeCompare(b.name)) + .forEach((attribute) => { + result += ` ${attribute.name}`; + if (attribute.value) { + result += `="${__1.escapeHtmlString(attribute.value)}"`; + } + }); + if (node.firstChild) { + result += ">"; + result += "\n"; + result += exports.printHtmlChildren(node, printFunction, depth + 1); + result += "</" + node.nodeName + ">"; + } + else { + result += "/>"; + } + result += "\n"; + } + return result; +}; +exports.pruneHtmlNode = (node, pruneElement) => { + let toBeRemoved = false; + switch (node.nodeType) { + case node.COMMENT_NODE: + case node.DOCUMENT_TYPE_NODE: + toBeRemoved = true; + break; + case node.TEXT_NODE: { + const trimmedText = node.textContent.trim(); + if (trimmedText === "") { + toBeRemoved = true; + } + else { + node.textContent = trimmedText; + } + break; + } + case node.ELEMENT_NODE: + toBeRemoved = pruneElement(node); + } + if (toBeRemoved) { + return true; + } + const childrenToRemove = []; + let child = node.firstChild; + while (child) { + exports.pruneHtmlNode(child, pruneElement) && childrenToRemove.push(child); + child = child.nextSibling; + } + childrenToRemove.forEach((child) => node.removeChild(child)); + return false; +}; +exports.printOutlookElement = (node) => { + if (node.nodeType === constants_1.ELEMENT_NODE) { + if (node.classList.contains("WordSection1")) { + return exports.printHtmlChildren(node, null, 0); + } + } +};