Connection: guard internal box manipulation

fork
mscdex 11 years ago
parent 86ac8ceabc
commit a5a3ccfb4d

@ -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();

Loading…
Cancel
Save