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

imapflow

Package Overview
Dependencies
Maintainers
1
Versions
167
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imapflow - npm Package Compare versions

Comparing version 1.0.116 to 1.0.117

4

CHANGELOG.md
# CHANGELOG
- 1.0.117 - 2022-12-05
- Updated command compiling. The command compiler returns a Buffer, not a "binary" string.
- 1.0.116 - 2022-11-30

@@ -4,0 +8,0 @@

82

lib/handler/imap-compiler.js

@@ -7,2 +7,22 @@ /* eslint no-console: 0, new-cap: 0 */

const formatRespEntry = (entry, returnEmpty) => {
if (typeof entry === 'string') {
return Buffer.from(entry);
}
if (typeof entry === 'number') {
return Buffer.from(entry.toString());
}
if (Buffer.isBuffer(entry)) {
return entry;
}
if (returnEmpty) {
return null;
}
return Buffer.alloc(0);
};
/**

@@ -15,3 +35,3 @@ * Compiles an input object into

let resp = (response.tag || '') + (response.command ? ' ' + response.command : '');
let resp = [].concat(formatRespEntry(response.tag, true) || []).concat(response.command ? formatRespEntry(' ' + response.command) : []);
let val;

@@ -23,7 +43,13 @@ let lastType;

if (lastType === 'LITERAL' || (!['(', '<', '['].includes(resp.substr(-1)) && resp.length)) {
let lastRespEntry = resp.length && resp[resp.length - 1];
let lastRespByte = (lastRespEntry && lastRespEntry.length && lastRespEntry[lastRespEntry.length - 1]) || '';
if (typeof lastRespByte === 'number') {
lastRespByte = String.fromCharCode(lastRespByte);
}
if (lastType === 'LITERAL' || (!['(', '<', '['].includes(lastRespByte) && resp.length)) {
if (options.subArray) {
// ignore separator
} else {
resp += ' ';
resp.push(formatRespEntry(' '));
}

@@ -39,3 +65,3 @@ }

lastType = 'LIST';
resp += '(';
resp.push(formatRespEntry('('));

@@ -52,3 +78,3 @@ // check if we need to skip separtor WS between two arrays

resp += ')';
resp.push(formatRespEntry(')'));
return;

@@ -58,3 +84,3 @@ }

if (!node && typeof node !== 'string' && typeof node !== 'number' && !Buffer.isBuffer(node)) {
resp += 'NIL';
resp.push(formatRespEntry('NIL'));
return;

@@ -65,5 +91,5 @@ }

if (isLogging && node.length > 100) {
resp += '"(* ' + node.length + 'B string *)"';
resp.push(formatRespEntry('"(* ' + node.length + 'B string *)"'));
} else {
resp += JSON.stringify(node.toString('binary'));
resp.push(formatRespEntry(JSON.stringify(node.toString())));
}

@@ -74,3 +100,3 @@ return;

if (typeof node === 'number') {
resp += Math.round(node) || 0; // Only integers allowed
resp.push(formatRespEntry(Math.round(node) || 0)); // Only integers allowed
return;

@@ -82,3 +108,3 @@ }

if (isLogging && node.sensitive) {
resp += '"(* value hidden *)"';
resp.push(formatRespEntry('"(* value hidden *)"'));
return;

@@ -90,3 +116,3 @@ }

if (isLogging) {
resp += '"(* ' + node.value.length + 'B literal *)"';
resp.push(formatRespEntry('"(* ' + node.value.length + 'B literal *)"'));
} else {

@@ -98,9 +124,11 @@ let literalLength = !node.value ? 0 : Math.max(node.value.length, 0);

resp += `${node.isLiteral8 ? '~' : ''}{${literalLength}${usePlus ? '+' : ''}}\r\n`;
resp.push(formatRespEntry(`${node.isLiteral8 ? '~' : ''}{${literalLength}${usePlus ? '+' : ''}}\r\n`));
if (canAppend) {
resp += (node.value || '').toString('binary');
if (node.value && node.value.length) {
resp.push(formatRespEntry(node.value));
}
} else {
respParts.push(resp);
resp = (node.value || '').toString('binary');
resp = [].concat(formatRespEntry(node.value, true) || []);
}

@@ -112,5 +140,5 @@ }

if (isLogging && node.value.length > 100) {
resp += '"(* ' + node.value.length + 'B string *)"';
resp.push(formatRespEntry('"(* ' + node.value.length + 'B string *)"'));
} else {
resp += JSON.stringify(node.value || '');
resp.push(formatRespEntry(JSON.stringify((node.value || '').toString())));
}

@@ -121,7 +149,9 @@ break;

case 'SEQUENCE':
resp += (node.value || '').toString('binary');
if (node.value) {
resp.push(formatRespEntry(node.value));
}
break;
case 'NUMBER':
resp += node.value || 0;
resp.push(formatRespEntry(node.value || 0));
break;

@@ -131,3 +161,3 @@

case 'SECTION':
val = (node.value || '').toString('binary');
val = (node.value || '').toString();

@@ -139,7 +169,7 @@ if (!node.section || val) {

resp += val;
resp.push(formatRespEntry(val));
}
if (node.section) {
resp += '[';
resp.push(formatRespEntry('['));

@@ -150,6 +180,6 @@ for (let child of node.section) {

resp += ']';
resp.push(formatRespEntry(']'));
}
if (node.partial) {
resp += '<' + node.partial.join('.') + '>';
resp.push(formatRespEntry(`<${node.partial.join('.')}>`));
}

@@ -171,3 +201,7 @@ break;

return asArray ? respParts : respParts.join('');
for (let i = 0; i < respParts.length; i++) {
respParts[i] = Buffer.concat(respParts[i]);
}
return asArray ? respParts : respParts.flatMap(entry => entry);
};

@@ -106,3 +106,3 @@ /* eslint no-control-regex:0 */

return await compiler(response);
return (await compiler(response)).toString();
},

@@ -206,2 +206,3 @@

)
.toString()
.toLowerCase()

@@ -208,0 +209,0 @@ .replace(/<\d+>$/, '');

{
"name": "imapflow",
"version": "1.0.116",
"version": "1.0.117",
"description": "IMAP Client for Node",

@@ -36,3 +36,3 @@ "main": "./lib/imap-flow.js",

"braintree-jsdoc-template": "3.3.0",
"eslint": "8.28.0",
"eslint": "8.29.0",
"eslint-config-nodemailer": "1.2.0",

@@ -43,3 +43,3 @@ "eslint-config-prettier": "8.5.0",

"grunt-contrib-nodeunit": "4.0.0",
"grunt-eslint": "24.0.0",
"grunt-eslint": "24.0.1",
"jsdoc": "3.6.11",

@@ -46,0 +46,0 @@ "st": "3.0.0",

@@ -23,3 +23,3 @@ /*eslint no-unused-expressions: 0, prefer-arrow-callback: 0 */

});
const compiled = await compiler(parsed);
const compiled = (await compiler(parsed)).toString();
test.equal(compiled, command);

@@ -31,6 +31,8 @@ });

test.equal(
await compiler({
tag: '*',
command: 'CMD'
}),
(
await compiler({
tag: '*',
command: 'CMD'
})
).toString(),
'* CMD'

@@ -43,12 +45,14 @@ )

test.equal(
await compiler({
tag: '*',
command: 'CMD',
attributes: [
{
type: 'TEXT',
value: 'Tere tere!'
}
]
}),
(
await compiler({
tag: '*',
command: 'CMD',
attributes: [
{
type: 'TEXT',
value: 'Tere tere!'
}
]
})
).toString(),
'* CMD Tere tere!'

@@ -61,17 +65,19 @@ )

test.equal(
await compiler({
tag: '*',
command: 'CMD',
attributes: [
{
type: 'SECTION',
section: [
{
type: 'ATOM',
value: 'ALERT'
}
]
}
]
}),
(
await compiler({
tag: '*',
command: 'CMD',
attributes: [
{
type: 'SECTION',
section: [
{
type: 'ATOM',
value: 'ALERT'
}
]
}
]
})
).toString(),
'* CMD [ALERT]'

@@ -84,20 +90,22 @@ )

test.equal(
await compiler({
tag: '*',
command: 'CMD',
attributes: [
{
type: 'ATOM',
value: 'ALERT'
},
{
type: 'ATOM',
value: '\\ALERT'
},
{
type: 'ATOM',
value: 'NO ALERT'
}
]
}),
(
await compiler({
tag: '*',
command: 'CMD',
attributes: [
{
type: 'ATOM',
value: 'ALERT'
},
{
type: 'ATOM',
value: '\\ALERT'
},
{
type: 'ATOM',
value: 'NO ALERT'
}
]
})
).toString(),
'* CMD ALERT \\ALERT "NO ALERT"'

@@ -110,12 +118,14 @@ )

test.equal(
await compiler({
tag: '*',
command: 'CMD',
attributes: [
{
type: 'SEQUENCE',
value: '*:4,5,6'
}
]
}),
(
await compiler({
tag: '*',
command: 'CMD',
attributes: [
{
type: 'SEQUENCE',
value: '*:4,5,6'
}
]
})
).toString(),
'* CMD *:4,5,6'

@@ -128,7 +138,9 @@ )

test.equal(
await compiler({
tag: '*',
command: 'CMD',
attributes: [null, null]
}),
(
await compiler({
tag: '*',
command: 'CMD',
attributes: [null, null]
})
).toString(),
'* CMD NIL NIL'

@@ -141,23 +153,4 @@ )

test.equal(
await compiler({
tag: '*',
command: 'CMD',
attributes: [
{
type: 'String',
value: 'Tere tere!',
sensitive: true
},
'Vana kere'
]
}),
'* CMD "Tere tere!" "Vana kere"'
)
);
module.exports['IMAP Compiler: keep short strings'] = test =>
asyncWrapper(test, async test =>
test.equal(
await compiler(
{
(
await compiler({
tag: '*',

@@ -168,9 +161,9 @@ command: 'CMD',

type: 'String',
value: 'Tere tere!'
value: 'Tere tere!',
sensitive: true
},
'Vana kere'
]
},
{ asArray: false, isLogging: true }
),
})
).toString(),
'* CMD "Tere tere!" "Vana kere"'

@@ -180,20 +173,45 @@ )

module.exports['IMAP Compiler: keep short strings'] = test =>
asyncWrapper(test, async test =>
test.equal(
(
await compiler(
{
tag: '*',
command: 'CMD',
attributes: [
{
type: 'String',
value: 'Tere tere!'
},
'Vana kere'
]
},
{ asArray: false, isLogging: true }
)
).toString(),
'* CMD "Tere tere!" "Vana kere"'
)
);
module.exports['IMAP Compiler: hide sensitive strings'] = test =>
asyncWrapper(test, async test =>
test.equal(
await compiler(
{
tag: '*',
command: 'CMD',
attributes: [
{
type: 'String',
value: 'Tere tere!',
sensitive: true
},
'Vana kere'
]
},
{ asArray: false, isLogging: true }
),
(
await compiler(
{
tag: '*',
command: 'CMD',
attributes: [
{
type: 'String',
value: 'Tere tere!',
sensitive: true
},
'Vana kere'
]
},
{ asArray: false, isLogging: true }
)
).toString(),
'* CMD "(* value hidden *)" "Vana kere"'

@@ -206,16 +224,18 @@ )

test.equal(
await compiler(
{
tag: '*',
command: 'CMD',
attributes: [
{
type: 'String',
value: 'Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere!'
},
'Vana kere'
]
},
{ asArray: false, isLogging: true }
),
(
await compiler(
{
tag: '*',
command: 'CMD',
attributes: [
{
type: 'String',
value: 'Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere! Tere tere!'
},
'Vana kere'
]
},
{ asArray: false, isLogging: true }
)
).toString(),
'* CMD "(* 219B string *)" "Vana kere"'

@@ -228,12 +248,14 @@ )

test.equal(
await compiler({
tag: '*',
attributes: [
1,
{
type: 'ATOM',
value: 'EXPUNGE'
}
]
}),
(
await compiler({
tag: '*',
attributes: [
1,
{
type: 'ATOM',
value: 'EXPUNGE'
}
]
})
).toString(),
'* 1 EXPUNGE'

@@ -246,14 +268,16 @@ )

test.equal(
await compiler({
tag: '*',
command: 'CMD',
attributes: [
// keep indentation
{
type: 'LITERAL',
value: 'Tere tere!'
},
'Vana kere'
]
}),
(
await compiler({
tag: '*',
command: 'CMD',
attributes: [
// keep indentation
{
type: 'LITERAL',
value: 'Tere tere!'
},
'Vana kere'
]
})
).toString(),
'* CMD {10}\r\nTere tere! "Vana kere"'

@@ -266,15 +290,17 @@ )

test.equal(
await compiler({
tag: '*',
command: 'CMD',
attributes: [
// keep indentation
{
type: 'LITERAL',
value: 'Tere\x00 tere!',
isLiteral8: false
},
'Vana kere'
]
}),
(
await compiler({
tag: '*',
command: 'CMD',
attributes: [
// keep indentation
{
type: 'LITERAL',
value: 'Tere\x00 tere!',
isLiteral8: false
},
'Vana kere'
]
})
).toString(),
'* CMD {11}\r\nTere\x00 tere! "Vana kere"'

@@ -287,15 +313,17 @@ )

test.equal(
await compiler({
tag: '*',
command: 'CMD',
attributes: [
// keep indentation
{
type: 'LITERAL',
value: 'Tere\x00 tere!',
isLiteral8: true
},
'Vana kere'
]
}),
(
await compiler({
tag: '*',
command: 'CMD',
attributes: [
// keep indentation
{
type: 'LITERAL',
value: 'Tere\x00 tere!',
isLiteral8: true
},
'Vana kere'
]
})
).toString(),
'* CMD ~{11}\r\nTere\x00 tere! "Vana kere"'

@@ -308,19 +336,21 @@ )

test.deepEqual(
await compiler(
{
tag: '*',
command: 'CMD',
attributes: [
{
type: 'LITERAL',
value: 'Tere tere!'
},
{
type: 'LITERAL',
value: 'Vana kere'
}
]
},
{ asArray: true }
),
(
await compiler(
{
tag: '*',
command: 'CMD',
attributes: [
{
type: 'LITERAL',
value: 'Tere tere!'
},
{
type: 'LITERAL',
value: 'Vana kere'
}
]
},
{ asArray: true }
)
).map(entry => entry.toString()),
['* CMD {10}\r\n', 'Tere tere! {9}\r\n', 'Vana kere']

@@ -333,20 +363,22 @@ )

test.deepEqual(
await compiler(
{
tag: '*',
command: 'CMD',
attributes: [
{
type: 'LITERAL',
value: 'Tere tere!'
},
{
type: 'LITERAL',
value: 'Vana kere'
},
'zzz'
]
},
{ asArray: true }
),
(
await compiler(
{
tag: '*',
command: 'CMD',
attributes: [
{
type: 'LITERAL',
value: 'Tere tere!'
},
{
type: 'LITERAL',
value: 'Vana kere'
},
'zzz'
]
},
{ asArray: true }
)
).map(entry => entry.toString()),
['* CMD {10}\r\n', 'Tere tere! {9}\r\n', 'Vana kere "zzz"']

@@ -359,20 +391,22 @@ )

test.deepEqual(
await compiler(
{
tag: '*',
command: 'CMD',
attributes: [
{
type: 'LITERAL',
value: 'Tere tere!'
},
{
type: 'LITERAL',
value: 'Vana kere'
},
'zzz'
]
},
{ asArray: true, literalPlus: true }
),
(
await compiler(
{
tag: '*',
command: 'CMD',
attributes: [
{
type: 'LITERAL',
value: 'Tere tere!'
},
{
type: 'LITERAL',
value: 'Vana kere'
},
'zzz'
]
},
{ asArray: true, literalPlus: true }
)
).map(entry => entry.toString()),
['* CMD {10+}\r\nTere tere! {9+}\r\nVana kere "zzz"']

@@ -385,17 +419,19 @@ )

test.deepEqual(
await compiler(
{
attributes: [
{
type: 'LITERAL',
value: 'Tere tere!'
},
{
type: 'LITERAL',
value: 'Vana kere'
}
]
},
{ asArray: true }
),
(
await compiler(
{
attributes: [
{
type: 'LITERAL',
value: 'Tere tere!'
},
{
type: 'LITERAL',
value: 'Vana kere'
}
]
},
{ asArray: true }
)
).map(entry => entry.toString()),
['{10}\r\n', 'Tere tere! {9}\r\n', 'Vana kere']

@@ -408,18 +444,20 @@ )

test.deepEqual(
await compiler(
{
tag: '*',
command: 'CMD',
attributes: [
{
type: 'LITERAL',
value: 'Tere tere!'
},
'Vana kere'
]
},
{ asArray: false, isLogging: true }
),
(
await compiler(
{
tag: '*',
command: 'CMD',
attributes: [
{
type: 'LITERAL',
value: 'Tere tere!'
},
'Vana kere'
]
},
{ asArray: false, isLogging: true }
)
).toString(),
'* CMD "(* 10B literal *)" "Vana kere"'
)
);

Sorry, the diff of this file is too big to display

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