1
0
mirror of https://github.com/eleith/emailjs.git synced 2024-07-05 20:10:37 +00:00

support return-path properly and ensure quit finishes before calling callback

This commit is contained in:
eleith 2014-07-05 23:18:48 -07:00
parent 4ca1742751
commit 19f3686f1d
2 changed files with 14 additions and 4 deletions

View File

@ -108,6 +108,9 @@ Client.prototype =
if(msg.header.bcc)
stack.to = stack.to.concat(address.parse(msg.header.bcc));
if(msg.header['return-path'] && address.parse(msg.header['return-path']).length)
stack.returnPath = address.parse(msg.header['return-path'])[0].address;
self.queue.push(stack);
self._poll();
}
@ -160,8 +163,9 @@ Client.prototype =
_sendmail: function(stack)
{
var self = this;
var from = stack.returnPath || stack.from;
self.sending = true;
self.smtp.mail(self._sendsmtp(stack, self._sendrcpt), '<' + stack.from + '>');
self.smtp.mail(self._sendsmtp(stack, self._sendrcpt), '<' + from + '>');
},
_sendrcpt: function(stack)

View File

@ -105,7 +105,12 @@ SMTP.prototype = {
self.port = port || self.port;
self.ssl = options.ssl || self.ssl;
if (self._state != SMTPState.NOTCONNECTED) self.quit();
if (self._state != SMTPState.NOTCONNECTED) {
self.quit(function() {
self.connect(callback, port, host, options);
});
return;
}
var connected = function(err) {
if (!err) {
@ -136,8 +141,9 @@ SMTP.prototype = {
caller(callback, null, msg.data);
} else {
log("response (data): " + msg.data);
self.quit();
caller(callback, SMTPError("bad response on connection", SMTPError.BADRESPONSE, err, msg.data));
self.quit(function() {
caller(callback, SMTPError("bad response on connection", SMTPError.BADRESPONSE, err, msg.data));
});
}
};