@@ -196,6 +196,8 @@ function messageToHtml(messages, opts) {
196
196
date = formatDate ( message ) ,
197
197
from = formatEmails_ ( message . getFrom ( ) ) ,
198
198
to = formatEmails_ ( message . getTo ( ) ) ,
199
+ cc = formatEmails_ ( message . getCc ( ) ) ,
200
+ bcc = formatEmails_ ( message . getBcc ( ) ) ,
199
201
body = message . getBody ( ) ;
200
202
201
203
if ( opts . includeHeader ) {
@@ -208,9 +210,16 @@ function messageToHtml(messages, opts) {
208
210
'<dt>From:</dt>' + avatar + ' <dd class="strong">' + from + '</dd>\n' +
209
211
'<dt>Subject:</dt> <dd>' + subject + '</dd>\n' +
210
212
'<dt>Date:</dt> <dd>' + date + '</dd>\n' +
211
- '<dt>To:</dt> <dd>' + to + '</dd>\n' +
212
- '</dl>\n' ;
213
+ '<dt>To:</dt> <dd>' + to + '</dd>\n' ;
213
214
}
215
+ // Appending cc and bcc if they exist
216
+ if ( isRealValue ( cc ) ) {
217
+ html += '<dt>cc:</dt> <dd>' + cc + '</dd>\n' ;
218
+ }
219
+ if ( isRealValue ( bcc ) ) {
220
+ html += '<dt>bcc:</dt> <dd>' + bcc + '</dd>\n' ;
221
+ }
222
+ html += '</dl>\n' ;
214
223
if ( opts . embedRemoteImages ) {
215
224
body = embedHtmlImages_ ( body ) ;
216
225
}
@@ -284,25 +293,55 @@ function emailGetAvatar(email) {
284
293
*/
285
294
function embedHtmlImages_ ( html ) {
286
295
// process all img tags
287
- html = html . replace ( / ( < i m g [ ^ > ] + s r c = ) ( [ " ' ] ) ( (?: (? ! \2) [ ^ \\ ] | \\ .) * ) \2/ gi, function ( m , tag , q , src ) {
288
- // Logger.log('Processing image src: ' + src);
289
- return tag + q + ( renderDataUri_ ( src ) || src ) + q ;
290
- } ) ;
296
+ html = processImageTags ( html ) ;
291
297
// process all style attributes
292
- html = html . replace ( / ( < [ ^ > ] + s t y l e = ) ( [ " ' ] ) ( (?: (? ! \2) [ ^ \\ ] | \\ .) * ) \2/ gi, function ( m , tag , q , style ) {
293
- style = style . replace ( / u r l \( ( \\ ? [ " ' ] ? ) ( [ ^ \) ] * ) \1\) / gi, function ( m , q , url ) {
294
- return 'url(' + q + ( renderDataUri_ ( url ) || url ) + q + ')' ;
295
- } ) ;
296
- return tag + q + style + q ;
297
- } ) ;
298
+ html = processStyleAttributes ( html ) ;
298
299
// process all style tags
299
- html = html . replace ( / ( < s t y l e [ ^ > ] * > ) ( .* ?) (?: < \/ s t y l e > ) / gi, function ( m , tag , style , end ) {
300
+ html = processStyleTags ( html ) ;
301
+ return html ;
302
+ }
303
+
304
+ /**
305
+ * Download and embed all img tags
306
+ *
307
+ * @param {string } html
308
+ * @return {string } Html with embedded images
309
+ */
310
+ function processImageTags ( html ) {
311
+ return html . replace ( / ( < i m g [ ^ > ] + s r c = ) ( [ " ' ] ) ( (?: (? ! \2) [ ^ \\ ] | \\ .) * ) \2/ gi, function ( m , tag , q , src ) {
312
+ // Logger.log('Processing image src: ' + src);
313
+ return tag + q + ( renderDataUri_ ( src ) || src ) + q ;
314
+ } ) ;
315
+ }
316
+
317
+ /**
318
+ * Download and embed all HTML Style Attributes
319
+ *
320
+ * @param {string } html
321
+ * @return {string } Html with embedded style attributes
322
+ */
323
+ function processStyleAttributes ( html ) {
324
+ return html . replace ( / ( < [ ^ > ] + s t y l e = ) ( [ " ' ] ) ( (?: (? ! \2) [ ^ \\ ] | \\ .) * ) \2/ gi, function ( m , tag , q , style ) {
325
+ style = style . replace ( / u r l \( ( \\ ? [ " ' ] ? ) ( [ ^ \) ] * ) \1\) / gi, function ( m , q , url ) {
326
+ return 'url(' + q + ( renderDataUri_ ( url ) || url ) + q + ')' ;
327
+ } ) ;
328
+ return tag + q + style + q ;
329
+ } ) ;
330
+ }
331
+
332
+ /**
333
+ * Download and embed all HTML Style Tags
334
+ *
335
+ * @param {string } html
336
+ * @return {string } Html with embedded style tags
337
+ */
338
+ function processStyleTags ( html ) {
339
+ return html . replace ( / ( < s t y l e [ ^ > ] * > ) ( .* ?) (?: < \/ s t y l e > ) / gi, function ( m , tag , style , end ) {
300
340
style = style . replace ( / u r l \( ( [ " ' ] ? ) ( [ ^ \) ] * ) \1\) / gi, function ( m , q , url ) {
301
341
return 'url(' + q + ( renderDataUri_ ( url ) || url ) + q + ')' ;
302
342
} ) ;
303
343
return tag + style + end ;
304
344
} ) ;
305
- return html ;
306
345
}
307
346
308
347
/**
@@ -344,9 +383,19 @@ function embedInlineImages_(html, raw) {
344
383
} ) . filter ( function ( i ) { return i } ) ;
345
384
346
385
// process all img tags which reference "attachments"
347
- return html . replace ( / ( < i m g [ ^ > ] + s r c = ) ( [ " ' ] ) ( \? v i e w = a t t (?: (? ! \2) [ ^ \\ ] | \\ .) * ) \2/ gi, function ( m , tag , q , src ) {
348
- return tag + q + ( renderDataUri_ ( images . shift ( ) ) || src ) + q ;
349
- } ) ;
386
+ return processImgAttachments ( html ) ;
387
+ }
388
+
389
+ /**
390
+ * Download and embed all HTML Inline Image Attachments
391
+ *
392
+ * @param {string } html
393
+ * @return {string } Html with inline image attachments
394
+ */
395
+ function processImgAttachments ( html ) {
396
+ return html . replace ( / ( < i m g [ ^ > ] + s r c = ) ( [ " ' ] ) ( \? v i e w = a t t (?: (? ! \2) [ ^ \\ ] | \\ .) * ) \2/ gi, function ( m , tag , q , src ) {
397
+ return tag + q + ( renderDataUri_ ( images . shift ( ) ) || src ) + q ;
398
+ } ) ;
350
399
}
351
400
352
401
/**
@@ -455,6 +504,16 @@ function localTimezone_() {
455
504
return timezone . length ? timezone [ 1 ] : 'GMT' ;
456
505
}
457
506
507
+ /**
508
+ * Check if value is not null or undefined
509
+ *
510
+ * @param {Object } obj
511
+ * @return {boolean } true if object is not null or undefined
512
+ */
513
+ function isRealValue ( obj ) {
514
+ return obj && obj !== 'null' && obj !== 'undefined' ;
515
+ }
516
+
458
517
/**
459
518
* Create an MD5 hash of a string and return the reult as hexadecimal.
460
519
*
0 commit comments