Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

emailjs-imap-client

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emailjs-imap-client - npm Package Compare versions

Comparing version 2.0.6-beta.1 to 2.0.6-beta.2

2

package.json
{
"name": "emailjs-imap-client",
"version": "2.0.6-beta.1",
"version": "2.0.6-beta.2",
"homepage": "https://github.com/emailjs/emailjs-imap-client",

@@ -5,0 +5,0 @@ "description": "JavaScript IMAP client",

@@ -23,2 +23,3 @@ (function(root, factory) {

var LINE_FEED = 10;
var CARRIAGE_RETURN = 13;
var LEFT_CURLY_BRACKET = 123;

@@ -404,3 +405,15 @@ var RIGHT_CURLY_BRACKET = 125;

Imap.prototype._iterateIncomingBuffer = function*() {
let buf = this._incomingBuffers[this._incomingBuffers.length-1];
let buf;
if (this._concatLastTwoBuffers) {
// allocate new buffer for the sake of simpler parsing
delete this._concatLastTwoBuffers;
const latest = this._incomingBuffers.pop();
const prevBuf = this._incomingBuffers[this._incomingBuffers.length-1];
buf = new Uint8Array(prevBuf.length + latest.length);
buf.set(prevBuf);
buf.set(latest, prevBuf.length);
this._incomingBuffers[this._incomingBuffers.length-1] = buf;
} else {
buf = this._incomingBuffers[this._incomingBuffers.length-1];
}
let i = 0;

@@ -414,41 +427,28 @@

if (this._literalRemaining === 0) {
let numBuf;
if (this._numBuf) {
const rightIdx = buf.indexOf(RIGHT_CURLY_BRACKET, i);
const end = rightIdx > -1 ? rightIdx : buf.length;
const tmpNum = new Uint8Array(this._numBuf.length + end-i);
tmpNum.set(this._numBuf, 0);
tmpNum.set(buf.subarray(i, end), this._numBuf.length);
if (rightIdx > -1) {
delete this._numBuf;
numBuf = tmpNum;
i = rightIdx + 1;
} else {
this._numBuf = tmpNum;
return;
}
} else {
const leftIdx = buf.indexOf(LEFT_CURLY_BRACKET, i);
if (leftIdx > -1) {
const leftOfLeftCurly = new Uint8Array(buf.buffer, i, leftIdx-i);
if (leftOfLeftCurly.indexOf(LINE_FEED) === -1) {
const rightIdx = buf.indexOf(RIGHT_CURLY_BRACKET, leftIdx+2);
if (rightIdx > -1) {
numBuf = new Uint8Array(buf.buffer, leftIdx+1, rightIdx-leftIdx-1);
i = rightIdx + 1;
} else {
this._numBuf = new Uint8Array(buf.buffer, leftIdx+1);
return;
}
const leftIdx = buf.indexOf(LEFT_CURLY_BRACKET, i);
if (leftIdx > -1) {
const leftOfLeftCurly = new Uint8Array(buf.buffer, i, leftIdx-i);
if (leftOfLeftCurly.indexOf(LINE_FEED) === -1) {
let j = leftIdx + 1;
while (buf[j] >= 48 && buf[j] <= 57) { // digits
j++;
}
if (j >= buf.length-1) {
// not enough info to determine if this is literal length
this._concatLastTwoBuffers = true;
return;
}
if (j > leftIdx + 1 &&
buf[j] === RIGHT_CURLY_BRACKET &&
buf[j+1] === CARRIAGE_RETURN &&
buf[j+2] === LINE_FEED) {
const numBuf = buf.subarray(leftIdx+1, j);
this._literalRemaining = Number(mimecodec.fromTypedArray(numBuf));
i = j + 3;
} else {
i = j;
continue; // not a literal but there might still be one
}
}
}
if (numBuf) {
const remaining = Number(mimecodec.fromTypedArray(numBuf))+2; // 2 for CRLF
if (isNaN(remaining)) {
throw Error("error parsing literal length");
} else {
this._literalRemaining = remaining;
}
}
}

@@ -465,3 +465,3 @@

if (!this._numBuf && this._literalRemaining === 0 && i < buf.length) {
if (this._literalRemaining === 0 && i < buf.length) {
const LFidx = buf.indexOf(LINE_FEED, i);

@@ -468,0 +468,0 @@ if (LFidx > -1) {

@@ -145,3 +145,3 @@ 'use strict';

it('chould process chunked literals', () => {
it('should process chunked literals', () => {
appendIncomingBuffer('* 1 FETCH (UID {1}\r\n1)\r\n* 2 FETCH (UID {4}\r\n2345)\r\n* 3 FETCH (UID {4}\r\n3789)\r\n');

@@ -156,3 +156,3 @@ var iterator = client._iterateIncomingBuffer();

it('chould process chunked literals 2', () => {
it('should process chunked literals 2', () => {
appendIncomingBuffer('* 1 FETCH (UID 1)\r\n* 2 FETCH (UID {4}\r\n2345)\r\n');

@@ -166,3 +166,3 @@ var iterator = client._iterateIncomingBuffer();

it('chould process chunked literals 3', () => {
it('should process chunked literals 3', () => {
appendIncomingBuffer('* 1 FETCH (UID {1}\r\n1)\r\n* 2 FETCH (UID 4)\r\n');

@@ -176,3 +176,3 @@ var iterator = client._iterateIncomingBuffer();

it('chould process chunked literals 4', () => {
it('should process chunked literals 4', () => {
appendIncomingBuffer('* SEARCH {1}\r\n1 {1}\r\n2\r\n');

@@ -183,2 +183,14 @@ var iterator = client._iterateIncomingBuffer();

it('should process CRLF literal', () => {
appendIncomingBuffer('* 1 FETCH (UID 20 BODY[HEADER.FIELDS (REFERENCES LIST-ID)] {2}\r\n\r\n)\r\n');
var iterator = client._iterateIncomingBuffer();
expect(iterator.next().value).to.equal('* 1 FETCH (UID 20 BODY[HEADER.FIELDS (REFERENCES LIST-ID)] {2}\r\n\r\n)');
});
it('should process CRLF literal 2', () => {
appendIncomingBuffer('* 1 FETCH (UID 1 ENVELOPE ("string with {parenthesis}") BODY[HEADER.FIELDS (REFERENCES LIST-ID)] {2}\r\n\r\n)\r\n');
var iterator = client._iterateIncomingBuffer();
expect(iterator.next().value).to.equal('* 1 FETCH (UID 1 ENVELOPE ("string with {parenthesis}") BODY[HEADER.FIELDS (REFERENCES LIST-ID)] {2}\r\n\r\n)');
});
it('should process two commands when CRLF arrives in 2 parts', () => {

@@ -255,2 +267,14 @@ appendIncomingBuffer('* 1 FETCH (UID 1)\r');

it('should not process {} in string as literal 1', () => {
appendIncomingBuffer('* 1 FETCH (UID 1 ENVELOPE ("string with {parenthesis}"))\r\n');
var iterator = client._iterateIncomingBuffer();
expect(iterator.next().value).to.equal('* 1 FETCH (UID 1 ENVELOPE ("string with {parenthesis}"))');
});
it('should not process {} in string as literal 2', () => {
appendIncomingBuffer('* 1 FETCH (UID 1 ENVELOPE ("string with number in parenthesis {123}"))\r\n');
var iterator = client._iterateIncomingBuffer();
expect(iterator.next().value).to.equal('* 1 FETCH (UID 1 ENVELOPE ("string with number in parenthesis {123}"))');
});
function appendIncomingBuffer(content) {

@@ -257,0 +281,0 @@ client._incomingBuffers.push(mimefuncs.toTypedArray(content));

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc