fork
mscdex 12 years ago
parent 1a69a5646c
commit 1815f9d5f8

@ -148,7 +148,7 @@ ImapConnection.prototype.connect = function(loginCb) {
self.authenticated = false; self.authenticated = false;
self.debug&&self.debug('[connection] Connected to host.'); self.debug&&self.debug('[connection] Connected to host.');
state.status = STATES.NOAUTH; state.status = STATES.NOAUTH;
}; }
state.conn.on('end', function() { state.conn.on('end', function() {
self.connected = false; self.connected = false;
@ -255,7 +255,8 @@ ImapConnection.prototype.connect = function(loginCb) {
if (b.length === 0 || b.p >= b.length) return; if (b.length === 0 || b.p >= b.length) return;
self.debug&&self.debug('\n<== ' + inspect(b.toString('binary', b.p)) + '\n'); self.debug&&self.debug('\n<== ' + inspect(b.toString('binary', b.p)) + '\n');
var r, m, litType, i, len, msg, fetches, f, lenf; var r, m, litType, i, len, msg, fetches, index;
if (indata.expect > 0) { if (indata.expect > 0) {
r = read(b); r = read(b);
if (indata.streaming) { if (indata.streaming) {
@ -318,8 +319,7 @@ ImapConnection.prototype.connect = function(loginCb) {
switch (m.type) { switch (m.type) {
case 'FETCH': case 'FETCH':
// m.info = message details // m.info = message details
var data, parsed, headers, f, lenf, body, lenb, msg, bodies, var data, parsed, headers, body, lenb, bodies, details, val;
details, val;
isUnsolicited = isUnsolicited isUnsolicited = isUnsolicited
|| (requests[0] || (requests[0]
@ -334,7 +334,7 @@ ImapConnection.prototype.connect = function(loginCb) {
if (details['x-gm-labels'] !== undefined) { if (details['x-gm-labels'] !== undefined) {
var labels = details['x-gm-labels']; var labels = details['x-gm-labels'];
for (var i=0, len=labels.length; i<len; ++i) for (i=0, len=labels.length; i<len; ++i)
labels[i] = ('' + labels[i]).replace(RE_ESCAPE, '\\') labels[i] = ('' + labels[i]).replace(RE_ESCAPE, '\\')
} }
@ -354,7 +354,7 @@ ImapConnection.prototype.connect = function(loginCb) {
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 (i=0, len=fetches.length; i<len; ++i) {
parsed = undefined; parsed = undefined;
if (shouldEmit = (!fetches[i]._msg)) if (shouldEmit = (!fetches[i]._msg))
fetches[i]._msg = new ImapMessage(); fetches[i]._msg = new ImapMessage();
@ -375,7 +375,6 @@ ImapConnection.prototype.connect = function(loginCb) {
// a body was given as a quoted, non-literal string, // a body was given as a quoted, non-literal string,
// e.g. "foo" // e.g. "foo"
if (RE_ISHEADER.test(bodies[body])) { if (RE_ISHEADER.test(bodies[body])) {
var parsed, data, headers;
if (fetches[i]._parse) { if (fetches[i]._parse) {
if (parsed === undefined) if (parsed === undefined)
parsed = parsers.parseHeaders(val); parsed = parsers.parseHeaders(val);
@ -387,7 +386,7 @@ ImapConnection.prototype.connect = function(loginCb) {
} }
fetches[i]._msg.emit('headers', headers); fetches[i]._msg.emit('headers', headers);
} else { } else {
var data = new Buffer(val, 'binary'); data = new Buffer(val, 'binary');
fetches[i]._msg.emit('data', data); fetches[i]._msg.emit('data', data);
} }
} }
@ -672,31 +671,31 @@ ImapConnection.prototype.connect = function(loginCb) {
if (typeof requests[0].callback === 'function') { if (typeof requests[0].callback === 'function') {
m = RE_TAGGED_RESP.exec(line); m = RE_TAGGED_RESP.exec(line);
var err = null; var error = null;
var args = requests[0].cbargs, var args = requests[0].cbargs,
cmdstr = requests[0].cmdstr; cmdstr = requests[0].cmdstr;
if (!m) { if (!m) {
if (requests[0].cmd === 'APPEND') if (requests[0].cmd === 'APPEND')
return requests[0].callback(); return requests[0].callback();
else { else {
var isXOAuth2 = (cmdstr.indexOf('AUTHENTICATE XOAUTH2') === 0), var isXOAuth2 = (cmdstr.indexOf('AUTHENTICATE XOAUTH2') === 0);
msg = (isXOAuth2 msg = (isXOAuth2
? new Buffer(line.substr(2), 'base64').toString('utf8') ? new Buffer(line.substr(2), 'base64').toString('utf8')
: 'Unexpected continuation'); : 'Unexpected continuation');
err = new Error(msg); error = new Error(msg);
err.level = 'protocol'; error.level = 'protocol';
err.type = (isXOAuth2 ? 'failure' : 'continuation'); error.type = (isXOAuth2 ? 'failure' : 'continuation');
err.request = cmdstr; error.request = cmdstr;
} }
} else if (m[1] !== 'OK') { } else if (m[1] !== 'OK') {
// m[1]: error type // m[1]: error type
// m[2]: resp-text-code // m[2]: resp-text-code
// m[3]: message // m[3]: message
err = new Error(m[3]); error = new Error(m[3]);
err.level = 'protocol'; error.level = 'protocol';
err.type = 'failure'; error.type = 'failure';
err.code = m[2]; error.code = m[2];
err.request = cmdstr; error.request = cmdstr;
} else if (state.status === STATES.BOXSELECTED) { } else if (state.status === STATES.BOXSELECTED) {
if (sendBox) // SELECT, EXAMINE, RENAME if (sendBox) // SELECT, EXAMINE, RENAME
args.unshift(state.box); args.unshift(state.box);
@ -710,7 +709,8 @@ ImapConnection.prototype.connect = function(loginCb) {
args.unshift([]); args.unshift([]);
} }
if (m) { if (m) {
var msg = m[3], info; var info;
msg = m[3];
if (m[2]) { if (m[2]) {
m = RE_TEXT_CODE.exec(m[2]); m = RE_TEXT_CODE.exec(m[2]);
info = { info = {
@ -722,7 +722,7 @@ ImapConnection.prototype.connect = function(loginCb) {
info = { message: msg }; info = { message: msg };
args.push(info); args.push(info);
} }
args.unshift(err); args.unshift(error);
requests[0].callback.apply(self, args); requests[0].callback.apply(self, args);
} }
@ -738,9 +738,8 @@ ImapConnection.prototype.connect = function(loginCb) {
} else if (RE_RES_IDLE.test(indata.line)) { } else if (RE_RES_IDLE.test(indata.line)) {
self.debug&&self.debug('[parsing incoming] saw IDLE'); self.debug&&self.debug('[parsing incoming] saw IDLE');
requests.shift(); // remove IDLE request requests.shift(); // remove IDLE request
var idx; if ((index = indata.line.indexOf(CRLF)) > -1)
if ((idx = indata.line.indexOf(CRLF)) > -1) indata.line = indata.line.substr(index + 2);
indata.line = indata.line.substr(idx + 2);
else else
indata.line = undefined; indata.line = undefined;
state.ext.idle.state = IDLE_NONE; state.ext.idle.state = IDLE_NONE;
@ -753,9 +752,8 @@ ImapConnection.prototype.connect = function(loginCb) {
} else if (RE_RES_NOOP.test(indata.line)) { } else if (RE_RES_NOOP.test(indata.line)) {
self.debug&&self.debug('[parsing incoming] saw NOOP'); self.debug&&self.debug('[parsing incoming] saw NOOP');
requests.shift(); // remove NOOP request requests.shift(); // remove NOOP request
var idx; if ((index = indata.line.indexOf(CRLF)) > -1)
if ((idx = indata.line.indexOf(CRLF)) > -1) indata.line = indata.line.substr(index + 2);
indata.line = indata.line.substr(idx + 2);
else else
indata.line = undefined; indata.line = undefined;
if (!requests.length) if (!requests.length)
@ -1020,8 +1018,7 @@ ImapConnection.prototype._fetch = function(which, uids, options, what, cb) {
uids = [uids]; uids = [uids];
utils.validateUIDList(uids); utils.validateUIDList(uids);
var toFetch = '', prefix = ' BODY[', extensions, self = this, var toFetch = '', prefix = ' BODY[', extensions, parse, headers, key, stream,
parse, headers, key, stream,
fetchers = {}; fetchers = {};
// argument detection! // argument detection!

@ -306,8 +306,8 @@ exports.parseStructExtra = function(part, partLen, cur, next) {
exports.parseExpr = function(o, literals, result, start, useBrackets) { exports.parseExpr = function(o, literals, result, start, useBrackets) {
start = start || 0; start = start || 0;
var inQuote = false, lastPos = start - 1, isTop = false, inLitStart = false, var inQuote = false, lastPos = start - 1, isTop = false, val;
val;
if (useBrackets === undefined) if (useBrackets === undefined)
useBrackets = true; useBrackets = true;
if (!result) if (!result)

Loading…
Cancel
Save