smtp-connection
Advanced tools
Comparing version 2.6.0 to 2.7.0
# Changelog | ||
## v2.7.0 2016-07-06 | ||
* Use PIPELINING for multiple RCPT TO if available | ||
## v2.6.0 2016-07-06 | ||
@@ -4,0 +8,0 @@ |
@@ -122,6 +122,7 @@ 'use strict'; | ||
/** | ||
* Function to run if a data chunk comes from the server | ||
* Function queue to run if a data chunk comes from the server | ||
* @private | ||
*/ | ||
this._currentAction = false; | ||
this._responseActions = []; | ||
this._recipientQueue = []; | ||
@@ -232,3 +233,3 @@ /** | ||
this._sendCommand('QUIT'); | ||
this._currentAction = this.close; | ||
this._responseActions.push(this.close); | ||
}; | ||
@@ -242,2 +243,3 @@ | ||
clearTimeout(this._greetingTimeout); | ||
this._responseActions = []; | ||
@@ -296,11 +298,11 @@ // allow to run this function only once | ||
case 'LOGIN': | ||
this._currentAction = function (str) { | ||
this._responseActions.push(function (str) { | ||
this._actionAUTH_LOGIN_USER(str, callback); | ||
}.bind(this); | ||
}.bind(this)); | ||
this._sendCommand('AUTH LOGIN'); | ||
return; | ||
case 'PLAIN': | ||
this._currentAction = function (str) { | ||
this._responseActions.push(function (str) { | ||
this._actionAUTHComplete(str, callback); | ||
}.bind(this); | ||
}.bind(this)); | ||
this._sendCommand('AUTH PLAIN ' + new Buffer( | ||
@@ -313,11 +315,11 @@ //this._auth.user+'\u0000'+ | ||
case 'CRAM-MD5': | ||
this._currentAction = function (str) { | ||
this._responseActions.push(function (str) { | ||
this._actionAUTH_CRAM_MD5(str, callback); | ||
}.bind(this); | ||
}.bind(this)); | ||
this._sendCommand('AUTH CRAM-MD5'); | ||
return; | ||
case 'NTLM': | ||
this._currentAction = function (str) { | ||
this._responseActions.push(function (str) { | ||
this._actionAUTH_NTLM_TYPE1(str, callback); | ||
}.bind(this); | ||
}.bind(this)); | ||
this._sendCommand('AUTH ' + ntlm.createType1Message({ | ||
@@ -417,3 +419,3 @@ domain: this._auth.domain || '', | ||
// if still waiting for greeting, give up | ||
if (this._socket && !this._destroyed && this._currentAction === this._actionGreeting) { | ||
if (this._socket && !this._destroyed && this._responseActions[0] === this._actionGreeting) { | ||
this._onError('Greeting never received', 'ETIMEDOUT', false, 'CONN'); | ||
@@ -423,3 +425,3 @@ } | ||
this._currentAction = this._actionGreeting; | ||
this._responseActions.push(this._actionGreeting); | ||
@@ -525,3 +527,3 @@ // we have a 'data' listener set up so resume socket if it was paused | ||
if ([this._actionGreeting, this.close].indexOf(this._currentAction) < 0 && !this._destroyed) { | ||
if ([this._actionGreeting, this.close].indexOf(this._responseActions[0]) < 0 && !this._destroyed) { | ||
return this._onError(new Error('Connection closed unexpectedly'), 'ECONNECTION', false, 'CONN'); | ||
@@ -632,4 +634,3 @@ } | ||
var action = this._currentAction; | ||
this._currentAction = null; | ||
var action = this._responseActions.shift(); | ||
@@ -726,5 +727,5 @@ if (typeof action === 'function') { | ||
this._currentAction = function (str) { | ||
this._responseActions.push(function (str) { | ||
this._actionMAIL(str, callback); | ||
}.bind(this); | ||
}.bind(this)); | ||
@@ -810,5 +811,5 @@ // If the server supports SMTPUTF8 and the envelope includes an internationalized | ||
this._currentAction = function (str) { | ||
this._responseActions.push(function (str) { | ||
this._actionStream(str, callback); | ||
}.bind(this); | ||
}.bind(this)); | ||
@@ -855,6 +856,6 @@ dataStream.pipe(this._socket, { | ||
if (this.options.lmtp) { | ||
this._currentAction = this._actionLHLO; | ||
this._responseActions.push(this._actionLHLO); | ||
this._sendCommand('LHLO ' + this.name); | ||
} else { | ||
this._currentAction = this._actionEHLO; | ||
this._responseActions.push(this._actionEHLO); | ||
this._sendCommand('EHLO ' + this.name); | ||
@@ -900,3 +901,3 @@ } | ||
// Try HELO instead | ||
this._currentAction = this._actionHELO; | ||
this._responseActions.push(this._actionHELO); | ||
this._sendCommand('HELO ' + this.name); | ||
@@ -909,3 +910,3 @@ return; | ||
this._sendCommand('STARTTLS'); | ||
this._currentAction = this._actionSTARTTLS; | ||
this._responseActions.push(this._actionSTARTTLS); | ||
return; | ||
@@ -929,2 +930,7 @@ } | ||
// Detect if the server supports PIPELINING | ||
if (/[ \-]PIPELINING\b/mi.test(str)) { | ||
this._supportedExtensions.push('PIPELINING'); | ||
} | ||
// Detect if the server supports PLAIN auth | ||
@@ -991,3 +997,3 @@ if (str.match(/AUTH(?:(\s+|=)[^\n]*\s+|\s+|=)PLAIN/i)) { | ||
// restart session | ||
this._currentAction = this._actionEHLO; | ||
this._responseActions.push(this._actionEHLO); | ||
this._sendCommand('EHLO ' + this.name); | ||
@@ -1013,5 +1019,5 @@ } else { | ||
this._currentAction = function (str) { | ||
this._responseActions.push(function (str) { | ||
this._actionAUTH_LOGIN_PASS(str, callback); | ||
}.bind(this); | ||
}.bind(this)); | ||
@@ -1057,5 +1063,5 @@ this._sendCommand(new Buffer(this._auth.user + '', 'utf-8').toString('base64')); | ||
this._currentAction = function (str) { | ||
this._responseActions.push(function (str) { | ||
this._actionAUTH_NTLM_TYPE3(str, callback); | ||
}.bind(this); | ||
}.bind(this)); | ||
@@ -1093,5 +1099,5 @@ this._sendCommand(type3Message); | ||
this._currentAction = function (str) { | ||
this._responseActions.push(function (str) { | ||
this._actionAUTH_CRAM_MD5_PASS(str, callback); | ||
}.bind(this); | ||
}.bind(this)); | ||
@@ -1146,5 +1152,5 @@ | ||
this._currentAction = function (str) { | ||
this._responseActions.push(function (str) { | ||
this._actionAUTHComplete(str, callback); | ||
}.bind(this); | ||
}.bind(this)); | ||
@@ -1167,3 +1173,3 @@ this._sendCommand(new Buffer(this._auth.pass + '', 'utf-8').toString('base64')); | ||
if (str.substr(0, 3) === '334') { | ||
this._currentAction = function (str) { | ||
this._responseActions.push(function (str) { | ||
if (isRetry || !this._auth.xoauth2 || typeof this._auth.xoauth2 !== 'object') { | ||
@@ -1174,3 +1180,3 @@ this._actionAUTHComplete(str, true, callback); | ||
} | ||
}.bind(this); | ||
}.bind(this)); | ||
this._sendCommand(''); | ||
@@ -1196,3 +1202,3 @@ return; | ||
SMTPConnection.prototype._actionMAIL = function (str, callback) { | ||
var message; | ||
var message, curRecipient; | ||
if (Number(str.charAt(0)) !== 2) { | ||
@@ -1210,7 +1216,21 @@ if (this._usingSmtpUtf8 && /^550 /.test(str) && /[\x80-\uFFFF]/.test(this._envelope.from)) { | ||
} else { | ||
this._envelope.curRecipient = this._envelope.rcptQueue.shift(); | ||
this._currentAction = function (str) { | ||
this._actionRCPT(str, callback); | ||
}.bind(this); | ||
this._sendCommand('RCPT TO:<' + this._envelope.curRecipient + '>' + this._getDsnRcptToArgs()); | ||
this._recipientQueue = []; | ||
if (this._supportedExtensions.indexOf('PIPELINING') >= 0) { | ||
while (this._envelope.rcptQueue.length) { | ||
curRecipient = this._envelope.rcptQueue.shift(); | ||
this._recipientQueue.push(curRecipient); | ||
this._responseActions.push(function (str) { | ||
this._actionRCPT(str, callback); | ||
}.bind(this)); | ||
this._sendCommand('RCPT TO:<' + curRecipient + '>' + this._getDsnRcptToArgs()); | ||
} | ||
} else { | ||
curRecipient = this._envelope.rcptQueue.shift(); | ||
this._recipientQueue.push(curRecipient); | ||
this._responseActions.push(function (str) { | ||
this._actionRCPT(str, callback); | ||
}.bind(this)); | ||
this._sendCommand('RCPT TO:<' + curRecipient + '>' + this._getDsnRcptToArgs()); | ||
} | ||
} | ||
@@ -1225,6 +1245,6 @@ }; | ||
SMTPConnection.prototype._actionRCPT = function (str, callback) { | ||
var message, err; | ||
var message, err, curRecipient = this._recipientQueue.shift(); | ||
if (Number(str.charAt(0)) !== 2) { | ||
// this is a soft error | ||
if (this._usingSmtpUtf8 && /^553 /.test(str) && /[\x80-\uFFFF]/.test(this._envelope.curRecipient)) { | ||
if (this._usingSmtpUtf8 && /^553 /.test(str) && /[\x80-\uFFFF]/.test(curRecipient)) { | ||
message = 'Internationalized mailbox name not allowed'; | ||
@@ -1234,16 +1254,16 @@ } else { | ||
} | ||
this._envelope.rejected.push(this._envelope.curRecipient); | ||
this._envelope.rejected.push(curRecipient); | ||
// store error for the failed recipient | ||
err = this._formatError(message, 'EENVELOPE', str, 'RCPT TO'); | ||
err.recipient = this._envelope.curRecipient; | ||
err.recipient = curRecipient; | ||
this._envelope.rejectedErrors.push(err); | ||
} else { | ||
this._envelope.accepted.push(this._envelope.curRecipient); | ||
this._envelope.accepted.push(curRecipient); | ||
} | ||
if (!this._envelope.rcptQueue.length) { | ||
if (!this._envelope.rcptQueue.length && !this._recipientQueue.length) { | ||
if (this._envelope.rejected.length < this._envelope.to.length) { | ||
this._currentAction = function (str) { | ||
this._responseActions.push(function (str) { | ||
this._actionDATA(str, callback); | ||
}.bind(this); | ||
}.bind(this)); | ||
this._sendCommand('DATA'); | ||
@@ -1253,8 +1273,9 @@ } else { | ||
} | ||
} else { | ||
this._envelope.curRecipient = this._envelope.rcptQueue.shift(); | ||
this._currentAction = function (str) { | ||
} else if (this._envelope.rcptQueue.length) { | ||
curRecipient = this._envelope.rcptQueue.shift(); | ||
this._recipientQueue.push(curRecipient); | ||
this._responseActions.push(function (str) { | ||
this._actionRCPT(str, callback); | ||
}.bind(this); | ||
this._sendCommand('RCPT TO:<' + this._envelope.curRecipient + '>' + this._getDsnRcptToArgs()); | ||
}.bind(this)); | ||
this._sendCommand('RCPT TO:<' + curRecipient + '>' + this._getDsnRcptToArgs()); | ||
} | ||
@@ -1303,5 +1324,5 @@ }; | ||
SMTPConnection.prototype._handleXOauth2Token = function (isRetry, callback) { | ||
this._currentAction = function (str) { | ||
this._responseActions.push(function (str) { | ||
this._actionAUTHComplete(str, isRetry, callback); | ||
}.bind(this); | ||
}.bind(this)); | ||
@@ -1308,0 +1329,0 @@ if (this._auth.xoauth2 && typeof this._auth.xoauth2 === 'object') { |
{ | ||
"name": "smtp-connection", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"description": "Connect to SMTP servers", | ||
@@ -10,3 +10,3 @@ "main": "lib/smtp-connection.js", | ||
"scripts": { | ||
"test": "grunt" | ||
"test": "grunt mochaTest" | ||
}, | ||
@@ -35,3 +35,3 @@ "repository": { | ||
"sinon": "^1.17.4", | ||
"smtp-server": "^1.9.1", | ||
"smtp-server": "^1.10.0", | ||
"xoauth2": "^1.1.0" | ||
@@ -38,0 +38,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62368
1322