diff --git a/__tests__/files/gmail-outlook/empty b/__tests__/files/gmail-outlook/empty deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/__tests__/html-outlook-outlook.test.ts b/__tests__/html-outlook-outlook.test.ts index 0fa3d3a460de421a0894b366391e0481a22345de..e74341fc8bcd56fdcd1a71caca4bc205fc036cbb 100644 --- a/__tests__/html-outlook-outlook.test.ts +++ b/__tests__/html-outlook-outlook.test.ts @@ -12,57 +12,9 @@ describe("Outlook emails HTML normalization", () => { EMAIL_VENDORS.OUTLOOK ); - describe( - "Emails Chrome", - describeFunction("chrome", [ - "20", - "20forward", - "20reply", - "21", - "21forward", - "21reply", - "22", - "23", - "24", - "25", - "26", - "28", - ]) - ); - - describe( - "Emails Edge", - describeFunction("edge", [ - "20", - "20forward", - "20reply", - "21", - "22", - "23", - "24", - "25", - "26", - "28", - ]) - ); - describe( - "Emails Safari", - describeFunction("safari", [ - "04", - "20", - "20forward", - "20reply", - "21", - "21forward", - "21reply", - "22", - "23", - "24", - "25", - "26", - "28", - ]) - ); + describe("Emails Chrome", describeFunction("chrome")); + describe("Emails Edge", describeFunction("edge", ["21"])); + describe("Emails Safari", describeFunction("safari", ["04"])); // describe( // "Emails MacOS", // describeFunction("macos", ["20", "21", "22", "23", "24", "25", "26"]) diff --git a/src/HTMLNormalizer/strategies/outlook.ts b/src/HTMLNormalizer/strategies/outlook.ts index b67248f1f9651bd3c91b66e231badace6f589664..ab31b1af8dbe46fe05a572e2923515ec1d8fe529 100644 --- a/src/HTMLNormalizer/strategies/outlook.ts +++ b/src/HTMLNormalizer/strategies/outlook.ts @@ -28,6 +28,36 @@ export const pruneOutlookElement = (element: HTMLElement): boolean => { return !!element.nodeName.toLowerCase().startsWith("o:"); }; +const qrCodeContainerId = "test-for-us"; +const removeQrCodeNodes = (document: HTMLDocument) => { + const remove = (node: Element) => { + let toRemove = []; + + let child = node.firstChild; + + while (child) { + if (child.nodeType == child.ELEMENT_NODE) { + toRemove = [...toRemove, ...remove(child as Element)]; + + const childElement = child as Element; + const id = childElement.getAttribute("id"); + if (id && id.includes(qrCodeContainerId)) { + toRemove.push(childElement.parentNode); + } + } + + child = child.nextSibling; + } + + return toRemove; + }; + + const elementsToRemove = remove(document.body); + elementsToRemove.forEach((element) => + element.parentNode.removeChild(element) + ); +}; + export const amendOutlookNodes = (document: HTMLDocument): void => { /** * Remove quoted text @@ -78,6 +108,11 @@ export const amendOutlookNodes = (document: HTMLDocument): void => { // child = nextSibling as Node; // } // } + /** + * Remove QR code entries + */ + + removeQrCodeNodes(document); /** * Get rid of attachments panes