Skip to content

Commit

Permalink
Fix email sending fail when blog title has a comma
Browse files Browse the repository at this point in the history
no issue

- We send emails from Blog Title <[email protected]>, but it should be from "Blog Title" <[email protected]>
- It worked fine without quotes unless you have a comma in your Blog Title in which case different mail systems get confused in different ways
  • Loading branch information
ErisDS committed Jan 9, 2015
1 parent 7501b44 commit 283deb2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion core/server/mail.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ GhostMailer.prototype.from = function () {
if (!config.theme.title) {
config.theme.title = 'Ghost at ' + this.getDomain();
}
from = config.theme.title + ' <' + from + '>';
from = '"' + config.theme.title + '" <' + from + '>';
}

return from;
Expand Down
32 changes: 16 additions & 16 deletions core/test/unit/mail_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,57 +71,57 @@ describe('Mail', function () {
it('should use from address as configured in config.js', function () {
config.set({
mail: {
from: 'Blog Title <[email protected]>'
from: '"Blog Title" <[email protected]>'
}
});
mailer.from().should.equal('Blog Title <[email protected]>');
mailer.from().should.equal('"Blog Title" <[email protected]>');
});

it('should fall back to [blog.title] <ghost@[blog.url]> as from address', function () {
// Standard domain
config.set({url: 'http://default.com', mail: {from: null}, theme: {title: 'Test'}});
mailer.from().should.equal('Test <[email protected]>');
mailer.from().should.equal('"Test" <[email protected]>');

// Trailing slash
config.set({url: 'http://default.com/', mail: {from: null}, theme: {title: 'Test'}});
mailer.from().should.equal('Test <[email protected]>');
mailer.from().should.equal('"Test" <[email protected]>');

// Strip Port
config.set({url: 'http://default.com:2368/', mail: {from: null}, theme: {title: 'Test'}});
mailer.from().should.equal('Test <[email protected]>');
mailer.from().should.equal('"Test" <[email protected]>');
});

it('should use mail.from if both from and fromaddress are present', function () {
// Standard domain
config.set({mail: {from: 'bar <[email protected]>', fromaddress: 'Qux <[email protected]>'}});
mailer.from().should.equal('bar <[email protected]>');
config.set({mail: {from: '"bar" <[email protected]>', fromaddress: '"Qux" <[email protected]>'}});
mailer.from().should.equal('"bar" <[email protected]>');
});

it('should attach blog title if from or fromaddress are only email addresses', function () {
// from and fromaddress are both set
config.set({mail: {from: '[email protected]', fromaddress: '[email protected]'}, theme: {title: 'Test'}});
mailer.from().should.equal('Test <[email protected]>');
mailer.from().should.equal('"Test" <[email protected]>');

// only from set
config.set({mail: {from: '[email protected]', fromaddress: null}, theme: {title: 'Test'}});
mailer.from().should.equal('Test <[email protected]>');
mailer.from().should.equal('"Test" <[email protected]>');

// only fromaddress set
config.set({mail: {from: null, fromaddress: '[email protected]'}, theme: {title: 'Test'}});
mailer.from().should.equal('Test <[email protected]>');
mailer.from().should.equal('"Test" <[email protected]>');
});

it('should ignore theme title if from address is Title <[email protected]> format', function () {
// from and fromaddress are both set
config.set({mail: {from: 'R2D2 <[email protected]>', fromaddress: 'C3PO <[email protected]>'}, theme: {title: 'Test'}});
mailer.from().should.equal('R2D2 <[email protected]>');
config.set({mail: {from: '"R2D2" <[email protected]>', fromaddress: '"C3PO" <[email protected]>'}, theme: {title: 'Test'}});
mailer.from().should.equal('"R2D2" <[email protected]>');

// only from set
config.set({mail: {from: 'R2D2 <[email protected]>', fromaddress: null}, theme: {title: 'Test'}});
mailer.from().should.equal('R2D2 <[email protected]>');
config.set({mail: {from: '"R2D2" <[email protected]>', fromaddress: null}, theme: {title: 'Test'}});
mailer.from().should.equal('"R2D2" <[email protected]>');

// only fromaddress set
config.set({mail: {from: null, fromaddress: 'C3PO <[email protected]>'}, theme: {title: 'Test'}});
mailer.from().should.equal('C3PO <[email protected]>');
config.set({mail: {from: null, fromaddress: '"C3PO" <[email protected]>'}, theme: {title: 'Test'}});
mailer.from().should.equal('"C3PO" <[email protected]>');
});
});

0 comments on commit 283deb2

Please sign in to comment.