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.authenticated = false;
self.debug&&self.debug('[connection] FIN packet received. Disconnecting...');
clearTimeout(state.tmrConn);
self.emit('end');
});
@ -154,9 +155,11 @@ ImapConnection.prototype.connect = function(loginCb) {
state.conn.on('error', function(err) {
clearTimeout(state.tmrConn);
err.level = 'socket';
if (state.status === STATES.NOCONNECT)
loginCb(new Error('Unable to connect. Reason: ' + err));
self.emit('error', err);
loginCb(err);
else
self.emit('error', err);
self.debug&&self.debug('[connection] Error occurred: ' + err);
});
@ -569,8 +572,16 @@ ImapConnection.prototype.connect = function(loginCb) {
break;
case 'NO':
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();
}
break;
}
} else {

Loading…
Cancel
Save