Skip to content

Commit

Permalink
Merge pull request #21 from siyegen/fix-to-address-on-format
Browse files Browse the repository at this point in the history
fixed issue for web and smtp format
  • Loading branch information
partkyle committed Jan 17, 2012
2 parents f9d5bf4 + 09fca0f commit 5265945
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ Email.prototype.toWebFormat = function() {

// there needs to be at least 1 to address.
// If it is missing, just copy over the from.
if (_.isEmpty(data.to)) {
data.to = data.from;
}
// Only do this is we have a value for the to
// address on this.smtpapi
this.checkAddTo(data);

return data;
}
Expand All @@ -156,14 +156,20 @@ Email.prototype.toSmtpFormat = function() {
}

// there needs to be at least 1 to address.
// If it is missing, just copy the sender.
if (_.isEmpty(data.to)) {
data.to = data.sender;
}
// If it is missing, just copy over the from.
// Only do this is we have a value for the to
// address on this.smtpapi
this.checkAddTo(data);

return data;
}

Email.prototype.checkAddTo = function(data) {
if (_.isEmpty(data.to) && this.smtpapi.to && !_.isEmpty(this.smtpapi.to)) {
data.to = data.from;
}
}

Email.prototype.hasFiles = function() {
return _(this.files).size() > 0;
}
Expand Down
6 changes: 6 additions & 0 deletions test/lib/email.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ describe('Email', function () {
expect(smtpFormat.body).to.equal(text_params.text);
});

it('should not have a to address if there is no to or no smtpapi.to set via Smtp Api', function() {
var email = new Email({from: 'test@test.com', subject: 'testing', text: 'testing'});
var smtpFormat = email.toSmtpFormat();
expect(smtpFormat.to).to.be.empty;
});

it('should support file attachments', function() {
var email = new Email();
email.addFile('file1', files[0]);
Expand Down

0 comments on commit 5265945

Please sign in to comment.