@@ -9,7 +9,6 @@ const punycode = require('punycode');
9
9
const FlowedDecoder = require ( './flowed-decoder' ) ;
10
10
const StreamHash = require ( './stream-hash' ) ;
11
11
const iconv = require ( 'iconv-lite' ) ;
12
- const marked = require ( 'marked' ) ;
13
12
const htmlToText = require ( 'html-to-text' ) ;
14
13
const he = require ( 'he' ) ;
15
14
@@ -502,13 +501,7 @@ class MailParser extends Transform {
502
501
if ( node . contentType === 'text/plain' ) {
503
502
text . push ( node . textContent ) ;
504
503
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 ) ) ;
512
505
}
513
506
} else if ( node . contentType === 'text/html' ) {
514
507
html . push ( node . textContent ) ;
@@ -533,13 +526,7 @@ class MailParser extends Transform {
533
526
}
534
527
if ( text . length ) {
535
528
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' ) ;
543
530
}
544
531
return response ;
545
532
}
@@ -616,7 +603,7 @@ class MailParser extends Transform {
616
603
this . push ( attachment ) ;
617
604
this . attachmentList . push ( attachment ) ;
618
605
619
- } else if ( node . disposition === 'inline' ) {
606
+ } else if ( node . disposition === 'inline' ) {
620
607
let chunks = [ ] ;
621
608
let chunklen = 0 ;
622
609
let contentStream = node . decoder ;
@@ -791,3 +778,20 @@ class MailParser extends Transform {
791
778
}
792
779
793
780
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
+ }
0 commit comments