From 4057573a542f943385a9a8c9413dde93273a9ccd Mon Sep 17 00:00:00 2001
From: igor <igor.markin@vereign.com>
Date: Fri, 27 Nov 2020 14:38:02 +0300
Subject: [PATCH] Cover all chrome/edge/safari cases

---
 __tests__/outlook-outlook.test.ts        |  8 ++++--
 src/HTMLNormalizer/strategies/common.ts  |  2 +-
 src/HTMLNormalizer/strategies/outlook.ts | 36 ++++++++++++++++++------
 3 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/__tests__/outlook-outlook.test.ts b/__tests__/outlook-outlook.test.ts
index b74e510..e449e1a 100644
--- a/__tests__/outlook-outlook.test.ts
+++ b/__tests__/outlook-outlook.test.ts
@@ -18,7 +18,7 @@ const getTestCasesDirs = (testCasesPath: string) => {
     return fs.statSync(testCasesPath + "/" + file).isDirectory();
   });
 };
-
+console.debug = () => {}
 const getNormalizedHtml = (
   testCasePath: string
 ): {
@@ -61,7 +61,7 @@ describe("Outlook emails HTML normalization", () => {
       try {
         normalizedHtmls = getNormalizedHtml(testCasePath);
       } catch (e) {
-        console.log("Invalid test case: " + dirName);
+        console.log(`Invalid test case: ${casesName}/${dirName}`);
         return;
       }
 
@@ -75,7 +75,9 @@ describe("Outlook emails HTML normalization", () => {
 
   describe("Emails Chrome", describeTestCases("chrome"));
   describe("Emails Edge", describeTestCases("edge"));
-  //describe("Emails Gmail", describeTestCases("gmail"));
+  describe("Emails Safari", describeTestCases("safari"));
+  // describe("Emails MacOS", describeTestCases("macos"));
+  // describe("Emails Windows", describeTestCases("windows"));
 
   // it("Emails Edge", () => {
   // })
diff --git a/src/HTMLNormalizer/strategies/common.ts b/src/HTMLNormalizer/strategies/common.ts
index d35e7cb..74476ac 100644
--- a/src/HTMLNormalizer/strategies/common.ts
+++ b/src/HTMLNormalizer/strategies/common.ts
@@ -1,6 +1,6 @@
 const DUMMY_QR_CODE_ID = "dummyQrCode";
 
-export const ELEMENT_TYPES_TO_REMOVE = { br: true, hr: true };
+export const ELEMENT_TYPES_TO_REMOVE = { br: true, hr: true, use: true, svg: true };
 
 export const ATTRIBUTES_TO_KEEP = {
   alt: true,
diff --git a/src/HTMLNormalizer/strategies/outlook.ts b/src/HTMLNormalizer/strategies/outlook.ts
index 84d6630..4dea0d7 100644
--- a/src/HTMLNormalizer/strategies/outlook.ts
+++ b/src/HTMLNormalizer/strategies/outlook.ts
@@ -32,11 +32,31 @@ export const amendOutlookNodes = (document: HTMLDocument): void => {
   /**
    * Remove quoted text
    */
-  const appendOnSendNode = document.querySelector(
+
+  // Quoted text in web apps
+  const appendOnSend = document.querySelector(
     "[id*='appendonsend']"
   ) as Node;
-  if (appendOnSendNode) {
-    let child = appendOnSendNode;
+
+  if (appendOnSend) {
+    let child = appendOnSend;
+    while (child) {
+      const nextSibling = child.nextSibling;
+      child.parentNode.removeChild(child);
+      child = nextSibling as Node;
+    }
+  }
+
+  // Quoted text in desktop apps
+  const mailOriginal = document.querySelector("[name*='_MailOriginal']") as Node;
+  if (mailOriginal) {
+    const separatorCandidate = mailOriginal.parentNode as Node;
+
+    // while (!(separatorCandidate.parentNode as Element).classList.contains("WordSection1")) {
+    //   separatorCandidate = separatorCandidate.parentNode;
+    // }
+
+    let child = separatorCandidate;
     while (child) {
       const nextSibling = child.nextSibling;
       child.parentNode.removeChild(child);
@@ -47,20 +67,20 @@ export const amendOutlookNodes = (document: HTMLDocument): void => {
   /**
    * Get rid of attachments panes
    */
-  const attachmentsPanesConatiner = document.getElementById(
+  const attachmentsPanesContainer = document.getElementById(
     "OwaReferenceAttachments"
   );
   const attachmentsPanesContainerEnd = document.getElementById(
     "OwaReferenceAttachmentsEnd"
   );
 
-  if (attachmentsPanesConatiner) {
-    const as = attachmentsPanesConatiner.getElementsByTagName("a");
+  if (attachmentsPanesContainer) {
+    const as = attachmentsPanesContainer.getElementsByTagName("a");
     Array.from(as).forEach((a) => {
-      cloneAnchorFromPane(a, attachmentsPanesConatiner as HTMLElement);
+      cloneAnchorFromPane(a, attachmentsPanesContainer as HTMLElement);
     });
 
-    attachmentsPanesConatiner.parentNode.removeChild(attachmentsPanesConatiner);
+    attachmentsPanesContainer.parentNode.removeChild(attachmentsPanesContainer);
   }
 
   attachmentsPanesContainerEnd &&
-- 
GitLab