Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions lib/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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'));
}
});
};
Expand Down Expand Up @@ -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),
Expand Down