fix emitting of 'message' event for fetch responses with no body literals

fork
mscdex 12 years ago
parent 44fb676910
commit 2964cfe14a

@ -326,12 +326,13 @@ ImapConnection.prototype.connect = function(loginCb) {
bodies = ['', null];
}
var shouldEmit;
for (body = 0, lenb = bodies.length; body < lenb; body += 2) {
fetches = requests[0].fetchers[bodies[body]];
val = bodies[body + 1];
for (var i=0, len=fetches.length; i<len; ++i) {
parsed = undefined;
if (!fetches[i]._msg)
if (shouldEmit = (!fetches[i]._msg))
fetches[i]._msg = new ImapMessage();
// copy message properties (uid, date, flags, etc)
@ -339,15 +340,18 @@ ImapConnection.prototype.connect = function(loginCb) {
k < lenk; ++k)
fetches[i]._msg[keys[k]] = details[keys[k]];
if (shouldEmit)
fetches[i].emit('message', fetches[i]._msg);
if (typeof val === 'number') {
// we streamed a body, e.g. {3}\r\nfoo
} else {
// no body was streamed
if (typeof val === 'string') {
// a body was given as a non-literal string, e.g. "foo"
// a body was given as a quoted, non-literal string,
// e.g. "foo"
if (RE_ISHEADER.test(bodies[body])) {
var parsed, data, headers;
//for (f = 0, lenf = fetches.length; f < lenf; ++f) {
if (fetches[i]._parse) {
if (parsed === undefined)
parsed = parsers.parseHeaders(val);
@ -358,15 +362,10 @@ ImapConnection.prototype.connect = function(loginCb) {
headers = data;
}
fetches[i]._msg.emit('headers', headers);
//}
} else {
var data = new Buffer(val, 'binary');
//for (f = 0, lenf = fetches.length; f < lenf; ++f)
fetches[i]._msg.emit('data', data);
}
} else if (val === null) {
//for (f = 0, lenf = fetches.length; f < lenf; ++f)
fetches[i].emit('message', fetches[i]._msg);
}
}
}

Loading…
Cancel
Save