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,19 +389,25 @@ 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])) {
var curReq = self._state.requests[0], if (self._state.requests.length &&
msg = new ImapMessage(); self._state.requests[0].command.indexOf('FETCH') > -1) {
parseFetch(data[2].substring(data[2].indexOf("(")+1, var curReq = self._state.requests[0],
data[2].lastIndexOf(")")), msg = new ImapMessage();
"", msg); parseFetch(data[2].substring(data[2].indexOf("(")+1,
curReq._fetcher.emit('message', msg); data[2].lastIndexOf(")")),
msg.emit('end'); "", msg);
curReq._fetcher.emit('message', msg);
msg.emit('end');
}
} }
} }
} }

Loading…
Cancel
Save