From 92e91ca3c1680c9e9e0e939976099d3f004a2cfb Mon Sep 17 00:00:00 2001 From: Brian White Date: Tue, 22 Feb 2011 06:11:58 -0500 Subject: [PATCH] More reliable new mail event detection. --- imap.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/imap.js b/imap.js index 65ec144..b02b7ef 100644 --- a/imap.js +++ b/imap.js @@ -305,12 +305,16 @@ ImapConnection.prototype.connect = function(loginCb) { if (/^\d+$/.test(data[1])) { switch (data[2]) { case 'EXISTS': // mailbox total message count - self._state.box.messages.total = parseInt(data[1]); + var prev = self._state.box.messages.total, + now = parseInt(data[1]); + self._state.box.messages.total = now; + if (self._state.status !== STATES.BOXSELECTING && now > prev) { + self._state.box.messages.new = now-prev; + self.emit('mail', self._state.box.messages.new); // new mail notification + } break; case 'RECENT': // messages marked with the \Recent flag (i.e. new messages) self._state.box.messages.new = parseInt(data[1]); - if (self._state.status !== STATES.BOXSELECTING) - self.emit('mail', self._state.box.messages.new); // new mail notification break; case 'EXPUNGE': // confirms permanent deletion of a single message if (self._state.box.messages.total > 0)