Skip to content

Commit 66ff999

Browse files
committed
v2.0.5
1 parent 9759f9f commit 66ff999

File tree

5 files changed

+12626
-23
lines changed

5 files changed

+12626
-23
lines changed

lib/mail-parser.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const punycode = require('punycode');
99
const FlowedDecoder = require('./flowed-decoder');
1010
const StreamHash = require('./stream-hash');
1111
const iconv = require('iconv-lite');
12-
const marked = require('marked');
1312
const htmlToText = require('html-to-text');
1413
const he = require('he');
1514

@@ -502,13 +501,7 @@ class MailParser extends Transform {
502501
if (node.contentType === 'text/plain') {
503502
text.push(node.textContent);
504503
if (!alternative && this.hasHtml) {
505-
html.push(marked(node.textContent, {
506-
breaks: true,
507-
sanitize: true,
508-
gfm: true,
509-
tables: true,
510-
smartypants: true
511-
}));
504+
html.push(textToHtml(node.textContent));
512505
}
513506
} else if (node.contentType === 'text/html') {
514507
html.push(node.textContent);
@@ -533,13 +526,7 @@ class MailParser extends Transform {
533526
}
534527
if (text.length) {
535528
this.text = response.text = text.join('\n');
536-
this.textAsHtml = response.textAsHtml = text.map(part => marked(part, {
537-
breaks: true,
538-
sanitize: true,
539-
gfm: true,
540-
tables: true,
541-
smartypants: true
542-
})).join('<br/>\n');
529+
this.textAsHtml = response.textAsHtml = text.map(part => textToHtml(part)).join('<br/>\n');
543530
}
544531
return response;
545532
}
@@ -616,7 +603,7 @@ class MailParser extends Transform {
616603
this.push(attachment);
617604
this.attachmentList.push(attachment);
618605

619-
} else if(node.disposition === 'inline') {
606+
} else if (node.disposition === 'inline') {
620607
let chunks = [];
621608
let chunklen = 0;
622609
let contentStream = node.decoder;
@@ -791,3 +778,20 @@ class MailParser extends Transform {
791778
}
792779

793780
module.exports = MailParser;
781+
782+
function textToHtml(str) {
783+
784+
let text = '<p>' + he.
785+
// encode special chars
786+
encode(
787+
str, {
788+
useNamedReferences: true
789+
}).
790+
replace(/\r?\n/g, '\n').trim(). // normalize line endings
791+
replace(/[ \t]+$/mg, '').trim(). // trim empty line endings
792+
replace(/\n\n+/g, '</p><p>').trim(). // insert <p> to multiple linebreaks
793+
replace(/\n/g, '<br/>') + // insert <br> to single linebreaks
794+
'</p>';
795+
796+
return text;
797+
}

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mailparser",
3-
"version": "2.0.4",
3+
"version": "2.0.5",
44
"description": "Parse e-mails",
55
"main": "index.js",
66
"scripts": {
@@ -10,12 +10,11 @@
1010
"license": "EUPL-1.1",
1111
"dependencies": {
1212
"addressparser": "1.0.1",
13-
"he": "1.1.1",
13+
"he": "^1.1.1",
1414
"html-to-text": "3.2.0",
15-
"iconv-lite": "0.4.15",
15+
"iconv-lite": "0.4.17",
1616
"libmime": "3.1.0",
17-
"mailsplit": "4.0.2",
18-
"marked": "0.3.6"
17+
"mailsplit": "4.0.2"
1918
},
2019
"devDependencies": {
2120
"eslint-config-nodemailer": "^1.0.0",

0 commit comments

Comments
 (0)