@postalsys/email-text-tools 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/mime-html.js +31 -2
- package/lib/text-to-html.js +2 -2
- package/package.json +1 -1
package/lib/mime-html.js
CHANGED
|
@@ -7,6 +7,30 @@ const he = require('he');
|
|
|
7
7
|
|
|
8
8
|
const textToHtml = require('./text-to-html');
|
|
9
9
|
|
|
10
|
+
const FORBID_TAGS = [
|
|
11
|
+
'title',
|
|
12
|
+
'link',
|
|
13
|
+
'meta',
|
|
14
|
+
'base',
|
|
15
|
+
'basefont',
|
|
16
|
+
'frame',
|
|
17
|
+
'iframe',
|
|
18
|
+
'frameset',
|
|
19
|
+
'template',
|
|
20
|
+
'script',
|
|
21
|
+
'noframes',
|
|
22
|
+
'noscript',
|
|
23
|
+
'object',
|
|
24
|
+
'embed',
|
|
25
|
+
'dialog',
|
|
26
|
+
'canvas',
|
|
27
|
+
'audio',
|
|
28
|
+
'video',
|
|
29
|
+
'applet'
|
|
30
|
+
];
|
|
31
|
+
// keep the style at first
|
|
32
|
+
const FORBID_TAGS_ALL = ['style'].concat(FORBID_TAGS);
|
|
33
|
+
|
|
10
34
|
// define styles for plaintext emails
|
|
11
35
|
const INLINE_STYLE_BLOCK = `<style>
|
|
12
36
|
|
|
@@ -63,7 +87,7 @@ function mimeHtml(message) {
|
|
|
63
87
|
const DOMPurify = createDOMPurify(window);
|
|
64
88
|
|
|
65
89
|
// first pass, outputs a fixed HTML page
|
|
66
|
-
html = DOMPurify.sanitize(html, { WHOLE_DOCUMENT: true, FORCE_BODY: false, FORBID_TAGS
|
|
90
|
+
html = DOMPurify.sanitize(html, { WHOLE_DOCUMENT: true, FORCE_BODY: false, FORBID_TAGS });
|
|
67
91
|
|
|
68
92
|
try {
|
|
69
93
|
//inline styles
|
|
@@ -74,7 +98,12 @@ function mimeHtml(message) {
|
|
|
74
98
|
}
|
|
75
99
|
|
|
76
100
|
// second pass, outputs a BODY DOM element
|
|
77
|
-
const dom = DOMPurify.sanitize(html, {
|
|
101
|
+
const dom = DOMPurify.sanitize(html, {
|
|
102
|
+
RETURN_DOM: true,
|
|
103
|
+
WHOLE_DOCUMENT: false,
|
|
104
|
+
FORCE_BODY: true,
|
|
105
|
+
FORBID_TAGS: FORBID_TAGS_ALL
|
|
106
|
+
});
|
|
78
107
|
|
|
79
108
|
// mark all links to be opened in a new window
|
|
80
109
|
for (let elm of dom.querySelectorAll('a')) {
|
package/lib/text-to-html.js
CHANGED
|
@@ -134,14 +134,14 @@ function textLinesToHtml(lines) {
|
|
|
134
134
|
}
|
|
135
135
|
} else if (i < lines.length - 1 && lines[i + 1].trim()) {
|
|
136
136
|
let escaped = linkifyAndHtmlEscape(line);
|
|
137
|
-
if (/^[ \t]*[-_]
|
|
137
|
+
if (/^[ \t]*[-_]{2,}[ \t]*$/.test(escaped)) {
|
|
138
138
|
textparts.push(`<hr />`);
|
|
139
139
|
} else {
|
|
140
140
|
textparts.push(`${escaped}<br />`);
|
|
141
141
|
}
|
|
142
142
|
} else {
|
|
143
143
|
let escaped = linkifyAndHtmlEscape(line);
|
|
144
|
-
if (/^[ \t]*[-_]
|
|
144
|
+
if (/^[ \t]*[-_]{2,}[ \t]*$/.test(escaped)) {
|
|
145
145
|
escaped = `<hr />`;
|
|
146
146
|
}
|
|
147
147
|
textparts.push(escaped);
|