diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..3c3629e6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/lib/Connection.js b/lib/Connection.js index 57b83384..909d1028 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -45,7 +45,8 @@ var MAX_INT = 9007199254740992, RE_BACKSLASH = /\\/g, RE_DBLQUOTE = /"/g, RE_ESCAPE = /\\\\/g, - RE_INTEGER = /^\d+$/; + RE_INTEGER = /^\d+$/, + RE_PARTIAL_BODY = /^([A-Za-z]+)(<[0-9]+\.[0-9]+>)$/; function Connection(config) { if (!(this instanceof Connection)) @@ -820,8 +821,15 @@ Connection.prototype._fetch = function(which, uids, options) { if (!Array.isArray(bodies)) bodies = [bodies]; for (i = 0, len = bodies.length; i < len; ++i) { + var suffix = ''; + var parts = bodies[i].match(RE_PARTIAL_BODY); + if (parts) { + suffix = parts[2]; + bodies[i] = parts[1]; + } + fetching.push(parseExpr(''+bodies[i])); - cmd += ' BODY' + prefix + '[' + bodies[i] + ']'; + cmd += ' BODY' + prefix + '[' + bodies[i] + ']' + suffix; } } } else diff --git a/lib/Parser.js b/lib/Parser.js index d6d673e8..6c4f4907 100644 --- a/lib/Parser.js +++ b/lib/Parser.js @@ -12,7 +12,7 @@ var CH_LF = 10, EMPTY_READCB = function(n) {}, RE_INTEGER = /^\d+$/, RE_PRECEDING = /^(?:(?:\*|A\d+) )|\+ ?/, - RE_BODYLITERAL = /BODY\[(.*)\] \{(\d+)\}$/i, + RE_BODYLITERAL = /BODY\[(.*)\](<[0-9]+>)* \{(\d+)\}$/i, RE_BODYINLINEKEY = /^BODY\[(.*)\]$/i, RE_SEQNO = /^\* (\d+)/, RE_LISTCONTENT = /^\((.*)\)$/, @@ -186,7 +186,7 @@ Parser.prototype._resUntagged = function() { var m; if (m = RE_BODYLITERAL.exec(this._buffer)) { // BODY literal -- stream it - var which = m[1], size = parseInt(m[2], 10); + var which = m[1], size = parseInt(m[3], 10); this._literallen = size; this._body = new ReadableStream(); this._body._readableState.sync = false; @@ -889,7 +889,7 @@ function decodeWords(str, state) { state.replaces = []; var bytes, m, next, i, j, leni, lenj, seq, replaces = [], lastReplace = {}; - + // join consecutive q-encoded words that have the same charset first while (m = RE_ENCWORD.exec(str)) { seq = {