improve handling of negative welcome response upon connection

fork
mscdex 12 years ago
parent d4b7fbc0f8
commit 86efc68998

@ -140,6 +140,7 @@ ImapConnection.prototype.connect = function(loginCb) {
state.connected = false; state.connected = false;
state.authenticated = false; state.authenticated = false;
self.debug&&self.debug('[connection] FIN packet received. Disconnecting...'); self.debug&&self.debug('[connection] FIN packet received. Disconnecting...');
clearTimeout(state.tmrConn);
self.emit('end'); self.emit('end');
}); });
@ -154,8 +155,10 @@ ImapConnection.prototype.connect = function(loginCb) {
state.conn.on('error', function(err) { state.conn.on('error', function(err) {
clearTimeout(state.tmrConn); clearTimeout(state.tmrConn);
err.level = 'socket';
if (state.status === STATES.NOCONNECT) if (state.status === STATES.NOCONNECT)
loginCb(new Error('Unable to connect. Reason: ' + err)); loginCb(err);
else
self.emit('error', err); self.emit('error', err);
self.debug&&self.debug('[connection] Error occurred: ' + err); self.debug&&self.debug('[connection] Error occurred: ' + err);
}); });
@ -569,8 +572,16 @@ ImapConnection.prototype.connect = function(loginCb) {
break; break;
case 'NO': case 'NO':
case 'BAD': case 'BAD':
if (state.status === STATES.NOAUTH) if (state.status === STATES.NOAUTH) {
clearTimeout(state.tmrConn);
var err = new Error('Received negative welcome (' + m[3] + ')');
err.level = 'protocol';
if (state.status === STATES.NOCONNECT)
loginCb(err);
else
self.emit('error', err);
state.conn.end(); state.conn.end();
}
break; break;
} }
} else { } else {

Loading…
Cancel
Save