fix unsolicited fetch response detection

fork
mscdex 12 years ago
parent 23dc0e9c80
commit 44fb676910

@ -272,7 +272,7 @@ The structure of a message with only one part will simply look something like th
Therefore, an easy way to check for a multipart message is to check if the structure length is >1.
Lastly, here are the system flags defined by the IMAP spec (that may be added/removed to/from messages):
Lastly, here are the system flags defined by RFC3501 that may be added/removed:
* Seen - Message has been read
* Answered - Message has been answered

@ -308,69 +308,72 @@ ImapConnection.prototype.connect = function(loginCb) {
// m.info = message details
var data, parsed, headers, f, lenf, body, lenb, msg, bodies,
details, val;
bodies = parsers.parseFetchBodies(m.info, indata.literals);
if (!isUnsolicited)
bodies = parsers.parseFetchBodies(m.info, indata.literals);
details = new ImapMessage();
parsers.parseFetch(m.info, indata.literals, details);
details.seqno = parseInt(m.num, 10);
if (requests[0].fetchers[''] !== undefined) {
// account for non-body fetches
if (bodies) {
bodies.push('');
bodies.push(null);
} else
bodies = ['', null];
}
if (isUnsolicited)
self.emit('msgupdate', details);
else {
if (requests[0].fetchers[''] !== undefined) {
// account for non-body fetches
if (bodies) {
bodies.push('');
bodies.push(null);
} else
bodies = ['', null];
}
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)
fetches[i]._msg = new ImapMessage();
// copy message properties (uid, date, flags, etc)
for (var k = 0, keys = Object.keys(details), lenk = keys.length;
k < lenk; ++k)
fetches[i]._msg[keys[k]] = details[keys[k]];
if (typeof val === 'number') {
// we streamed a body, e.g. {3}\r\nfoo
} else {
// no body was streamed
if (isUnsolicited)
self.emit('msgupdate', details);
else if (typeof val === 'string') {
// a body was given as a 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);
headers = parsed;
} else {
if (data === undefined)
data = new Buffer(val, 'binary');
headers = data;
}
fetches[i]._msg.emit('headers', headers);
//}
} else {
var data = new Buffer(val, 'binary');
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)
fetches[i]._msg = new ImapMessage();
// copy message properties (uid, date, flags, etc)
for (var k = 0, keys = Object.keys(details), lenk = keys.length;
k < lenk; ++k)
fetches[i]._msg[keys[k]] = details[keys[k]];
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"
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);
headers = parsed;
} else {
if (data === undefined)
data = new Buffer(val, 'binary');
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]._msg.emit('data', data);
fetches[i].emit('message', fetches[i]._msg);
}
} else if (val === null) {
//for (f = 0, lenf = fetches.length; f < lenf; ++f)
fetches[i].emit('message', fetches[i]._msg);
}
}
}
for (body = 0, lenb = bodies.length; body < lenb; body += 2)
emitMsgEnd(bodies[body]);
}
for (body = 0, lenb = bodies.length; body < lenb; body += 2)
emitMsgEnd(bodies[body]);
break;
case 'EXISTS':
// mailbox total message count
@ -1198,7 +1201,6 @@ ImapConnection.prototype._storeLabels = function(which, uids, labels, mode, cb)
if (!Array.isArray(labels))
labels = [labels];
labels = labels.join(' ');
cb = arguments[arguments.length-1];
this._send(which + 'STORE ' + uids.join(',') + ' ' + mode
+ 'X-GM-LABELS.SILENT (' + labels + ')', cb);
@ -1362,7 +1364,6 @@ ImapConnection.prototype._store = function(which, uids, flags, isAdding, cb) {
}
}
flags = flags.join(' ');
cb = arguments[arguments.length-1];
this._send(which + 'STORE ' + uids.join(',') + ' ' + (isAdding ? '+' : '-')
+ 'FLAGS.SILENT (' + flags + ')', cb);

Loading…
Cancel
Save