Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial bodies #480

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
12 changes: 10 additions & 2 deletions lib/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The * operator in this change isn't correct I think. There is only ever one set of < and >. It should instead be a ? to make it optional.

RE_BODYINLINEKEY = /^BODY\[(.*)\]$/i,
RE_SEQNO = /^\* (\d+)/,
RE_LISTCONTENT = /^\((.*)\)$/,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down