Skip to content
Snippets Groups Projects
Commit 3b125026 authored by Igor Markin's avatar Igor Markin
Browse files

Add build

parent 37b6a1d6
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ const constants_2 = require("../constants");
const utils_1 = require("../utils");
const gmail_1 = require("./strategies/gmail");
const index_1 = require("../index");
const common_1 = require("./strategies/common");
const nodesAmendingFunctions = {
[constants_2.EMAIL_VENDORS.GMAIL]: gmail_1.amendGmailNodes,
[constants_2.EMAIL_VENDORS.OUTLOOK]: outlook_1.amendOutlookNodes,
......@@ -24,6 +25,7 @@ const vendorPrintingFunctions = {
};
const normalizeVendorHtml = (document, vendor) => {
const mimeBody = document.body;
common_1.amendNodes(document);
const amendNodesFunction = nodesAmendingFunctions[vendor];
if (amendNodesFunction) {
amendNodesFunction(document);
......
......@@ -13,6 +13,7 @@ export declare const ATTRIBUTES_TO_KEEP: {
href: boolean;
value: boolean;
};
export declare const amendNodes: (document: HTMLDocument) => void;
/**
* Decides whether node should be removed
* @param element
......
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cloneAnchorFromPane = exports.pruneElement = exports.ATTRIBUTES_TO_KEEP = exports.ELEMENT_TYPES_TO_REMOVE = void 0;
exports.cloneAnchorFromPane = exports.pruneElement = exports.amendNodes = exports.ATTRIBUTES_TO_KEEP = exports.ELEMENT_TYPES_TO_REMOVE = void 0;
const DUMMY_QR_CODE_ID = "dummyQrCode";
exports.ELEMENT_TYPES_TO_REMOVE = {
br: true,
......@@ -17,6 +17,20 @@ exports.ATTRIBUTES_TO_KEEP = {
href: true,
value: true,
};
const amendNodes = (document) => {
/**
* Unwind Outlook safelink wrappers
*/
const anchors = document.getElementsByTagName("a");
for (const anchor of anchors) {
const url = new URL(anchor.getAttribute("href"));
if (url.host.includes("safelinks.protection.outlook.com")) {
const originalUrl = new URL(url.searchParams.get("url"));
anchor.setAttribute("href", originalUrl.href);
}
}
};
exports.amendNodes = amendNodes;
/**
* Removes dummy QR code from HTML
* @param element
......
......@@ -2,14 +2,38 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.cleanupGMailElementAttributes = exports.amendGmailNodes = exports.pruneGmailElement = void 0;
const common_1 = require("./common");
const constants_1 = require("../../constants");
const pruneGmailElement = (element) => {
return common_1.pruneElement(element);
};
exports.pruneGmailElement = pruneGmailElement;
const qrCodeContainerIds = { vereignWrapperLink: 1 };
const removeQrCodeNodes = (document) => {
const remove = (node) => {
let toRemove = [];
let child = node.firstChild;
while (child) {
if (child.nodeType == constants_1.ELEMENT_NODE) {
toRemove = [...toRemove, ...remove(child)];
const childElement = child;
const id = childElement.getAttribute("id");
if (id &&
Object.keys(qrCodeContainerIds).find((possibleId) => id.includes(possibleId))) {
toRemove.push(childElement);
}
}
child = child.nextSibling;
}
return toRemove;
};
const elementsToRemove = remove(document.body);
elementsToRemove.forEach((element) => element.parentNode.removeChild(element));
};
const amendGmailNodes = (document) => {
// unwindTags(document, "span");
removeQrCodeNodes(document);
/**
* Look for attachments panes and remove everything but liks
* Look for attachments panes and remove everything but links
*/
const attachmentsPanes = Array.from(document.getElementsByClassName("gmail_chip"));
attachmentsPanes.forEach((pane) => {
......
......@@ -25,7 +25,9 @@ const pruneOutlookElement = (element) => {
return !!element.nodeName.toLowerCase().startsWith("o:");
};
exports.pruneOutlookElement = pruneOutlookElement;
const qrCodeContainerId = "test-for-us";
const qrCodeContainerIds = {
"test-for-us": 1,
};
const removeQrCodeNodes = (document) => {
const remove = (node) => {
let toRemove = [];
......@@ -35,7 +37,8 @@ const removeQrCodeNodes = (document) => {
toRemove = [...toRemove, ...remove(child)];
const childElement = child;
const id = childElement.getAttribute("id");
if (id && id.includes(qrCodeContainerId)) {
if (id &&
Object.keys(qrCodeContainerIds).find((possibleId) => id.includes(possibleId))) {
toRemove.push(childElement.parentNode);
}
}
......@@ -104,7 +107,9 @@ const amendOutlookNodes = (document) => {
const attachmentsPanesContainerEnd = document.getElementById("OwaReferenceAttachmentsEnd");
if (attachmentsPanesContainer) {
const as = attachmentsPanesContainer.getElementsByTagName("a");
Array.from(as).forEach((a) => {
Array.from(as)
.sort((a, b) => a.getAttribute("href").localeCompare(b.getAttribute("href")))
.forEach((a) => {
common_1.cloneAnchorFromPane(a, attachmentsPanesContainer);
});
attachmentsPanesContainer.parentNode.removeChild(attachmentsPanesContainer);
......
......@@ -5,13 +5,25 @@ const utils_1 = require("../utils");
const normalizePlainPart = (text) => {
text = removeListBullets(text);
text = utils_1.removeSpacesAndLinebreaks(text);
text = patchOutlookSafelinksWrappers(text);
return removeQRCodes(text);
};
exports.normalizePlainPart = normalizePlainPart;
const patchOutlookSafelinksWrappers = (text) => {
const links = text.match(/<https:.+?(safelinks\.protection\.outlook\.com).+?>/g);
if (links) {
links.forEach((link) => {
const url = new URL(link.slice(1, link.length - 1));
const originalUrl = url.searchParams.get("url");
text = text.replace(link, `<${originalUrl}>`);
});
}
return text;
};
const removeQRCodes = (s) => {
return s
.replace(/\[qrcode.png]\s*<https:\/\/[\w./?=\-&]+>/g, "")
.replace(/<https:\/\/[\w./?=\-&]+>\s*\[qrcode.png]/g, "");
.replace(/\[(image:)*qrcode.png]\s*<https:\/\/[\w./?=\-&]+>/g, "")
.replace(/<https:\/\/[\w./?=\-&]+>\s*\[(image: )*qrcode.png]/g, "");
};
const removeListBullets = (s) => {
return s.replace("\n[o§]\n+/g", "");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment