Skip to content

Commit db32c93

Browse files
committed
fix(inline): Use 'inline' as the default Content Dispostion value for embedded images
1 parent fdc7c27 commit db32c93

File tree

5 files changed

+479
-442
lines changed

5 files changed

+479
-442
lines changed

examples/pool-mx.js

Whitespace-only changes.

examples/ses.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
let nodemailer = require('nodemailer');
3+
let nodemailer = require('../lib/nodemailer');
44

55
/* --- Select AWS SDK version by uncommenting correct version --- */
66

lib/mail-composer/index.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ class MailComposer {
9191
attachment = this._processDataUrl(attachment);
9292
}
9393

94+
let contentType = attachment.contentType || mimeFuncs.detectMimeType(attachment.filename || attachment.path || attachment.href || 'bin');
95+
let isImage = /^image\//i.test(contentType);
96+
let contentDisposition = attachment.contentDisposition || (isMessageNode || (isImage && attachment.cid) ? 'inline' : 'attachment');
97+
9498
data = {
95-
contentType: attachment.contentType || mimeFuncs.detectMimeType(attachment.filename || attachment.path || attachment.href || 'bin'),
96-
contentDisposition: attachment.contentDisposition || (isMessageNode ? 'inline' : 'attachment'),
99+
contentType,
100+
contentDisposition,
97101
contentTransferEncoding: 'contentTransferEncoding' in attachment ? attachment.contentTransferEncoding : 'base64'
98102
};
99103

@@ -506,7 +510,10 @@ class MailComposer {
506510
}
507511

508512
if (!/^text\//i.test(element.contentType) || element.contentDisposition) {
509-
node.setHeader('Content-Disposition', element.contentDisposition || (element.cid ? 'inline' : 'attachment'));
513+
node.setHeader(
514+
'Content-Disposition',
515+
element.contentDisposition || (element.cid && /^image\//i.test(element.contentType) ? 'inline' : 'attachment')
516+
);
510517
}
511518

512519
if (typeof element.content === 'string' && !['utf8', 'usascii', 'ascii'].includes(encoding)) {

0 commit comments

Comments
 (0)