Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed issue for web and smtp format #21

Merged
merged 1 commit into from
Jan 17, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to find a better way to do this check because of the way underscore handles isEmpty on undefined

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