diff --git a/lib/imap.js b/lib/imap.js index 42583ca..83a48b9 100644 --- a/lib/imap.js +++ b/lib/imap.js @@ -248,13 +248,15 @@ ImapConnection.prototype.connect = function(loginCb) { if (indata.expect > -1) { if ((m = /\* (\d+) FETCH/i.exec(indata.line)) && /^BODY\[/i.test(litType)) { - msg = new ImapMessage(); - msg.seqno = parseInt(m[1], 10); - requests[0].msg = msg; + if (!requests[0].msg) { + msg = new ImapMessage(); + msg.seqno = parseInt(m[1], 10); + requests[0].msg = msg; + var fetches = requests[0].fetchers[litType]; + for (var f = 0, lenf = fetches.length; f < lenf; ++f) + fetches[f].emit('message', msg); + } requests[0].key = litType; - var fetches = requests[0].fetchers[litType]; - for (var f = 0, lenf = fetches.length; f < lenf; ++f) - fetches[f].emit('message', msg); indata.streaming = (!RE_ISHEADER.test(litType)); if (indata.streaming) indata.literals.push(indata.expect);