@@ -26,6 +26,7 @@ import {
2626 * @param {Object } [options.parentNode] immediate parent for this node
2727 * @param {Object } [options.filename] filename for an attachment node
2828 * @param {String } [options.baseBoundary] shared part of the unique multipart boundary
29+ * @param {String } [options.isEncoded] is the node's content encoded or not
2930 */
3031export default class MimeNode {
3132 constructor ( contentType , options = { } ) {
@@ -91,6 +92,11 @@ export default class MimeNode {
9192 * If true then BCC header is included in RFC2822 message.
9293 */
9394 this . includeBccInHeader = options . includeBccInHeader || false
95+
96+ /**
97+ * Is this node's content already encoded
98+ */
99+ this . isEncoded = options . isEncoded
94100 }
95101
96102 /**
@@ -400,20 +406,24 @@ export default class MimeNode {
400406 lines . push ( '' )
401407
402408 if ( this . content ) {
403- switch ( transferEncoding ) {
404- case 'quoted-printable' :
405- lines . push ( quotedPrintableEncode ( this . content ) )
406- break
407- case 'base64' :
408- lines . push ( base64Encode ( this . content , typeof this . content === 'object' ? 'binary' : undefined ) )
409- break
410- default :
411- if ( flowed ) {
412- // space stuffing http://tools.ietf.org/html/rfc3676#section-4.2
413- lines . push ( foldLines ( this . content . replace ( / \r ? \n / g, '\r\n' ) . replace ( / ^ ( | F r o m | > ) / igm, ' $1' ) , 76 , true ) )
414- } else {
415- lines . push ( this . content . replace ( / \r ? \n / g, '\r\n' ) )
416- }
409+ if ( this . isEncoded ) {
410+ lines . push ( this . content . replace ( / \r ? \n / g, '\r\n' ) )
411+ } else {
412+ switch ( transferEncoding ) {
413+ case 'quoted-printable' :
414+ lines . push ( quotedPrintableEncode ( this . content ) )
415+ break
416+ case 'base64' :
417+ lines . push ( base64Encode ( this . content , typeof this . content === 'object' ? 'binary' : undefined ) )
418+ break
419+ default :
420+ if ( flowed ) {
421+ // space stuffing http://tools.ietf.org/html/rfc3676#section-4.2
422+ lines . push ( foldLines ( this . content . replace ( / \r ? \n / g, '\r\n' ) . replace ( / ^ ( | F r o m | > ) / igm, ' $1' ) , 76 , true ) )
423+ } else {
424+ lines . push ( this . content . replace ( / \r ? \n / g, '\r\n' ) )
425+ }
426+ }
417427 }
418428 if ( this . multipart ) {
419429 lines . push ( '' )
0 commit comments