From 26c6a7827c33cc60add810e596034d03eea548b2 Mon Sep 17 00:00:00 2001 From: mscdex Date: Sun, 7 Apr 2013 19:10:27 -0400 Subject: [PATCH] guard against duplicate DONE commands --- lib/imap.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/imap.js b/lib/imap.js index 3b236b2..76ce23e 100644 --- a/lib/imap.js +++ b/lib/imap.js @@ -39,7 +39,8 @@ var CRLF = '\r\n', // extension constants var IDLE_NONE = 1, IDLE_WAIT = 2, - IDLE_IDLING = 3; + IDLE_IDLING = 3, + IDLE_DONE = 4; function ImapConnection(options) { if (!(this instanceof ImapConnection)) @@ -763,9 +764,10 @@ ImapConnection.prototype.connect = function(loginCb) { if (state.isIdle) { if (state.ext.idle.state === IDLE_IDLING) { var timeDiff = Date.now() - state.ext.idle.timeStarted; - if (timeDiff >= state.ext.idle.MAX_WAIT) + if (timeDiff >= state.ext.idle.MAX_WAIT) { + state.ext.idle.state = IDLE_DONE; self._send('DONE'); - else + } else state.tmrKeepalive = setTimeout(idleHandler, state.tmoKeepalive); } else if (!self.serverSupports('IDLE')) doKeepalive(); @@ -1578,8 +1580,10 @@ ImapConnection.prototype._send = function(cmdstr, cb) { } if (idle.state !== IDLE_NONE && cmdstr !== 'DONE') { - if (cmdstr !== undefined) + if (cmdstr !== undefined && idle.state !== IDLE_DONE) { + idle.state = IDLE_DONE; this._send('DONE'); + } return; }