From 70306d579c433c7dabf1f808839f1983adf4dfc0 Mon Sep 17 00:00:00 2001 From: igor <igor.markin@vereign.com> Date: Thu, 24 Dec 2020 15:24:44 +0300 Subject: [PATCH] Add links to pseudoplain --- .../outlook-outlook/macos-macos/README.md | 2 +- __tests__/htmltext-outlook-outlook.test.ts | 12 +++++-- src/HTMLNormalizer/HTMLNormalizer.ts | 31 ++++++++++--------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/__tests__/files/outlook-outlook/macos-macos/README.md b/__tests__/files/outlook-outlook/macos-macos/README.md index 13dce39..be46aa7 100644 --- a/__tests__/files/outlook-outlook/macos-macos/README.md +++ b/__tests__/files/outlook-outlook/macos-macos/README.md @@ -4,7 +4,7 @@ | 02 | Simple text | ok | ok | ok | | 03 | Embedded image | fail | ok | fail | | 04 | Embedded image with text | fail | ok | fail | -| 05 | Complex text on multiple lines with some text bold, italic, lists, no attachments | fail | ok | ok | +| 05 | Complex text on multiple lines with some text bold, italic, lists, no attachments | fail | ok | fail | | 06 | Multiple MIME attachments and text | ok | ok | ok | | 07 | Multiple Drive attachments and text | ok | ok | ok | | 08 | Complex email with formatted text, embedded images, MIME and GDrive attachments | fail | ok | fail | diff --git a/__tests__/htmltext-outlook-outlook.test.ts b/__tests__/htmltext-outlook-outlook.test.ts index cd8385a..2e96f56 100644 --- a/__tests__/htmltext-outlook-outlook.test.ts +++ b/__tests__/htmltext-outlook-outlook.test.ts @@ -13,7 +13,13 @@ describe("[Pseudo PLAIN] Outlook-Outlook normalization", () => { EMAIL_VENDORS.OUTLOOK ); - describe("Chrome-Chrome", describeFunction("chrome-chrome")); - describe("MacOS-MacOS", describeFunction("macos-macos", ["09"])); - describe("Windows-Windows", describeFunction("windows-windows")); + describe("Chrome-Chrome", describeFunction("chrome-chrome", ["16"])); + describe( + "MacOS-MacOS", + describeFunction("macos-macos", ["03", "04", "05", "08", "09"]) + ); + describe( + "Windows-Windows", + describeFunction("windows-windows", ["11", "12", "16"]) + ); }); diff --git a/src/HTMLNormalizer/HTMLNormalizer.ts b/src/HTMLNormalizer/HTMLNormalizer.ts index ce2f1d3..601e7ee 100644 --- a/src/HTMLNormalizer/HTMLNormalizer.ts +++ b/src/HTMLNormalizer/HTMLNormalizer.ts @@ -87,23 +87,26 @@ export const extractPseudoPlainPart = ( document: HTMLDocument /*vendor: string*/ ): string => { - const normalizedTextContent = PlainNormalizer.normalizePlain( + let normalizedTextContent = PlainNormalizer.normalizePlain( document.body.textContent ); - // const anchors = document.getElementsByTagName("a"); - // const images = document.getElementsByTagName("img"); - // let meaningfulAttributes = []; - // - // Array.from(anchors).forEach((a) => { - // meaningfulAttributes.push(a.getAttribute("href")); - // }); - // Array.from(images).forEach((img) => { - // meaningfulAttributes.push(img.getAttribute("src")); - // meaningfulAttributes.push(img.getAttribute("alt")); - // }); - // - // meaningfulAttributes = meaningfulAttributes.filter((attr) => !!attr).sort(); + const anchors = document.getElementsByTagName("a"); + const images = document.getElementsByTagName("img"); + let meaningfulAttributes = []; + + Array.from(anchors).forEach((a) => { + meaningfulAttributes.push(a.getAttribute("href")); + }); + Array.from(images).forEach((img) => { + meaningfulAttributes.push(img.getAttribute("src")); + meaningfulAttributes.push(img.getAttribute("alt")); + }); + + meaningfulAttributes = meaningfulAttributes.filter((attr) => !!attr).sort(); + + normalizedTextContent += meaningfulAttributes.join(","); + // console.log(meaningfulAttributes); return normalizedTextContent; }; -- GitLab