From 61fdef282d680158329528892cde899d86baacc0 Mon Sep 17 00:00:00 2001 From: Brian White Date: Sun, 26 Aug 2012 10:11:15 -0400 Subject: [PATCH] Fix scope issue when re-using mime parser instance --- lib/imap.js | 8 ++++---- lib/mimeparser.js | 7 +------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/imap.js b/lib/imap.js index 7e2dd3f..fad043d 100644 --- a/lib/imap.js +++ b/lib/imap.js @@ -255,13 +255,13 @@ ImapConnection.prototype.connect = function(loginCb) { self._state.parser = new MIMEParser(); self._state.parser.on('header', function(name, val) { name = name.toLowerCase(); - if (curReq._msg.headers[name] !== undefined) - curReq._msg.headers[name].push(val); + if (self._state.requests[0]._msg.headers[name] !== undefined) + self._state.requests[0]._msg.headers[name].push(val); else - curReq._msg.headers[name] = [val]; + self._state.requests[0]._msg.headers[name] = [val]; }); self._state.parser.on('data', function(str) { - curReq._msg.emit('data', str); + self._state.requests[0]._msg.emit('data', str); }); } } diff --git a/lib/mimeparser.js b/lib/mimeparser.js index cb00370..51d857c 100644 --- a/lib/mimeparser.js +++ b/lib/mimeparser.js @@ -13,12 +13,7 @@ var CR = 13, REGEXP_FOLD = /\r\n\s+/g; var MIMEParser = module.exports = function() { - this._state = PARSE_HEADER_NAME; - this._hdrname = ''; - this._hdrval = ''; - this._sawCR = false; - this._sawLF = false; - this._needUnfold = false; + this.finish(); }; inherits(MIMEParser, EventEmitter);