Simplify checking of server capabilities

fork
Brian White 12 years ago
parent 15a2e1036b
commit 1866d4ad88

@ -95,7 +95,7 @@ ImapConnection.prototype.connect = function(loginCb) {
return;
}
// Next, get the list of available namespaces if supported (RFC2342)
if (!reentry && self.capabilities.indexOf('NAMESPACE') > -1) {
if (!reentry && self._supports('NAMESPACE')) {
var fnMe = arguments.callee;
// Re-enter this function after we've obtained the available
// namespaces
@ -513,8 +513,7 @@ ImapConnection.prototype.connect = function(loginCb) {
self._state.requests.shift();
if (self._state.requests.length === 0
&& recentCmd !== 'LOGOUT') {
if (self._state.status === STATES.BOXSELECTED &&
self.capabilities.indexOf('IDLE') > -1) {
if (self._state.status === STATES.BOXSELECTED && self._supports('IDLE')) {
// According to RFC 2177, we should re-IDLE at least every 29
// minutes to avoid disconnection by the server
self._send('IDLE', undefined, true);
@ -525,7 +524,7 @@ ImapConnection.prototype.connect = function(loginCb) {
self._state.ext.idle.timeWaited += self._state.tmoKeepalive;
if (self._state.ext.idle.timeWaited >= self._state.ext.idle.MAX_WAIT)
self._send('IDLE', undefined, true); // restart IDLE
} else if (self.capabilities.indexOf('IDLE') === -1)
} else if (!self._supports('IDLE'))
self._noop();
}
}, self._state.tmoKeepalive);
@ -602,7 +601,7 @@ ImapConnection.prototype.getBoxes = function(namespace, cb) {
cb = arguments[arguments.length - 1];
if (arguments.length !== 2)
namespace = '';
this._send(((this.capabilities.indexOf('XLIST') == -1) ? 'LIST' : 'XLIST')
this._send((!this._supports('XLIST') ? 'LIST' : 'XLIST')
+ ' "' + utils.escape(namespace) + '" "*"', cb);
};
@ -765,7 +764,7 @@ ImapConnection.prototype._fetch = function(which, uids, options) {
var extensions = '';
// always fetch GMail-specific bits of information when on GMail
if (this.capabilities.indexOf('X-GM-EXT-1') > -1)
if (this._supports('X-GM-EXT-1'))
extensions = 'X-GM-THRID X-GM-MSGID X-GM-LABELS ';
this._send(which + 'FETCH ' + uids.join(',') + ' (' + extensions
@ -922,7 +921,11 @@ ImapConnection.prototype.__defineGetter__('seq', function() {
ImapConnection.prototype._fnTmrConn = function(loginCb) {
loginCb(new Error('Connection timed out'));
this._state.conn.destroy();
}
};
ImapConnection.prototype._supports = function(capability) {
return (this.capabilities.indexOf(capability) > -1);
};
ImapConnection.prototype._store = function(which, uids, flags, isAdding, cb) {
var isKeywords = (arguments.callee.caller === this.addKeywords
@ -982,11 +985,10 @@ ImapConnection.prototype._login = function(cb) {
};
if (this._state.status === STATES.NOAUTH) {
if (this.capabilities.indexOf('LOGINDISABLED') !== -1)
if (this._supports('LOGINDISABLED'))
return cb(new Error('Logging in is disabled on this server'));
if (this.capabilities.indexOf('AUTH=XOAUTH') !== -1
&& 'xoauth' in this._options) {
if (this._supports('AUTH=XOAUTH') && 'xoauth' in this._options) {
this._send('AUTHENTICATE XOAUTH ' + utils.escape(this._options.xoauth),
fnReturn);
} else if (this._options.username !== undefined

Loading…
Cancel
Save