From 4e6190537895a3928d71c10a28d7c4af08a65ca9 Mon Sep 17 00:00:00 2001 From: Brian White Date: Mon, 31 Dec 2012 12:14:51 -0500 Subject: [PATCH] Don't clear connection timer until greeting is received --- lib/imap.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/imap.js b/lib/imap.js index 0329ba9..1a34d39 100644 --- a/lib/imap.js +++ b/lib/imap.js @@ -129,7 +129,6 @@ ImapConnection.prototype.connect = function(loginCb) { state.conn.cleartext = state.conn; state.conn.on('connect', function() { - clearTimeout(state.tmrConn); state.connected = true; state.authenticated = false; self.debug&&self.debug('[connection] Connected to host.'); @@ -488,6 +487,7 @@ ImapConnection.prototype.connect = function(loginCb) { var code = m[2]; if (state.status === STATES.NOAUTH) { if (!state.isReady) { + clearTimeout(state.tmrConn); state.isReady = true; state.conn.emit('ready'); } @@ -666,8 +666,11 @@ ImapConnection.prototype.connect = function(loginCb) { state.conn.cleartext.on('data', ondata); state.conn.connect(this._options.port, this._options.host); - state.tmrConn = setTimeout(this._fnTmrConn.bind(this, loginCb), - this._options.connTimeout); + + state.tmrConn = setTimeout(function() { + state.conn.destroy(); + loginCb(new Error('Connection timed out')); + }, this._options.connTimeout); }; ImapConnection.prototype.isAuthenticated = function() { @@ -1274,11 +1277,6 @@ ImapConnection.prototype.__defineGetter__('seq', function() { // Private/Internal Functions -ImapConnection.prototype._fnTmrConn = function(loginCb) { - loginCb(new Error('Connection timed out')); - this._state.conn.destroy(); -}; - ImapConnection.prototype._serverSupports = function(capability) { return (this.capabilities.indexOf(capability) > -1); };