smtp-connection
Advanced tools
Comparing version 1.3.3 to 1.3.4
{ | ||
"name": "smtp-connection", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"description": "Connect to SMTP servers", | ||
@@ -34,3 +34,6 @@ "main": "src/smtp-connection.js", | ||
"xoauth2": "^1.1.0" | ||
}, | ||
"dependencies": { | ||
"isemail": "^2.1.0" | ||
} | ||
} |
@@ -11,2 +11,3 @@ 'use strict'; | ||
var DataStream = require('./data-stream'); | ||
var isemail = require('isemail'); | ||
@@ -135,3 +136,3 @@ module.exports = SMTPConnection; | ||
*/ | ||
SMTPConnection.prototype.connect = function(connectCallback) { | ||
SMTPConnection.prototype.connect = function (connectCallback) { | ||
if (typeof connectCallback === 'function') { | ||
@@ -155,3 +156,3 @@ this.once('connect', connectCallback); | ||
if (this.options.tls) { | ||
Object.keys(this.options.tls).forEach((function(key) { | ||
Object.keys(this.options.tls).forEach((function (key) { | ||
opts[key] = this.options.tls[key]; | ||
@@ -165,3 +166,3 @@ }).bind(this)); | ||
this._connectionTimeout = setTimeout((function() { | ||
this._connectionTimeout = setTimeout((function () { | ||
this._onError('Connection timeout', 'ETIMEDOUT'); | ||
@@ -176,3 +177,3 @@ }).bind(this), this.options.connectionTimeout || 60 * 1000); | ||
*/ | ||
SMTPConnection.prototype.quit = function() { | ||
SMTPConnection.prototype.quit = function () { | ||
this._sendCommand('QUIT'); | ||
@@ -185,3 +186,3 @@ this._currentAction = this.close; | ||
*/ | ||
SMTPConnection.prototype.close = function() { | ||
SMTPConnection.prototype.close = function () { | ||
clearTimeout(this._connectionTimeout); | ||
@@ -209,3 +210,5 @@ clearTimeout(this._greetingTimeout); | ||
this._socket[closeMethod](); | ||
} catch (E) {} | ||
} catch (E) { | ||
// just ignore | ||
} | ||
} | ||
@@ -219,3 +222,3 @@ | ||
*/ | ||
SMTPConnection.prototype.login = function(authData, callback) { | ||
SMTPConnection.prototype.login = function (authData, callback) { | ||
this._auth = authData || {}; | ||
@@ -238,3 +241,3 @@ | ||
case 'LOGIN': | ||
this._currentAction = function(str) { | ||
this._currentAction = function (str) { | ||
this._actionAUTH_LOGIN_USER(str, callback); | ||
@@ -245,3 +248,3 @@ }.bind(this); | ||
case 'PLAIN': | ||
this._currentAction = function(str) { | ||
this._currentAction = function (str) { | ||
this._actionAUTHComplete(str, callback); | ||
@@ -256,3 +259,3 @@ }.bind(this); | ||
case 'CRAM-MD5': | ||
this._currentAction = function(str) { | ||
this._currentAction = function (str) { | ||
this._actionAUTH_CRAM_MD5(str, callback); | ||
@@ -274,3 +277,3 @@ }.bind(this); | ||
*/ | ||
SMTPConnection.prototype.send = function(envelope, message, callback) { | ||
SMTPConnection.prototype.send = function (envelope, message, callback) { | ||
if (!message) { | ||
@@ -280,7 +283,7 @@ return callback(this._formatError('Empty message', 'EMESSAGE')); | ||
this._setEnvelope(envelope, function(err, info) { | ||
this._setEnvelope(envelope, function (err, info) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
var stream = this._createSendStream(function(err, str) { | ||
var stream = this._createSendStream(function (err, str) { | ||
if (err) { | ||
@@ -308,3 +311,3 @@ return callback(err); | ||
*/ | ||
SMTPConnection.prototype._onConnect = function() { | ||
SMTPConnection.prototype._onConnect = function () { | ||
clearTimeout(this._connectionTimeout); | ||
@@ -327,3 +330,3 @@ | ||
this._greetingTimeout = setTimeout((function() { | ||
this._greetingTimeout = setTimeout((function () { | ||
// if still waiting for greeting, give up | ||
@@ -344,3 +347,3 @@ if (this._socket && !this._destroyed && this._currentAction === this._actionGreeting) { | ||
*/ | ||
SMTPConnection.prototype._onData = function(chunk) { | ||
SMTPConnection.prototype._onData = function (chunk) { | ||
if (this._destroyed || !chunk || !chunk.length) { | ||
@@ -377,3 +380,3 @@ return; | ||
*/ | ||
SMTPConnection.prototype._onError = function(err, type, data) { | ||
SMTPConnection.prototype._onError = function (err, type, data) { | ||
clearTimeout(this._connectionTimeout); | ||
@@ -393,3 +396,3 @@ clearTimeout(this._greetingTimeout); | ||
SMTPConnection.prototype._formatError = function(message, type, response) { | ||
SMTPConnection.prototype._formatError = function (message, type, response) { | ||
var err; | ||
@@ -425,3 +428,3 @@ | ||
*/ | ||
SMTPConnection.prototype._onClose = function() { | ||
SMTPConnection.prototype._onClose = function () { | ||
if ([this._actionGreeting, this.close].indexOf(this._currentAction) < 0 && !this._destroyed) { | ||
@@ -439,3 +442,3 @@ return this._onError(new Error('Connection closed unexpectedly')); | ||
*/ | ||
SMTPConnection.prototype._onEnd = function() { | ||
SMTPConnection.prototype._onEnd = function () { | ||
this._destroy(); | ||
@@ -449,3 +452,3 @@ }; | ||
*/ | ||
SMTPConnection.prototype._onTimeout = function() { | ||
SMTPConnection.prototype._onTimeout = function () { | ||
return this._onError(new Error('Timeout'), 'ETIMEOUT'); | ||
@@ -457,3 +460,3 @@ }; | ||
*/ | ||
SMTPConnection.prototype._destroy = function() { | ||
SMTPConnection.prototype._destroy = function () { | ||
if (this._destroyed) { | ||
@@ -472,3 +475,3 @@ return; | ||
*/ | ||
SMTPConnection.prototype._upgradeConnection = function(callback) { | ||
SMTPConnection.prototype._upgradeConnection = function (callback) { | ||
this._socket.removeAllListeners(); | ||
@@ -481,7 +484,7 @@ | ||
Object.keys(this.options.tls || {}).forEach((function(key) { | ||
Object.keys(this.options.tls || {}).forEach((function (key) { | ||
opts[key] = this.options.tls[key]; | ||
}).bind(this)); | ||
this._socket = tls.connect(opts, function() { | ||
this._socket = tls.connect(opts, function () { | ||
this.secure = true; | ||
@@ -506,3 +509,3 @@ this._socket.on('data', this._onData.bind(this)); | ||
*/ | ||
SMTPConnection.prototype._processResponse = function() { | ||
SMTPConnection.prototype._processResponse = function () { | ||
if (!this._responseQueue.length) { | ||
@@ -546,3 +549,3 @@ return false; | ||
*/ | ||
SMTPConnection.prototype._sendCommand = function(str) { | ||
SMTPConnection.prototype._sendCommand = function (str) { | ||
if (this._destroyed) { | ||
@@ -576,8 +579,8 @@ // Connection already closed, can't send any more data | ||
*/ | ||
SMTPConnection.prototype._setEnvelope = function(envelope, callback) { | ||
SMTPConnection.prototype._setEnvelope = function (envelope, callback) { | ||
this._envelope = envelope || {}; | ||
this._envelope.from = this._envelope.from && this._envelope.from.address || this._envelope.from || ''; | ||
this._envelope.from = (this._envelope.from && this._envelope.from.address || this._envelope.from || '').toString().trim(); | ||
this._envelope.to = [].concat(this._envelope.to || []).map(function(to) { | ||
return to && to.address || to; | ||
this._envelope.to = [].concat(this._envelope.to || []).map(function (to) { | ||
return (to && to.address || to || '').toString().trim(); | ||
}); | ||
@@ -589,2 +592,12 @@ | ||
if (this._envelope.from && !isemail.validate(this._envelope.from)) { | ||
return callback(this._formatError('Invalid sender ' + JSON.stringify(this._envelope.from), 'EENVELOPE')); | ||
} | ||
for (var i = 0, len = this._envelope.to.length; i < len; i++) { | ||
if (!this._envelope.to[i] || !isemail.validate(this._envelope.to[i])) { | ||
return callback(this._formatError('Invalid recipient ' + JSON.stringify(this._envelope.to[i]), 'EENVELOPE')); | ||
} | ||
} | ||
// clone the recipients array for latter manipulation | ||
@@ -595,3 +608,3 @@ this._envelope.rcptQueue = JSON.parse(JSON.stringify(this._envelope.to || [])); | ||
this._currentAction = function(str) { | ||
this._currentAction = function (str) { | ||
this._actionMAIL(str, callback); | ||
@@ -602,6 +615,6 @@ }.bind(this); | ||
SMTPConnection.prototype._createSendStream = function(callback) { | ||
SMTPConnection.prototype._createSendStream = function (callback) { | ||
var dataStream = new DataStream(); | ||
this._currentAction = function(str) { | ||
this._currentAction = function (str) { | ||
this._actionStream(str, callback); | ||
@@ -615,3 +628,3 @@ }.bind(this); | ||
if (this.options.debug) { | ||
dataStream.on('data', function(chunk) { | ||
dataStream.on('data', function (chunk) { | ||
this.emit('log', { | ||
@@ -636,3 +649,3 @@ type: 'stream', | ||
*/ | ||
SMTPConnection.prototype._actionGreeting = function(str) { | ||
SMTPConnection.prototype._actionGreeting = function (str) { | ||
clearTimeout(this._greetingTimeout); | ||
@@ -660,3 +673,3 @@ | ||
*/ | ||
SMTPConnection.prototype._actionLHLO = function(str) { | ||
SMTPConnection.prototype._actionLHLO = function (str) { | ||
if (str.charAt(0) !== '2') { | ||
@@ -678,3 +691,3 @@ this._onError(new Error('Invalid response for LHLO:\n' + str), 'EPROTOCOL', str); | ||
*/ | ||
SMTPConnection.prototype._actionEHLO = function(str) { | ||
SMTPConnection.prototype._actionEHLO = function (str) { | ||
if (str.substr(0, 3) === '421') { | ||
@@ -733,3 +746,3 @@ this._onError(new Error('Server terminates connection:\n' + str), 'ECONNECTION', str); | ||
*/ | ||
SMTPConnection.prototype._actionHELO = function(str) { | ||
SMTPConnection.prototype._actionHELO = function (str) { | ||
if (str.charAt(0) !== '2') { | ||
@@ -750,3 +763,3 @@ this._onError(new Error('Invalid response for EHLO/HELO:\n' + str), 'EPROTOCOL', str); | ||
*/ | ||
SMTPConnection.prototype._actionSTARTTLS = function(str) { | ||
SMTPConnection.prototype._actionSTARTTLS = function (str) { | ||
if (str.charAt(0) !== '2') { | ||
@@ -757,3 +770,3 @@ this._onError(new Error('Error upgrading connection with STARTTLS', 'ETLS', str)); | ||
this._upgradeConnection((function(err, secured) { | ||
this._upgradeConnection((function (err, secured) { | ||
if (err) { | ||
@@ -788,3 +801,3 @@ this._onError(new Error('Error initiating TLS - ' + (err.message || err)), 'ETLS'); | ||
*/ | ||
SMTPConnection.prototype._actionAUTH_LOGIN_USER = function(str, callback) { | ||
SMTPConnection.prototype._actionAUTH_LOGIN_USER = function (str, callback) { | ||
if (str !== '334 VXNlcm5hbWU6') { | ||
@@ -795,3 +808,3 @@ callback(this._formatError('Invalid login sequence while waiting for "334 VXNlcm5hbWU6"', 'EAUTH', str)); | ||
this._currentAction = function(str) { | ||
this._currentAction = function (str) { | ||
this._actionAUTH_LOGIN_PASS(str, callback); | ||
@@ -812,3 +825,3 @@ }.bind(this); | ||
*/ | ||
SMTPConnection.prototype._actionAUTH_CRAM_MD5 = function(str, callback) { | ||
SMTPConnection.prototype._actionAUTH_CRAM_MD5 = function (str, callback) { | ||
var challengeMatch = str.match(/^334\s+(.+)$/); | ||
@@ -832,3 +845,3 @@ var challengeString = ''; | ||
this._currentAction = function(str) { | ||
this._currentAction = function (str) { | ||
this._actionAUTH_CRAM_MD5_PASS(str, callback); | ||
@@ -848,3 +861,3 @@ }.bind(this); | ||
*/ | ||
SMTPConnection.prototype._actionAUTH_CRAM_MD5_PASS = function(str, callback) { | ||
SMTPConnection.prototype._actionAUTH_CRAM_MD5_PASS = function (str, callback) { | ||
if (!str.match(/^235\s+/)) { | ||
@@ -865,3 +878,3 @@ return callback(this._formatError('Invalid login sequence while waiting for "235"', 'EAUTH', str)); | ||
*/ | ||
SMTPConnection.prototype._actionAUTH_LOGIN_PASS = function(str, callback) { | ||
SMTPConnection.prototype._actionAUTH_LOGIN_PASS = function (str, callback) { | ||
if (str !== '334 UGFzc3dvcmQ6') { | ||
@@ -871,3 +884,3 @@ return callback(this._formatError('Invalid login sequence while waiting for "334 UGFzc3dvcmQ6"', 'EAUTH', str)); | ||
this._currentAction = function(str) { | ||
this._currentAction = function (str) { | ||
this._actionAUTHComplete(str, callback); | ||
@@ -886,3 +899,3 @@ }.bind(this); | ||
*/ | ||
SMTPConnection.prototype._actionAUTHComplete = function(str, isRetry, callback) { | ||
SMTPConnection.prototype._actionAUTHComplete = function (str, isRetry, callback) { | ||
if (!callback && typeof isRetry === 'function') { | ||
@@ -894,3 +907,3 @@ callback = isRetry; | ||
if (str.substr(0, 3) === '334') { | ||
this._currentAction = function(str) { | ||
this._currentAction = function (str) { | ||
if (isRetry || !this._auth.xoauth2 || typeof this._auth.xoauth2 !== 'object') { | ||
@@ -919,3 +932,3 @@ this._actionAUTHComplete(str, true, callback); | ||
*/ | ||
SMTPConnection.prototype._actionMAIL = function(str, callback) { | ||
SMTPConnection.prototype._actionMAIL = function (str, callback) { | ||
if (Number(str.charAt(0)) !== 2) { | ||
@@ -929,3 +942,3 @@ return callback(this._formatError('Mail command failed', 'EENVELOPE', str)); | ||
this._envelope.curRecipient = this._envelope.rcptQueue.shift(); | ||
this._currentAction = function(str) { | ||
this._currentAction = function (str) { | ||
this._actionRCPT(str, callback); | ||
@@ -942,3 +955,3 @@ }.bind(this); | ||
*/ | ||
SMTPConnection.prototype._actionRCPT = function(str, callback) { | ||
SMTPConnection.prototype._actionRCPT = function (str, callback) { | ||
if (Number(str.charAt(0)) !== 2) { | ||
@@ -953,3 +966,3 @@ // this is a soft error | ||
if (this._envelope.rejected.length < this._envelope.to.length) { | ||
this._currentAction = function(str) { | ||
this._currentAction = function (str) { | ||
this._actionDATA(str, callback); | ||
@@ -963,3 +976,3 @@ }.bind(this); | ||
this._envelope.curRecipient = this._envelope.rcptQueue.shift(); | ||
this._currentAction = function(str) { | ||
this._currentAction = function (str) { | ||
this._actionRCPT(str, callback); | ||
@@ -976,3 +989,3 @@ }.bind(this); | ||
*/ | ||
SMTPConnection.prototype._actionDATA = function(str, callback) { | ||
SMTPConnection.prototype._actionDATA = function (str, callback) { | ||
// response should be 354 but according to this issue https://github.com/eleith/emailjs/issues/24 | ||
@@ -995,3 +1008,3 @@ // some servers might use 250 instead, so lets check for 2 or 3 as the first digit | ||
*/ | ||
SMTPConnection.prototype._actionStream = function(str, callback) { | ||
SMTPConnection.prototype._actionStream = function (str, callback) { | ||
if (Number(str.charAt(0)) !== 2) { | ||
@@ -1002,8 +1015,8 @@ // Message failed | ||
// Message sent succesfully | ||
callback(null, str); | ||
return callback(null, str); | ||
} | ||
}; | ||
SMTPConnection.prototype._handleXOauth2Token = function(isRetry, callback) { | ||
this._currentAction = function(str) { | ||
SMTPConnection.prototype._handleXOauth2Token = function (isRetry, callback) { | ||
this._currentAction = function (str) { | ||
this._actionAUTHComplete(str, isRetry, callback); | ||
@@ -1013,3 +1026,3 @@ }.bind(this); | ||
if (this._auth.xoauth2 && typeof this._auth.xoauth2 === 'object') { | ||
this._auth.xoauth2[isRetry ? 'generateToken' : 'getToken'](function(err, token) { | ||
this._auth.xoauth2[isRetry ? 'generateToken' : 'getToken'](function (err, token) { | ||
if (err) { | ||
@@ -1032,3 +1045,3 @@ return callback(this._formatError(err, 'EAUTH')); | ||
*/ | ||
SMTPConnection.prototype._buildXOAuth2Token = function(user, token) { | ||
SMTPConnection.prototype._buildXOAuth2Token = function (user, token) { | ||
var authData = [ | ||
@@ -1043,3 +1056,3 @@ 'user=' + (user || ''), | ||
SMTPConnection.prototype._getHostname = function() { | ||
SMTPConnection.prototype._getHostname = function () { | ||
// defaul hostname is machine hostname or [IP] | ||
@@ -1046,0 +1059,0 @@ var defaultHostname = os.hostname() || ''; |
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
43289
977
1
+ Addedisemail@^2.1.0
+ Addedisemail@2.2.1(transitive)