Skip to content

Commit

Permalink
Force charset for Content-Type headers even if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed May 28, 2020
1 parent 5702a71 commit b039ca5
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 251 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ module.exports = {
singleQuote: true,
endOfLine: 'lf',
trailingComma: 'none',
arrowParens: 'avoid',
arrowParens: 'avoid'
};
22 changes: 6 additions & 16 deletions lib/mail-composer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,7 @@ class MailComposer {
if (attachment.filename) {
data.filename = attachment.filename;
} else if (!isMessageNode && attachment.filename !== false) {
data.filename =
(attachment.path || attachment.href || '')
.split('/')
.pop()
.split('?')
.shift() || 'attachment-' + (i + 1);
data.filename = (attachment.path || attachment.href || '').split('/').pop().split('?').shift() || 'attachment-' + (i + 1);
if (data.filename.indexOf('.') < 0) {
data.filename += '.' + mimeFuncs.detectExtension(data.contentType);
}
Expand Down Expand Up @@ -207,7 +202,7 @@ class MailComposer {
content: this.mail.text
};
}
text.contentType = 'text/plain' + (!text.encoding && mimeFuncs.isPlainText(text.content) ? '' : '; charset=utf-8');
text.contentType = 'text/plain; charset=utf-8';
}

if (this.mail.watchHtml) {
Expand All @@ -221,7 +216,7 @@ class MailComposer {
content: this.mail.watchHtml
};
}
watchHtml.contentType = 'text/watch-html' + (!watchHtml.encoding && mimeFuncs.isPlainText(watchHtml.content) ? '' : '; charset=utf-8');
watchHtml.contentType = 'text/watch-html; charset=utf-8';
}

if (this.mail.amp) {
Expand All @@ -232,7 +227,7 @@ class MailComposer {
content: this.mail.amp
};
}
amp.contentType = 'text/x-amp-html' + (!amp.encoding && mimeFuncs.isPlainText(amp.content) ? '' : '; charset=utf-8');
amp.contentType = 'text/x-amp-html; charset=utf-8';
}

// only include the calendar alternative if there are no attachments
Expand Down Expand Up @@ -261,12 +256,7 @@ class MailComposer {
}

eventObject.filename = false;
eventObject.contentType =
'text/calendar; charset="utf-8"; method=' +
(eventObject.method || 'PUBLISH')
.toString()
.trim()
.toUpperCase();
eventObject.contentType = 'text/calendar; charset=utf-8; method=' + (eventObject.method || 'PUBLISH').toString().trim().toUpperCase();
if (!eventObject.headers) {
eventObject.headers = {};
}
Expand All @@ -280,7 +270,7 @@ class MailComposer {
content: this.mail.html
};
}
html.contentType = 'text/html' + (!html.encoding && mimeFuncs.isPlainText(html.content) ? '' : '; charset=utf-8');
html.contentType = 'text/html; charset=utf-8';
}

[]
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
"bunyan": "1.8.12",
"chai": "4.2.0",
"eslint-config-nodemailer": "1.2.0",
"eslint-config-prettier": "6.10.0",
"eslint-config-prettier": "6.11.0",
"grunt": "1.1.0",
"grunt-cli": "1.3.2",
"grunt-eslint": "22.0.0",
"grunt-eslint": "23.0.0",
"grunt-mocha-test": "0.13.3",
"libbase64": "1.2.1",
"libmime": "4.2.1",
"libqp": "1.1.0",
"mocha": "7.1.1",
"mocha": "7.2.0",
"nodemailer-ntlm-auth": "1.0.1",
"proxy": "1.0.1",
"proxy-test-server": "1.0.0",
"sinon": "9.0.1",
"sinon": "9.0.2",
"smtp-server": "3.6.0"
},
"engines": {
Expand Down

0 comments on commit b039ca5

Please sign in to comment.