Add isConnected and isAuthenticated properties

fork
Brian White 12 years ago
parent 8db9bccc72
commit d39b7e72ac

@ -44,6 +44,7 @@ function ImapConnection (options) {
connTimeout: 10000, // connection timeout in msecs
debug: false
};
this._state = {
status: STATES.NOCONNECT,
conn: null,
@ -89,9 +90,12 @@ function ImapConnection (options) {
this.debug = this._options.debug;
else
this.debug = false;
this.delimiter = undefined;
this.namespaces = { personal: [], other: [], shared: [] };
this.capabilities = [];
this.isConnected = false;
this.isAuthenticated = false;
}
inherits(ImapConnection, EventEmitter);
@ -119,12 +123,16 @@ ImapConnection.prototype.connect = function(loginCb) {
state.conn.on('connect', function() {
clearTimeout(state.tmrConn);
state.isConnected = true;
state.isAuthenticated = false;
self.debug&&self.debug('[connection] Connected to host.');
state.conn.cleartext.write('');
state.status = STATES.NOAUTH;
});
state.conn.on('end', function() {
state.isConnected = false;
state.isAuthenticated = false;
self.debug&&self.debug('[connection] FIN packet received. Disconnecting...');
self.emit('end');
});
@ -142,6 +150,8 @@ ImapConnection.prototype.connect = function(loginCb) {
state.conn.on('close', function(had_error) {
self._reset();
requests = state.requests;
state.isConnected = false;
state.isAuthenticated = false;
self.debug&&self.debug('[connection] Connection closed.');
self.emit('close', had_error);
});
@ -498,6 +508,7 @@ ImapConnection.prototype.connect = function(loginCb) {
break;
case 'PREAUTH':
state.status = STATES.AUTH;
state.isAuthenticated = true;
if (state.numCapRecvs === 0)
state.numCapRecvs = 1;
break;
@ -1188,6 +1199,7 @@ ImapConnection.prototype._login = function(cb) {
fnReturn = function(err) {
if (!err) {
self._state.status = STATES.AUTH;
self._state.isAuthenticated = true;
if (self._state.numCapRecvs !== 2) {
// fetch post-auth server capabilities if they were not
// automatically provided after login

Loading…
Cancel
Save