Skip to content

Commit

Permalink
fix(inline): Use 'inline' as the default Content Dispostion value for…
Browse files Browse the repository at this point in the history
… embedded images
  • Loading branch information
andris9 committed Oct 9, 2023
1 parent fdc7c27 commit db32c93
Show file tree
Hide file tree
Showing 5 changed files with 479 additions and 442 deletions.
Empty file added examples/pool-mx.js
Empty file.
2 changes: 1 addition & 1 deletion examples/ses.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

let nodemailer = require('nodemailer');
let nodemailer = require('../lib/nodemailer');

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

Expand Down
13 changes: 10 additions & 3 deletions lib/mail-composer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,13 @@ class MailComposer {
attachment = this._processDataUrl(attachment);
}

let contentType = attachment.contentType || mimeFuncs.detectMimeType(attachment.filename || attachment.path || attachment.href || 'bin');
let isImage = /^image\//i.test(contentType);
let contentDisposition = attachment.contentDisposition || (isMessageNode || (isImage && attachment.cid) ? 'inline' : 'attachment');

data = {
contentType: attachment.contentType || mimeFuncs.detectMimeType(attachment.filename || attachment.path || attachment.href || 'bin'),
contentDisposition: attachment.contentDisposition || (isMessageNode ? 'inline' : 'attachment'),
contentType,
contentDisposition,
contentTransferEncoding: 'contentTransferEncoding' in attachment ? attachment.contentTransferEncoding : 'base64'
};

Expand Down Expand Up @@ -506,7 +510,10 @@ class MailComposer {
}

if (!/^text\//i.test(element.contentType) || element.contentDisposition) {
node.setHeader('Content-Disposition', element.contentDisposition || (element.cid ? 'inline' : 'attachment'));
node.setHeader(
'Content-Disposition',
element.contentDisposition || (element.cid && /^image\//i.test(element.contentType) ? 'inline' : 'attachment')
);
}

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

0 comments on commit db32c93

Please sign in to comment.