From 098aa73b966b9d502ac90bde76bc24d142ac7d50 Mon Sep 17 00:00:00 2001 From: lucas-pouchot Date: Wed, 20 Apr 2016 11:56:12 +0200 Subject: [PATCH] Update Connection.js add some check on object _curReq and object box before use it It's fix some uncaugth error like : self._box.name = name; ^ TypeError: Cannot set property 'name' of undefined at Connection. (/root/thethingbox/node_modules/node-red/node_modules/node-red-node-email/node_modules/imap/lib/Connection.js:422:22) or var msg = self._curReq.fetchCache[info.seqno], toget; ^ TypeError: Cannot read property 'fetchCache' of undefined at Parser. (/root/thethingbox/node_modules/node-red/node_modules/node-red-node-email/node_modules/imap/lib/Connection.js:196:27) --- lib/Connection.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/Connection.js b/lib/Connection.js index 292d854e..6fcf5cca 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -193,8 +193,16 @@ Connection.prototype.connect = function() { self._resTagged(info); }); parser.on('body', function(stream, info) { - var msg = self._curReq.fetchCache[info.seqno], toget; - + if (!self._curReq) { + stream.resume(); + return; + } + var msg = undefined; + var toget; + if (self._curReq.fetchCache.hasOwnProperty(info.seqno)) { + msg = self._curReq.fetchCache[info.seqno]; + } + if (msg === undefined) { msg = self._curReq.fetchCache[info.seqno] = { msgEmitter: new EventEmitter(), @@ -422,9 +430,11 @@ Connection.prototype.openBox = function(name, readOnly, cb) { if (err) { self._box = undefined; cb(err); - } else { + } else if (self._box) { self._box.name = name; cb(err, self._box); + } else { + cb(new Error('No mailbox is currently selected')); } }); }; @@ -1400,7 +1410,7 @@ Connection.prototype._resUntagged = function(info) { } this._curReq.cbargs.push(box); } else if (type === 'fetch') { - if (/^(?:UID )?FETCH/.test(this._curReq.fullcmd)) { + if (this._curReq && /^(?:UID )?FETCH/.test(this._curReq.fullcmd)) { // FETCH response sent as result of FETCH request var msg = this._curReq.fetchCache[info.num], keys = Object.keys(info.text),