|
|
|
@ -15,7 +15,9 @@ var CH_LF = 10,
|
|
|
|
|
RE_LITERAL = /\{(\d+)\}$/,
|
|
|
|
|
RE_UNTAGGED = /^\* (?:(OK|NO|BAD|BYE|FLAGS|LIST|LSUB|SEARCH|STATUS|CAPABILITY|NAMESPACE|PREAUTH|SORT)|(\d+) (EXPUNGE|FETCH|RECENT|EXISTS))(?: (?:\[([^\]]+)\] )?(.+))?$/i,
|
|
|
|
|
RE_TAGGED = /^A(\d+) (OK|NO|BAD) (?:\[([^\]]+)\] )?(.+)$/i,
|
|
|
|
|
RE_CONTINUE = /^\+ (?:\[([^\]]+)\] )?(.+)$/i;
|
|
|
|
|
RE_CONTINUE = /^\+ (?:\[([^\]]+)\] )?(.+)$/i,
|
|
|
|
|
RE_CRLF = /\r\n/g,
|
|
|
|
|
RE_HDR = /^([^:]+):[ \t]?(.+)?$/;
|
|
|
|
|
|
|
|
|
|
function Parser(stream, debug) {
|
|
|
|
|
if (!(this instanceof Parser))
|
|
|
|
@ -576,7 +578,42 @@ function convStr(str, literals) {
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseHeader(str) {
|
|
|
|
|
var lines = str.split(RE_CRLF),
|
|
|
|
|
len = lines.length,
|
|
|
|
|
modded = false,
|
|
|
|
|
header = {},
|
|
|
|
|
m, h;
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < len; ++i) {
|
|
|
|
|
if (lines[i].length === 0)
|
|
|
|
|
continue;
|
|
|
|
|
if (lines[i][0] === '\t' || lines[i][0] === ' ') {
|
|
|
|
|
// folded header content
|
|
|
|
|
// RFC2822 says to just remove the CRLF and not the whitespace following
|
|
|
|
|
// it, so we follow the RFC and include the leading whitespace ...
|
|
|
|
|
header[h][header[h].length - 1] += lines[i];
|
|
|
|
|
} else {
|
|
|
|
|
m = RE_HDR.exec(lines[i]);
|
|
|
|
|
if (m) {
|
|
|
|
|
h = m[1].toLowerCase();
|
|
|
|
|
if (m[2]) {
|
|
|
|
|
if (header[h] === undefined)
|
|
|
|
|
header[h] = [m[2]];
|
|
|
|
|
else
|
|
|
|
|
header[h].push(m[2]);
|
|
|
|
|
} else
|
|
|
|
|
header[h] = [''];
|
|
|
|
|
} else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return header;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exports.Parser = Parser;
|
|
|
|
|
exports.parseExpr = parseExpr;
|
|
|
|
|
exports.parseEnvelopeAddresses = parseEnvelopeAddresses;
|
|
|
|
|
exports.parseBodyStructure = parseBodyStructure;
|
|
|
|
|
exports.parseHeader = parseHeader;
|
|
|
|
|