Skip to content

Commit

Permalink
馃悰 escape blog title for mail header (#8453)
Browse files Browse the repository at this point in the history
closes #8436

- this is how the from field looks like "blog title <owner@blog.com>"
- so if you set your blog title with double quotes, it throws a syntax error from the smtp library
  • Loading branch information
kirrg001 committed May 12, 2017
1 parent 37e28cb commit 524cc4c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/server/mail/GhostMailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ GhostMailer.prototype.from = function () {

// If we do have a from address, and it's just an email
if (validator.isEmail(from)) {
defaultBlogTitle = settingsCache.get('title') || i18n.t('common.mail.title', {domain: this.getDomain()});
defaultBlogTitle = settingsCache.get('title') ? settingsCache.get('title').replace(/"/g, '\\"') : i18n.t('common.mail.title', {domain: this.getDomain()});
from = '"' + defaultBlogTitle + '" <' + from + '>';
}

Expand Down
7 changes: 7 additions & 0 deletions core/test/unit/mail/GhostMailer_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ describe('Mail: Ghostmailer', function () {
// Strip Port
configUtils.set({url: 'http://default.com:2368/', mail: {from: null}});
mailer.from().should.equal('"Test" <ghost@default.com>');

settingsCache.get.restore();
sandbox.stub(settingsCache, 'get').returns('Test"');

// Escape title
configUtils.set({url: 'http://default.com:2368/', mail: {from: null}});
mailer.from().should.equal('"Test\\"" <ghost@default.com>');
});

it('should use mail.from if both from and fromaddress are present', function () {
Expand Down

0 comments on commit 524cc4c

Please sign in to comment.