Skip to content

Fixes #147 #148

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

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 4 additions & 1 deletion src/emailjs-imap-client-imap.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

// As the server sends data in chunks, it needs to be split into separate lines. Helps parsing the input.
this._incomingBuffers = [];
this._literalFound = false;
this._literalRemaining = 0;

//
Expand Down Expand Up @@ -448,6 +449,7 @@
buf[j+2] === LINE_FEED) {
const numBuf = buf.subarray(leftIdx+1, j);
this._literalRemaining = Number(mimecodec.fromTypedArray(numBuf));
this._literalFound = true;
i = j + 3;
} else {
i = j;
Expand All @@ -458,10 +460,11 @@
}

const diff = Math.min(buf.length-i, this._literalRemaining);
if (diff) {
if (diff || this._literalFound) {
this._literalRemaining -= diff;
i += diff;
if (this._literalRemaining === 0) {
this._literalFound = false;
continue; // find another literal
}
}
Expand Down
6 changes: 6 additions & 0 deletions test/unit/emailjs-imap-client-imap-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@
});

describe('#_iterateIncomingBuffer', () => {
it('Parse multiple zero-length literals', () => {
appendIncomingBuffer('* 126015 FETCH (UID 585599 BODY[1.2] {0}\r\n BODY[1.1] {0}\r\n)\r\n');
var iterator = client._iterateIncomingBuffer();
expect(String.fromCharCode.apply(null, iterator.next().value)).to.equal ('* 126015 FETCH (UID 585599 BODY[1.2] {0}\r\n BODY[1.1] {0}\r\n)');
});

it('should iterate chunked input', () => {
appendIncomingBuffer('* 1 FETCH (UID 1)\r\n* 2 FETCH (UID 2)\r\n* 3 FETCH (UID 3)\r\n');
var iterator = client._iterateIncomingBuffer();
Expand Down