From f107a86f105609fb15f1ef79cb1129b21b9a7ef0 Mon Sep 17 00:00:00 2001 From: Brian White Date: Thu, 3 Jan 2013 13:59:57 -0500 Subject: [PATCH] fix double emit on fetch() --- lib/imap.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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);