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