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

Add build

parent 1400ff78
No related branches found
No related tags found
No related merge requests found
...@@ -9,39 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge ...@@ -9,39 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
}); });
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const normalizationStrategies_1 = require("./normalizationStrategies"); const mime_normalizer_1 = require("@vereign/mime-normalizer");
const dom_1 = require("@vereign/dom");
const MailParser_1 = require("../MailParser/MailParser"); const MailParser_1 = require("../MailParser/MailParser");
const CryptoService_1 = require("../CryptoService"); const CryptoService_1 = require("../CryptoService");
const StatusesService_1 = require("../StatusesService");
const index_1 = require("./index"); const index_1 = require("./index");
const rka_1 = require("../../utils/rka"); const rka_1 = require("../../utils/rka");
const common_1 = require("../../utils/common"); const common_1 = require("../../utils/common");
const VerificationError_1 = require("../VerificationService/VerificationError"); const VerificationError_1 = require("../VerificationService/VerificationError");
const stringUtils_1 = require("../../utils/stringUtils");
const utils_1 = require("./utils");
const vendorAmendingFunctions = {
[StatusesService_1.EMAIL_VENDORS.GMAIL]: normalizationStrategies_1.amendGmailNodes,
[StatusesService_1.EMAIL_VENDORS.OUTLOOK]: normalizationStrategies_1.amendOutlookNodes,
};
const vendorPruningFunctions = {
[StatusesService_1.EMAIL_VENDORS.GMAIL]: normalizationStrategies_1.pruneGmailElement,
[StatusesService_1.EMAIL_VENDORS.OUTLOOK]: normalizationStrategies_1.pruneOutlookElement,
};
const vendorAttributesCleanupFunctions = {
[StatusesService_1.EMAIL_VENDORS.GMAIL]: normalizationStrategies_1.cleanupGMailElementAttributes,
[StatusesService_1.EMAIL_VENDORS.OUTLOOK]: normalizationStrategies_1.cleanupOutlookElementAttributes,
};
const vendorPrintingFunctions = {
[StatusesService_1.EMAIL_VENDORS.OUTLOOK]: utils_1.printOutlookElement,
};
// Load JSDOM dynamically for Node env only, because built CRA is crashing with it
let JSDOM;
const loadJSDOM = () => __awaiter(void 0, void 0, void 0, function* () {
if (!JSDOM) {
JSDOM = (yield Promise.resolve().then(() => require("jsdom"))).JSDOM;
}
});
typeof window === "undefined" && loadJSDOM();
const prepareMimeForPartsVerification = (mimeString, attachmentsHashes, senderSystem, sourceHtmlRabinFingerprint, sourceHtmlSize, sourcePlainRabinFingerprint, sourcePlainSize) => __awaiter(void 0, void 0, void 0, function* () { const prepareMimeForPartsVerification = (mimeString, attachmentsHashes, senderSystem, sourceHtmlRabinFingerprint, sourceHtmlSize, sourcePlainRabinFingerprint, sourcePlainSize) => __awaiter(void 0, void 0, void 0, function* () {
const { htmlPart, plainPart } = getNormalizedMimeParts(mimeString, senderSystem); const { htmlPart, plainPart } = getNormalizedMimeParts(mimeString, senderSystem);
const originalHtml = findSubstring(htmlPart, sourceHtmlRabinFingerprint, sourceHtmlSize); const originalHtml = findSubstring(htmlPart, sourceHtmlRabinFingerprint, sourceHtmlSize);
...@@ -56,8 +31,8 @@ const prepareMimeForPartsVerification = (mimeString, attachmentsHashes, senderSy ...@@ -56,8 +31,8 @@ const prepareMimeForPartsVerification = (mimeString, attachmentsHashes, senderSy
}); });
const getNormalizedMimeParts = (mimeString, senderSystem) => { const getNormalizedMimeParts = (mimeString, senderSystem) => {
const { htmlPart, plainPart, } = index_1.default.getMimeHtmlAndPlainParts(mimeString); const { htmlPart, plainPart, } = index_1.default.getMimeHtmlAndPlainParts(mimeString);
const normalizedHtmlPart = index_1.default.normalizeVendorHtml(htmlPart, senderSystem); const normalizedHtmlPart = normalizeVendorHtml(htmlPart, senderSystem);
const normalizedPlainPart = index_1.default.normalizePlainPart(plainPart); const normalizedPlainPart = normalizePlainPart(plainPart);
return { return {
htmlPart: normalizedHtmlPart, htmlPart: normalizedHtmlPart,
plainPart: normalizedPlainPart, plainPart: normalizedPlainPart,
...@@ -102,39 +77,12 @@ const normalizeVendorHtml = (htmlString, vendor) => { ...@@ -102,39 +77,12 @@ const normalizeVendorHtml = (htmlString, vendor) => {
document = parser.parseFromString(htmlString, "text/html"); document = parser.parseFromString(htmlString, "text/html");
} }
else { else {
const { window } = new JSDOM(htmlString); const { window } = new dom_1.DOM(htmlString);
document = window.document; document = window.document;
} }
const mimeBody = document.body; return mime_normalizer_1.HTMLNormalizer.normalizeVendorHtml(document, vendor);
const amendNodesFunction = vendorAmendingFunctions[vendor];
if (amendNodesFunction) {
amendNodesFunction(document);
}
/**
* Remove unnecessary nodes
*/
const elementPruningFunction = vendorPruningFunctions[vendor];
if (!elementPruningFunction) {
throw new Error(`Vendor "${vendor}" is not supported. Please, develop a pruning function for it.`);
}
utils_1.pruneHtmlNode(document, elementPruningFunction);
/**
* Cleanup unnecessary attributes of nodes
*/
const elementAttributesCleanupFunction = vendorAttributesCleanupFunctions[vendor];
if (elementAttributesCleanupFunction) {
utils_1.cleanupHtmlNodeAttributes(document, elementAttributesCleanupFunction);
}
/**
* Print nodes
*/
const vendorPrintFunction = vendorPrintingFunctions[vendor];
return utils_1.printHtmlChildren(mimeBody, vendorPrintFunction, 0);
};
const normalizePlainPart = (text) => {
text = stringUtils_1.removeSpacesAndLinebreaks(text);
return stringUtils_1.removeQRCodes(text);
}; };
const normalizePlainPart = mime_normalizer_1.PlainNormalizer.normalizePlain;
exports.default = { exports.default = {
normalizeVendorHtml, normalizeVendorHtml,
getMimeHtmlAndPlainParts, getMimeHtmlAndPlainParts,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment