fork
mscdex 12 years ago
parent 1a69a5646c
commit 1815f9d5f8

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

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

Loading…
Cancel
Save