From a5a3ccfb4df7745ee2e27a0121fbe6604d268fd9 Mon Sep 17 00:00:00 2001 From: mscdex Date: Wed, 14 Aug 2013 16:01:18 -0400 Subject: [PATCH] Connection: guard internal box manipulation --- lib/Connection.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/Connection.js b/lib/Connection.js index 4e89a0f..664ee6a 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -1107,11 +1107,13 @@ Connection.prototype._resUntagged = function(info) { } else if (type === 'recent') { if (!this._box && RE_OPENBOX.test(this._curReq.type)) this._createCurrentBox(); - this._box.messages.new = info.num; + if (this._box) + this._box.messages.new = info.num; } else if (type === 'flags') { if (!this._box && RE_OPENBOX.test(this._curReq.type)) this._createCurrentBox(); - this._box.flags = info.text; + if (this._box) + this._box.flags = info.text; } else if (type === 'bad' || type === 'no') { if (this.state === 'connected' && !this._curReq) { clearTimeout(this._tmrConn); @@ -1123,18 +1125,22 @@ Connection.prototype._resUntagged = function(info) { } else if (type === 'exists') { if (!this._box && RE_OPENBOX.test(this._curReq.type)) this._createCurrentBox(); - var prev = this._box.messages.total, - now = info.num; - this._box.messages.total = now; - if (now > prev && this.state === 'authenticated') { - this._box.messages.new = now - prev; - this.emit('mail', this._box.messages.total); + if (this._box) { + var prev = this._box.messages.total, + now = info.num; + this._box.messages.total = now; + if (now > prev && this.state === 'authenticated') { + this._box.messages.new = now - prev; + this.emit('mail', this._box.messages.total); + } } } else if (type === 'expunge') { - if (this._box.messages.total > 0) - --this._box.messages.total; - if (!this._curReq) - this.emit('expunge', info.num); + if (this._box) { + if (this._box.messages.total > 0) + --this._box.messages.total; + if (!this._curReq) + this.emit('expunge', info.num); + } } else if (type === 'ok') { if (this.state === 'connected' && !this._curReq) this._login();