|
|
|
@ -82,28 +82,7 @@ exports.parseFetchBodies = function(str, literals) {
|
|
|
|
|
if (Array.isArray(result[i])) {
|
|
|
|
|
if (result[i].length === 0)
|
|
|
|
|
result[i].push('');
|
|
|
|
|
/*else if (result[i].length === 2 && typeof result[i][1] === 'number') {
|
|
|
|
|
// OK, so ordinarily this is where we'd transform a partial fetch
|
|
|
|
|
// key so that it matches up with a key in our request's fetchers object
|
|
|
|
|
// but since IMAP sucks, we have no way to match up a partial fetch
|
|
|
|
|
// response if less than the number of octets we requested were returned.
|
|
|
|
|
//
|
|
|
|
|
// Example: We request BODY[TEXT]<0.32>, but BODY[TEXT] is only 16 bytes,
|
|
|
|
|
// then we get back: BODY[TEXT]<0> {16}
|
|
|
|
|
// This leaves us with no way to find out what the original
|
|
|
|
|
// length request was. ARGH!!!^%&#^@#$%&$!
|
|
|
|
|
// Because of this and the fact that the server can return requested
|
|
|
|
|
// values in any order, I am disabling partial fetches entirely.
|
|
|
|
|
|
|
|
|
|
// BODY[TEXT]<0.32>
|
|
|
|
|
result[i][0] += '<';
|
|
|
|
|
result[i][0] += result[i][1]; // starting octet
|
|
|
|
|
result[i][0] += '.';
|
|
|
|
|
if (typeof result[i + 1] === 'number')
|
|
|
|
|
result[i][0] += result[i + 1];
|
|
|
|
|
else if (typeof
|
|
|
|
|
result[i][0] += '>';
|
|
|
|
|
}*/ else if (result[i].length > 1) {
|
|
|
|
|
else if (result[i].length > 1) {
|
|
|
|
|
// HEADER.FIELDS (foo) or HEADER.FIELDS (foo bar baz)
|
|
|
|
|
result[i][0] += ' (';
|
|
|
|
|
if (Array.isArray(result[i][1]))
|
|
|
|
@ -125,11 +104,11 @@ exports.parseFetchBodies = function(str, literals) {
|
|
|
|
|
|
|
|
|
|
exports.parseFetch = function(str, literals, fetchData) {
|
|
|
|
|
literals.lp = 0;
|
|
|
|
|
var result = exports.parseExpr(str, literals);
|
|
|
|
|
var result = exports.parseExpr(str, literals, false, 0, false);
|
|
|
|
|
for (var i = 0, len = result.length; i < len; i += 2) {
|
|
|
|
|
if (Array.isArray(result[i]))
|
|
|
|
|
continue;
|
|
|
|
|
result[i] = result[i].toUpperCase();
|
|
|
|
|
if (/^BODY\[/.test(result[i]))
|
|
|
|
|
continue;
|
|
|
|
|
if (result[i] === 'UID')
|
|
|
|
|
fetchData.uid = parseInt(result[i + 1], 10);
|
|
|
|
|
else if (result[i] === 'INTERNALDATE')
|
|
|
|
@ -325,10 +304,12 @@ exports.parseStructExtra = function(part, partLen, cur, next) {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.parseExpr = function(o, literals, result, start) {
|
|
|
|
|
exports.parseExpr = function(o, literals, result, start, useBrackets) {
|
|
|
|
|
start = start || 0;
|
|
|
|
|
var inQuote = false, lastPos = start - 1, isTop = false, inLitStart = false,
|
|
|
|
|
val;
|
|
|
|
|
if (useBrackets === undefined)
|
|
|
|
|
useBrackets = true;
|
|
|
|
|
if (!result)
|
|
|
|
|
result = [];
|
|
|
|
|
if (typeof o === 'string') {
|
|
|
|
@ -339,27 +320,21 @@ exports.parseExpr = function(o, literals, result, start) {
|
|
|
|
|
if (!inQuote) {
|
|
|
|
|
if (o.str[i] === '"')
|
|
|
|
|
inQuote = true;
|
|
|
|
|
else if (o.str[i] === ' ' || o.str[i] === ')' || o.str[i] === ']') {
|
|
|
|
|
else if (o.str[i] === ' ' || o.str[i] === ')'
|
|
|
|
|
|| (useBrackets && o.str[i] === ']')) {
|
|
|
|
|
if (i - (lastPos + 1) > 0) {
|
|
|
|
|
val = exports.convStr(o.str.substring(lastPos + 1, i), literals);
|
|
|
|
|
result.push(val);
|
|
|
|
|
}
|
|
|
|
|
if ((o.str[i] === ')' || o.str[i] === ']') && !isTop)
|
|
|
|
|
if ((o.str[i] === ')' || (useBrackets && o.str[i] === ']')) && !isTop)
|
|
|
|
|
return i;
|
|
|
|
|
lastPos = i;
|
|
|
|
|
} else if ((o.str[i] === '(' || o.str[i] === '[')) {
|
|
|
|
|
} else if ((o.str[i] === '(' || (useBrackets && o.str[i] === '['))) {
|
|
|
|
|
var innerResult = [];
|
|
|
|
|
i = exports.parseExpr(o, literals, innerResult, i + 1);
|
|
|
|
|
i = exports.parseExpr(o, literals, innerResult, i + 1, useBrackets);
|
|
|
|
|
lastPos = i;
|
|
|
|
|
result.push(innerResult);
|
|
|
|
|
}/* else if (i > 0 && o.str[i] === '<' && o.str[i - 1] === ']') {
|
|
|
|
|
lastPos = i;
|
|
|
|
|
inLitStart = true;
|
|
|
|
|
} else if (o.str[i] === '>' && inLitStart) {
|
|
|
|
|
val = exports.convStr(o.str.substring(lastPos + 1, i), literals);
|
|
|
|
|
result[result.length - 1].push(val);
|
|
|
|
|
inLitStart = false;
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
} else if (o.str[i] === '"' &&
|
|
|
|
|
(o.str[i - 1] &&
|
|
|
|
|
(o.str[i - 1] !== '\\'
|
|
|
|
|