11"use strict" ;
22Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
3+ exports . GBKUTF8 = exports . buildEml = exports . readEml = exports . parseEml = exports . completeBoundary = exports . decode = exports . encode = exports . convert = exports . Base64 = exports . mimeDecode = exports . unquotePrintable = exports . unquoteString = exports . getCharset = exports . getBoundary = exports . createBoundary = exports . toEmailAddress = exports . getEmailAddress = void 0 ;
34/**
45 * @author superchow
5667 */
78var js_base64_1 = require ( "js-base64" ) ;
8- exports . Base64 = js_base64_1 . Base64 ;
9+ Object . defineProperty ( exports , " Base64" , { enumerable : true , get : function ( ) { return js_base64_1 . Base64 ; } } ) ;
910var charset_1 = require ( "./charset" ) ;
10- exports . convert = charset_1 . convert ;
11- exports . decode = charset_1 . decode ;
12- exports . encode = charset_1 . encode ;
11+ Object . defineProperty ( exports , " convert" , { enumerable : true , get : function ( ) { return charset_1 . convert ; } } ) ;
12+ Object . defineProperty ( exports , " decode" , { enumerable : true , get : function ( ) { return charset_1 . decode ; } } ) ;
13+ Object . defineProperty ( exports , " encode" , { enumerable : true , get : function ( ) { return charset_1 . encode ; } } ) ;
1314var utils_1 = require ( "./utils" ) ;
14- exports . GBKUTF8 = utils_1 . GB2312UTF8 ;
15- exports . mimeDecode = utils_1 . mimeDecode ;
15+ Object . defineProperty ( exports , " GBKUTF8" , { enumerable : true , get : function ( ) { return utils_1 . GB2312UTF8 ; } } ) ;
16+ Object . defineProperty ( exports , " mimeDecode" , { enumerable : true , get : function ( ) { return utils_1 . mimeDecode ; } } ) ;
1617/**
1718 * log for test
1819 */
@@ -274,7 +275,6 @@ exports.parseEml = parse;
274275 * @returns {ParsedEmlJson }
275276 */
276277function parseRecursive ( lines , start , parent , options ) {
277- var _a , _b , _c ;
278278 var boundary = null ;
279279 var lastHeaderName = '' ;
280280 var findBoundary = '' ;
@@ -373,15 +373,15 @@ function parseRecursive(lines, start, parent, options) {
373373 }
374374 if ( insideBoundary ) {
375375 //Search for boundary end
376- if ( ( ( _a = boundary ) === null || _a === void 0 ? void 0 : _a . boundary ) && lines [ i - 1 ] == '' && line . indexOf ( '--' + findBoundary + '--' ) == 0 ) {
376+ if ( ( boundary === null || boundary === void 0 ? void 0 : boundary . boundary ) && lines [ i - 1 ] == '' && line . indexOf ( '--' + findBoundary + '--' ) == 0 ) {
377377 insideBoundary = false ;
378378 complete ( boundary ) ;
379379 continue ;
380380 }
381- if ( ( ( _b = boundary ) === null || _b === void 0 ? void 0 : _b . boundary ) && line . indexOf ( '--' + findBoundary + '--' ) == 0 ) {
381+ if ( ( boundary === null || boundary === void 0 ? void 0 : boundary . boundary ) && line . indexOf ( '--' + findBoundary + '--' ) == 0 ) {
382382 continue ;
383383 }
384- ( _c = boundary ) === null || _c === void 0 ? void 0 : _c . lines . push ( line ) ;
384+ boundary === null || boundary === void 0 ? void 0 : boundary . lines . push ( line ) ;
385385 }
386386 }
387387 else {
@@ -714,7 +714,10 @@ function read(eml, options, callback) {
714714 //Message in HTML format
715715 result . html = content . replace ( / \r \n | ( & q u o t ; ) / g, '' ) . replace ( / \" / g, "\"" ) ;
716716 try {
717- if ( js_base64_1 . Base64 . btoa ( js_base64_1 . Base64 . atob ( result . html ) ) == result . html ) {
717+ if ( encoding === 'base64' ) {
718+ result . html = js_base64_1 . Base64 . decode ( result . html ) ;
719+ }
720+ else if ( js_base64_1 . Base64 . btoa ( js_base64_1 . Base64 . atob ( result . html ) ) == result . html ) {
718721 result . html = js_base64_1 . Base64 . atob ( result . html ) ;
719722 }
720723 }
@@ -731,6 +734,9 @@ function read(eml, options, callback) {
731734 if ( typeof content !== 'string' ) {
732735 content = charset_1 . decode ( content , charset ) ;
733736 }
737+ if ( encoding === 'base64' ) {
738+ content = js_base64_1 . Base64 . decode ( content ) ;
739+ }
734740 //Plain text message
735741 result . text = content ;
736742 result . textheaders = {
0 commit comments