diff --git a/__tests__/outlookHtml.test.ts b/__tests__/outlookHtml.test.ts index 6ff3540a557eaadd45c5da55917dae3ef4ab7ae5..5ce7f0adfb852f09de65d2b4e503ae1340d38e3a 100644 --- a/__tests__/outlookHtml.test.ts +++ b/__tests__/outlookHtml.test.ts @@ -78,6 +78,8 @@ describe("Outlook emails HTML normalization", () => { test("Emails Chrome", async () => { const normalizedCases = await getNormalizedTestCases("chrome"); normalizedCases.forEach(([sent, received]) => { + expect(received.length).toBeGreaterThan(0); + expect(sent.length).toBeGreaterThan(0); expect(received).toContain(sent); }); }); diff --git a/src/HTMLNormalizer/strategies/common.ts b/src/HTMLNormalizer/strategies/common.ts index b1601a25c9128e7d319bd88a39df66740b8f36ff..d35e7cb6936d581db1a01adea6592fdaf3063035 100644 --- a/src/HTMLNormalizer/strategies/common.ts +++ b/src/HTMLNormalizer/strategies/common.ts @@ -31,10 +31,20 @@ export const pruneElement = (element: HTMLElement): boolean => { return true; } + if ( + element.nodeName.toLowerCase() === "div" && + element.childNodes.length === 0 + ) { + return true; + } + return !!ELEMENT_TYPES_TO_REMOVE[element.nodeName.toLowerCase()]; }; -export const cloneAnchorFromPane = (a: HTMLAnchorElement, pane: HTMLElement): void => { +export const cloneAnchorFromPane = ( + a: HTMLAnchorElement, + pane: HTMLElement +): void => { try { const url = new URL(a.href); // If this is external url diff --git a/src/HTMLNormalizer/strategies/outlook.ts b/src/HTMLNormalizer/strategies/outlook.ts index 85f35f89a0239da3d8715b13c49f653672292e4f..84d66308a5df4d67f07cfcd39030ed98a2af1fed 100644 --- a/src/HTMLNormalizer/strategies/outlook.ts +++ b/src/HTMLNormalizer/strategies/outlook.ts @@ -1,7 +1,11 @@ // TODO: Move this logic to amendOutlookNodes -import {printHtmlChildren} from "../HTMLNormalizer"; -import {ELEMENT_NODE} from "../../constants"; -import {ATTRIBUTES_TO_KEEP, cloneAnchorFromPane, pruneElement} from "./common"; +import { printHtmlChildren } from "../HTMLNormalizer"; +import { ELEMENT_NODE } from "../../constants"; +import { + ATTRIBUTES_TO_KEEP, + cloneAnchorFromPane, + pruneElement, +} from "./common"; export const printOutlookElement = (node: Node): string => { if (node.nodeType === ELEMENT_NODE) { @@ -25,6 +29,21 @@ export const pruneOutlookElement = (element: HTMLElement): boolean => { }; export const amendOutlookNodes = (document: HTMLDocument): void => { + /** + * Remove quoted text + */ + const appendOnSendNode = document.querySelector( + "[id*='appendonsend']" + ) as Node; + if (appendOnSendNode) { + let child = appendOnSendNode; + while (child) { + const nextSibling = child.nextSibling; + child.parentNode.removeChild(child); + child = nextSibling as Node; + } + } + /** * Get rid of attachments panes */ @@ -45,9 +64,9 @@ export const amendOutlookNodes = (document: HTMLDocument): void => { } attachmentsPanesContainerEnd && - attachmentsPanesContainerEnd.parentNode.removeChild( - attachmentsPanesContainerEnd - ); + attachmentsPanesContainerEnd.parentNode.removeChild( + attachmentsPanesContainerEnd + ); /** * Unwind spans, because sometimes Outlook wraps everything into span after sending @@ -55,9 +74,7 @@ export const amendOutlookNodes = (document: HTMLDocument): void => { const spans = document.getElementsByTagName("span"); - /** - * Sort spans by depth to start unwinding the deepest ones, which does not contain nested spans - */ + //Sort spans by depth to start unwinding the deepest ones, which does not contain nested spans const spansDepths: { depth?: Array<Node> } = {}; Array.from(spans).forEach((span: Node) => { let descendant = span;