Watch out for unsolicited FETCH responses

Fixes #11
fork
Brian White 13 years ago
parent ef5ce33d43
commit e77eb8af26

@ -369,6 +369,9 @@ ImapConnection.prototype.connect = function(loginCb) {
break; break;
default: default:
if (/^\d+$/.test(data[1])) { if (/^\d+$/.test(data[1])) {
var isUnsolicited = (self._state.requests[0] &&
self._state.requests[0].command.indexOf('NOOP') > -1) ||
(self._state.isIdle && self._state.ext.idle.sentIdle);
switch (data[2]) { switch (data[2]) {
case 'EXISTS': case 'EXISTS':
// mailbox total message count // mailbox total message count
@ -386,12 +389,17 @@ ImapConnection.prototype.connect = function(loginCb) {
break; break;
case 'EXPUNGE': case 'EXPUNGE':
// confirms permanent deletion of a single message // confirms permanent deletion of a single message
// TODO: emit 'deleted' event for unsolicited expunge responses
if (self._state.box.messages.total > 0) if (self._state.box.messages.total > 0)
self._state.box.messages.total--; self._state.box.messages.total--;
break; break;
default: default:
// fetches without header or body (part) retrievals // fetches without header or body (part) retrievals
// TODO: emit event to notify flags for a message have changed
// for unsolicited fetch responses
if (/^FETCH/.test(data[2])) { if (/^FETCH/.test(data[2])) {
if (self._state.requests.length &&
self._state.requests[0].command.indexOf('FETCH') > -1) {
var curReq = self._state.requests[0], var curReq = self._state.requests[0],
msg = new ImapMessage(); msg = new ImapMessage();
parseFetch(data[2].substring(data[2].indexOf("(")+1, parseFetch(data[2].substring(data[2].indexOf("(")+1,
@ -403,6 +411,7 @@ ImapConnection.prototype.connect = function(loginCb) {
} }
} }
} }
}
} else if (data[0].indexOf('A') === 0) { // Tagged server response } else if (data[0].indexOf('A') === 0) { // Tagged server response
var sendBox = false; var sendBox = false;
clearTimeout(self._state.tmrKeepalive); clearTimeout(self._state.tmrKeepalive);

Loading…
Cancel
Save