From e2c7cdd32f1067c850ee985d36b98db0f34a0e54 Mon Sep 17 00:00:00 2001 From: mscdex Date: Mon, 1 Jul 2013 04:11:31 -0400 Subject: [PATCH] Parser: add 'hack' to properly take care of non-literal BODY[*] --- lib/Parser.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/Parser.js b/lib/Parser.js index e8ecac5..a98a1cf 100644 --- a/lib/Parser.js +++ b/lib/Parser.js @@ -579,7 +579,7 @@ function parseEnvelopeAddresses(list) { function parseExpr(o, literals, result, start, useBrackets) { start = start || 0; - var inQuote = false, lastPos = start - 1, isTop = false, val; + var inQuote = false, lastPos = start - 1, isTop = false, val, isBody = false; if (useBrackets === undefined) useBrackets = true; @@ -591,7 +591,14 @@ function parseExpr(o, literals, result, start, useBrackets) { } for (var i = start, len = o.str.length; i < len; ++i) { if (!inQuote) { - if (o.str[i] === '"') + if (isBody) { + if (o.str[i] === ']') { + val = convStr(o.str.substring(lastPos + 1, i + 1), literals); + result.push(val); + lastPos = i; + isBody = false; + } + } else if (o.str[i] === '"') inQuote = true; else if (o.str[i] === ' ' || o.str[i] === ')' || (useBrackets && o.str[i] === ']')) { @@ -603,10 +610,17 @@ function parseExpr(o, literals, result, start, useBrackets) { return i; lastPos = i; } else if ((o.str[i] === '(' || (useBrackets && o.str[i] === '['))) { - var innerResult = []; - i = parseExpr(o, literals, innerResult, i + 1, useBrackets); - lastPos = i; - result.push(innerResult); + if (o.str[i] === '[' + && i - 4 >= start + && o.str.substring(i - 4, i).toUpperCase() === 'BODY') { + isBody = true; + lastPos = i - 5; + } else { + var innerResult = []; + i = parseExpr(o, literals, innerResult, i + 1, useBrackets); + lastPos = i; + result.push(innerResult); + } } } else if (o.str[i] === '"' && (o.str[i - 1] &&