Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added new imapConnection event 'idleResponse' for more complete chang…

…e notification.
  • Loading branch information...
commit a8dba9a539d2f6c9c24285b3368919b8522573e8 1 parent 28ef611
Bruno Morency authored
Showing with 25 additions and 0 deletions.
  1. +2 −0  README.md
  2. +23 −0 imap.js
View
2  README.md
@@ -199,6 +199,8 @@ ImapConnection Events
* **error**(Error) - Fires when an exception/error occurs (similar to net.Stream's error event). The given Error object represents the error raised.
+* **idleResponse**(Integer, String, Mixed) - Fires when an idling connection (or NOOP if server doesn't support IDLE) gets a response. Params supplied are: sequence id (Integer), response (String) and flags as an Array if the response is 'FETCH' or false otherwise.
+
ImapConnection Properties
-------------------------
View
23 imap.js
@@ -402,6 +402,29 @@ ImapConnection.prototype.connect = function(loginCb) {
}
}
}
+ if ((self._state.ext.idle.sentIdle || self._state.requests[0].command == 'NOOP') && /^(EXISTS|EXPUNGE|RECENT|FETCH)/.test(data[2])) {
+ // Emit 'idleResponse' event for untagged server responses received from a NOOP
+ // or while idling.
+ //
+ // In the case on new message arriving in mailbox, both the 'mail' event
+ // (see 'EXISTS' case above) and this 'idleResponse' event will be triggered.
+ //
+ // In the case on flags changing on an existing message and the response
+ // is not from an IDLE command, both the 'message' event (see default
+ // case above) and this 'idleResponse' event will be triggered.
+
+ // parse flags on FETCH response into data structure
+ var rData = data[2].trim().explode(' ',2);
+ if (rData[0] == 'FETCH') {
+ var flags = false;
+ try {
+ flags = rData[1].match(/^\(FLAGS \((.*)\)\)/).pop().split(' ');
+ } catch (e) {}
+ }
+
+ self.emit('idleResponse', parseInt(data[1]), rData[0], flags);
+ }
+
}
}
} else if (data[0].indexOf('A') === 0) { // Tagged server response
Please sign in to comment.
Something went wrong with that request. Please try again.