From 44fb67691088a06f139ded320f107421effb82f4 Mon Sep 17 00:00:00 2001 From: mscdex Date: Mon, 14 Jan 2013 15:13:16 -0500 Subject: [PATCH] fix unsolicited fetch response detection --- README.md | 2 +- lib/imap.js | 109 ++++++++++++++++++++++++++-------------------------- 2 files changed, 56 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index e741266..e908c28 100644 --- a/README.md +++ b/README.md @@ -272,7 +272,7 @@ The structure of a message with only one part will simply look something like th Therefore, an easy way to check for a multipart message is to check if the structure length is >1. -Lastly, here are the system flags defined by the IMAP spec (that may be added/removed to/from messages): +Lastly, here are the system flags defined by RFC3501 that may be added/removed: * Seen - Message has been read * Answered - Message has been answered diff --git a/lib/imap.js b/lib/imap.js index 63b8eaa..cfca36a 100644 --- a/lib/imap.js +++ b/lib/imap.js @@ -308,69 +308,72 @@ ImapConnection.prototype.connect = function(loginCb) { // m.info = message details var data, parsed, headers, f, lenf, body, lenb, msg, bodies, details, val; - bodies = parsers.parseFetchBodies(m.info, indata.literals); + if (!isUnsolicited) + bodies = parsers.parseFetchBodies(m.info, indata.literals); details = new ImapMessage(); parsers.parseFetch(m.info, indata.literals, details); details.seqno = parseInt(m.num, 10); - if (requests[0].fetchers[''] !== undefined) { - // account for non-body fetches - if (bodies) { - bodies.push(''); - bodies.push(null); - } else - bodies = ['', null]; - } + if (isUnsolicited) + self.emit('msgupdate', details); + else { + if (requests[0].fetchers[''] !== undefined) { + // account for non-body fetches + if (bodies) { + bodies.push(''); + bodies.push(null); + } else + bodies = ['', null]; + } - for (body = 0, lenb = bodies.length; body < lenb; body += 2) { - fetches = requests[0].fetchers[bodies[body]]; - val = bodies[body + 1]; - for (var i=0, len=fetches.length; i