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

Merge branch '122-gmail-to-outlook' into 'master'

Gmail to Outlook - complex text + embeded image + attachments

See merge request !27
parents 9830b472 1ca9074d
No related branches found
No related tags found
1 merge request!27Gmail to Outlook - complex text + embeded image + attachments
Pipeline #45086 passed
......@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [1.0.3] - 2020-09-06
### Changed
PlainNormalizer now strips `image:` prefix from plain representations of the images [outlokaddin#122](https://code.vereign.com/seal/clients/outlook-add-in/-/issues/122)
## [1.0.2] - 2020-06-07
### Added
......
export interface SealRemovalOptions {
sealUrl: string;
export interface Options {
sealUrl?: string;
normalizeImagePlain?: boolean;
}
export declare const normalizePlainPart: (text: string, sealRemovalOptions?: SealRemovalOptions) => string;
export declare const normalizePlainPart: (text: string, options?: Options) => string;
export declare const cleanupImageText: (plain: string) => string;
export declare const cleanupHiddenCharacters: (s: string) => string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cleanupHiddenCharacters = exports.normalizePlainPart = void 0;
exports.cleanupHiddenCharacters = exports.cleanupImageText = exports.normalizePlainPart = void 0;
// this is a Node module. require is a must to work across different envs
const URL = require("url-parse");
const utils_1 = require("../utils");
const normalizePlainPart = (text, sealRemovalOptions) => {
const defaultOptions = {
normalizeImagePlain: true,
};
const normalizePlainPart = (text, options) => {
options = options
? Object.assign(defaultOptions, Object.assign({}, options))
: defaultOptions;
text = exports.cleanupHiddenCharacters(text);
text = patchOutlookSafelinksWrappers(text);
if (sealRemovalOptions) {
text = removeSeal(text, sealRemovalOptions.sealUrl);
if (options === null || options === void 0 ? void 0 : options.sealUrl) {
text = removeSeal(text, options.sealUrl);
}
if (options === null || options === void 0 ? void 0 : options.normalizeImagePlain) {
text = exports.cleanupImageText(text);
}
text = utils_1.normalizeTextSpacings(text);
return text.trim();
......@@ -39,6 +48,12 @@ const removeSeal = (plain, sealUrl) => {
.replace(new RegExp(sealRegex), "")
.replace(new RegExp(sealRegexReversed), "");
};
const cleanupImageText = (plain) => {
// For cases [image: IMAGE_NAME.EXTENSION]
const sealRegex = `\\[(image:\\s)(.*)\\]`;
return plain.replace(new RegExp(sealRegex), "[$2]");
};
exports.cleanupImageText = cleanupImageText;
const cleanupHiddenCharacters = (s) => {
const removeSymbols = new RegExp(/[\u200B]+/g);
return s.replace(removeSymbols, "");
......
declare const _default: {
normalizePlain: (text: string, sealRemovalOptions?: import("./PlainNormalizer").SealRemovalOptions) => string;
normalizePlain: (text: string, options?: import("./PlainNormalizer").Options) => string;
cleanupImageText: (plain: string) => string;
};
export default _default;
......@@ -3,4 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
const PlainNormalizer_1 = require("./PlainNormalizer");
exports.default = {
normalizePlain: PlainNormalizer_1.normalizePlainPart,
cleanupImageText: PlainNormalizer_1.cleanupImageText,
};
......@@ -2,7 +2,7 @@
"name": "@vereign/mime-normalizer",
"author": "Igor Markin <igor.markin@vereign.com>",
"description": "A library that handles normalization of MIME plain and html parts",
"version": "1.0.2",
"version": "1.0.3",
"license": "MIT",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
......
......@@ -3,21 +3,32 @@ const URL = require("url-parse");
import { normalizeTextSpacings } from "../utils";
export interface SealRemovalOptions {
sealUrl: string;
export interface Options {
sealUrl?: string;
normalizeImagePlain?: boolean;
}
export const normalizePlainPart = (
text: string,
sealRemovalOptions?: SealRemovalOptions
): string => {
const defaultOptions: Options = {
normalizeImagePlain: true,
};
export const normalizePlainPart = (text: string, options?: Options): string => {
options = options
? Object.assign(defaultOptions, { ...options })
: defaultOptions;
text = cleanupHiddenCharacters(text);
text = patchOutlookSafelinksWrappers(text);
if (sealRemovalOptions) {
text = removeSeal(text, sealRemovalOptions.sealUrl);
if (options?.sealUrl) {
text = removeSeal(text, options.sealUrl);
}
if (options?.normalizeImagePlain) {
text = cleanupImageText(text);
}
text = normalizeTextSpacings(text);
return text.trim();
......@@ -56,6 +67,13 @@ const removeSeal = (plain: string, sealUrl: string): string => {
.replace(new RegExp(sealRegexReversed), "");
};
export const cleanupImageText = (plain: string): string => {
// For cases [image: IMAGE_NAME.EXTENSION]
const sealRegex = `\\[(image:\\s)(.*)\\]`;
return plain.replace(new RegExp(sealRegex), "[$2]");
};
export const cleanupHiddenCharacters = (s: string): string => {
const removeSymbols = new RegExp(/[\u200B]+/g);
return s.replace(removeSymbols, "");
......
import { normalizePlainPart } from "./PlainNormalizer";
import { normalizePlainPart, cleanupImageText } from "./PlainNormalizer";
export default {
normalizePlain: normalizePlainPart,
cleanupImageText: cleanupImageText,
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment