fix IDLE after connection if there is nothing yet to do and other misc changes

fork
Brian White 12 years ago
parent 4e61905378
commit b5dca62d5b

@ -164,15 +164,17 @@ ImapConnection.prototype.connect = function(loginCb) {
state.conn.on('ready', function() { state.conn.on('ready', function() {
var checkedNS = false; var checkedNS = false;
var redo = function(err) { var reentry = function(err) {
if (err) if (err) {
state.conn.destroy();
return loginCb(err); return loginCb(err);
}
// Next, get the list of available namespaces if supported (RFC2342) // Next, get the list of available namespaces if supported (RFC2342)
if (!checkedNS && self._serverSupports('NAMESPACE')) { if (!checkedNS && self._serverSupports('NAMESPACE')) {
// Re-enter this function after we've obtained the available // Re-enter this function after we've obtained the available
// namespaces // namespaces
checkedNS = true; checkedNS = true;
return self._send('NAMESPACE', redo); return self._send('NAMESPACE', reentry);
} }
// Lastly, get the top-level mailbox hierarchy delimiter used by the // Lastly, get the top-level mailbox hierarchy delimiter used by the
// server // server
@ -185,9 +187,9 @@ ImapConnection.prototype.connect = function(loginCb) {
if (state.status !== STATES.AUTH) { if (state.status !== STATES.AUTH) {
// First get pre-auth capabilities, including server-supported auth // First get pre-auth capabilities, including server-supported auth
// mechanisms // mechanisms
self._login(redo); self._login(reentry);
} else } else
redo(); reentry();
}); });
}); });
@ -617,13 +619,13 @@ ImapConnection.prototype.connect = function(loginCb) {
args.unshift([]); args.unshift([]);
} }
args.unshift(err); args.unshift(err);
requests[0].callback.apply({}, args); requests[0].callback.apply(self, args);
} }
var recentCmd = requests[0].cmdstr; var recentCmd = requests[0].cmdstr;
requests.shift(); requests.shift();
if (requests.length === 0 && recentCmd !== 'LOGOUT') { if (requests.length === 0 && recentCmd !== 'LOGOUT') {
if (state.status === STATES.BOXSELECTED && self._serverSupports('IDLE')) { if (state.status >= STATES.AUTH && self._serverSupports('IDLE')) {
// According to RFC 2177, we should re-IDLE at least every 29 // According to RFC 2177, we should re-IDLE at least every 29
// minutes to avoid disconnection by the server // minutes to avoid disconnection by the server
self._send('IDLE', undefined, true); self._send('IDLE', undefined, true);
@ -766,7 +768,7 @@ ImapConnection.prototype.renameBox = function(oldname, newname, cb) {
ImapConnection.prototype.append = function(data, options, cb) { ImapConnection.prototype.append = function(data, options, cb) {
if (typeof options === 'function') { if (typeof options === 'function') {
cb = options; cb = options;
options = {}; options = undefined;
} }
options = options || {}; options = options || {};
if (!options.mailbox) { if (!options.mailbox) {

Loading…
Cancel
Save