imapflow 2.2.6 → 2.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/cjs/commands/append.js +10 -3
- package/dist/cjs/commands/authenticate.js +42 -22
- package/dist/cjs/commands/close.d.ts +12 -1
- package/dist/cjs/commands/close.js +4 -2
- package/dist/cjs/commands/delete.js +2 -1
- package/dist/cjs/commands/enable.js +6 -0
- package/dist/cjs/commands/esearch-parser.js +8 -2
- package/dist/cjs/commands/fetch.js +57 -14
- package/dist/cjs/commands/id.js +8 -1
- package/dist/cjs/commands/idle.js +15 -5
- package/dist/cjs/commands/list.js +10 -1
- package/dist/cjs/commands/login.js +5 -1
- package/dist/cjs/commands/logout.js +7 -0
- package/dist/cjs/commands/namespace.js +7 -3
- package/dist/cjs/commands/quota.js +3 -1
- package/dist/cjs/commands/rename.js +2 -1
- package/dist/cjs/commands/select.js +5 -0
- package/dist/cjs/commands/status.js +6 -1
- package/dist/cjs/commands/store.d.ts +1 -1
- package/dist/cjs/commands/store.js +8 -8
- package/dist/cjs/download.js +220 -95
- package/dist/cjs/handler/imap-compiler.js +19 -10
- package/dist/cjs/handler/limits.d.ts +11 -0
- package/dist/cjs/handler/limits.js +16 -1
- package/dist/cjs/handler/parser-instance.d.ts +10 -0
- package/dist/cjs/handler/parser-instance.js +25 -10
- package/dist/cjs/handler/token-parser.js +36 -28
- package/dist/cjs/imap-flow.d.ts +2 -2
- package/dist/cjs/imap-flow.js +256 -95
- package/dist/cjs/package-info.d.ts +1 -1
- package/dist/cjs/package-info.js +1 -1
- package/dist/cjs/proxy-connection.js +7 -7
- package/dist/cjs/search-compiler.js +33 -13
- package/dist/cjs/special-use.js +10 -5
- package/dist/cjs/tools.d.ts +14 -4
- package/dist/cjs/tools.js +69 -9
- package/dist/cjs/types.d.ts +19 -4
- package/dist/esm/commands/append.js +11 -4
- package/dist/esm/commands/authenticate.js +43 -23
- package/dist/esm/commands/close.d.ts +12 -1
- package/dist/esm/commands/close.js +5 -3
- package/dist/esm/commands/delete.js +2 -1
- package/dist/esm/commands/enable.js +6 -0
- package/dist/esm/commands/esearch-parser.js +8 -2
- package/dist/esm/commands/fetch.js +57 -14
- package/dist/esm/commands/id.js +9 -2
- package/dist/esm/commands/idle.js +16 -6
- package/dist/esm/commands/list.js +10 -1
- package/dist/esm/commands/login.js +6 -2
- package/dist/esm/commands/logout.js +7 -0
- package/dist/esm/commands/namespace.js +7 -3
- package/dist/esm/commands/quota.js +3 -1
- package/dist/esm/commands/rename.js +2 -1
- package/dist/esm/commands/select.js +5 -0
- package/dist/esm/commands/status.js +7 -2
- package/dist/esm/commands/store.d.ts +1 -1
- package/dist/esm/commands/store.js +9 -9
- package/dist/esm/download.js +220 -95
- package/dist/esm/handler/imap-compiler.js +19 -10
- package/dist/esm/handler/limits.d.ts +11 -0
- package/dist/esm/handler/limits.js +14 -0
- package/dist/esm/handler/parser-instance.d.ts +10 -0
- package/dist/esm/handler/parser-instance.js +25 -10
- package/dist/esm/handler/token-parser.js +37 -29
- package/dist/esm/imap-flow.d.ts +2 -2
- package/dist/esm/imap-flow.js +256 -95
- package/dist/esm/package-info.d.ts +1 -1
- package/dist/esm/package-info.js +1 -1
- package/dist/esm/proxy-connection.js +7 -7
- package/dist/esm/search-compiler.js +33 -13
- package/dist/esm/special-use.js +10 -5
- package/dist/esm/tools.d.ts +14 -4
- package/dist/esm/tools.js +68 -9
- package/dist/esm/types.d.ts +19 -4
- package/package.json +5 -3
|
@@ -73,7 +73,7 @@ class TokenParser {
|
|
|
73
73
|
if (!node.isClosed) {
|
|
74
74
|
let error = new Error(`Unexpected end of input at position ${this.pos + this.str.length - 1} [E9]`);
|
|
75
75
|
error.code = 'ParserError9';
|
|
76
|
-
error.parserContext = {
|
|
76
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + this.str.length - 1 };
|
|
77
77
|
throw error;
|
|
78
78
|
}
|
|
79
79
|
let type = (node.type || '').toString().toUpperCase();
|
|
@@ -147,7 +147,8 @@ class TokenParser {
|
|
|
147
147
|
if (node.depth > MAX_NODE_DEPTH) {
|
|
148
148
|
let error = new Error('Too much nesting in IMAP string');
|
|
149
149
|
error.code = 'MAX_IMAP_NESTING_REACHED';
|
|
150
|
-
error
|
|
150
|
+
// A bounded prefix only, the error travels whole into logs and rejections
|
|
151
|
+
error._imapStr = this.str.slice(0, limits_js_1.ERROR_CONTEXT_LENGTH);
|
|
151
152
|
throw error;
|
|
152
153
|
}
|
|
153
154
|
if (typeof startPos === 'number') {
|
|
@@ -226,7 +227,7 @@ class TokenParser {
|
|
|
226
227
|
if (!literals.length) {
|
|
227
228
|
let error = new Error(`Literal without data at position ${this.pos + i} [E35]`);
|
|
228
229
|
error.code = 'ParserError35';
|
|
229
|
-
error.parserContext = {
|
|
230
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
230
231
|
throw error;
|
|
231
232
|
}
|
|
232
233
|
return literals.shift();
|
|
@@ -241,7 +242,7 @@ class TokenParser {
|
|
|
241
242
|
if (!imap_formal_syntax_js_1.default['ATOM-CHAR']().includes(chr) && chr !== '\\' && chr !== '%' && chr.charCodeAt(0) < 0x80) {
|
|
242
243
|
let error = new Error(`Unexpected char at position ${this.pos + i} [E13: ${JSON.stringify(chr)}]`);
|
|
243
244
|
error.code = 'ParserError13';
|
|
244
|
-
error.parserContext = {
|
|
245
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
245
246
|
throw error;
|
|
246
247
|
}
|
|
247
248
|
this.currentNode = this.createNode(this.currentNode, this.pos + i);
|
|
@@ -272,7 +273,7 @@ class TokenParser {
|
|
|
272
273
|
if (this.currentNode.type !== 'LIST') {
|
|
273
274
|
let error = new Error(`Unexpected list terminator ) at position ${this.pos + i} [E10]`);
|
|
274
275
|
error.code = 'ParserError10';
|
|
275
|
-
error.parserContext = {
|
|
276
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
276
277
|
throw error;
|
|
277
278
|
}
|
|
278
279
|
this.currentNode.isClosed = true;
|
|
@@ -285,7 +286,7 @@ class TokenParser {
|
|
|
285
286
|
if (this.currentNode.type !== 'SECTION') {
|
|
286
287
|
let error = new Error(`Unexpected section terminator ] at position ${this.pos + i} [E11]`);
|
|
287
288
|
error.code = 'ParserError11';
|
|
288
|
-
error.parserContext = {
|
|
289
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
289
290
|
throw error;
|
|
290
291
|
}
|
|
291
292
|
this.currentNode.isClosed = true;
|
|
@@ -329,7 +330,7 @@ class TokenParser {
|
|
|
329
330
|
}
|
|
330
331
|
let error = new Error(`Unexpected literal8 marker at position ${this.pos + i} [E12]`);
|
|
331
332
|
error.code = 'ParserError12';
|
|
332
|
-
error.parserContext = {
|
|
333
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
333
334
|
throw error;
|
|
334
335
|
}
|
|
335
336
|
// Mark the next literal as literal8 type; consumed when '{' is encountered
|
|
@@ -489,16 +490,16 @@ class TokenParser {
|
|
|
489
490
|
chr.charCodeAt(0) < 0x80 && // allow 8bit (presumably unicode) bytes
|
|
490
491
|
chr !== ']' &&
|
|
491
492
|
!(chr === '*' && this.currentNode.value === '\\') &&
|
|
492
|
-
(!this.parent || !this.parent.command || !['NO', 'BAD', 'OK'].includes(this.parent.command))) {
|
|
493
|
+
(!this.parent || !this.parent.command || !['NO', 'BAD', 'OK'].includes(this.parent.command.toUpperCase()))) {
|
|
493
494
|
let error = new Error(`Unexpected char at position ${this.pos + i} [E16: ${JSON.stringify(chr)}]`);
|
|
494
495
|
error.code = 'ParserError16';
|
|
495
|
-
error.parserContext = {
|
|
496
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
496
497
|
throw error;
|
|
497
498
|
}
|
|
498
499
|
else if (this.currentNode.value === '\\*') {
|
|
499
500
|
let error = new Error(`Unexpected char at position ${this.pos + i} [E17: ${JSON.stringify(chr)}]`);
|
|
500
501
|
error.code = 'ParserError17';
|
|
501
|
-
error.parserContext = {
|
|
502
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
502
503
|
throw error;
|
|
503
504
|
}
|
|
504
505
|
appendToToken(chr);
|
|
@@ -519,7 +520,7 @@ class TokenParser {
|
|
|
519
520
|
if (i >= len) {
|
|
520
521
|
let error = new Error(`Unexpected end of input at position ${this.pos + i} [E18]`);
|
|
521
522
|
error.code = 'ParserError18';
|
|
522
|
-
error.parserContext = {
|
|
523
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i };
|
|
523
524
|
throw error;
|
|
524
525
|
}
|
|
525
526
|
chr = this.str.charAt(i);
|
|
@@ -531,7 +532,7 @@ class TokenParser {
|
|
|
531
532
|
if (tokenLast === '.') {
|
|
532
533
|
let error = new Error(`Unexpected end of partial at position ${this.pos + i} [E19]`);
|
|
533
534
|
error.code = 'ParserError19';
|
|
534
|
-
error.parserContext = {
|
|
535
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
535
536
|
throw error;
|
|
536
537
|
}
|
|
537
538
|
this.currentNode.endPos = this.pos + i;
|
|
@@ -544,19 +545,19 @@ class TokenParser {
|
|
|
544
545
|
if (chr === '.' && (!tokenLength || tokenHasDot)) {
|
|
545
546
|
let error = new Error(`Unexpected partial separator . at position ${this.pos + i} [E20]`);
|
|
546
547
|
error.code = 'ParserError20';
|
|
547
|
-
error.parserContext = {
|
|
548
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
548
549
|
throw error;
|
|
549
550
|
}
|
|
550
551
|
if (!imap_formal_syntax_js_1.default.DIGIT().includes(chr) && chr !== '.') {
|
|
551
552
|
let error = new Error(`Unexpected char at position ${this.pos + i} [E21: ${JSON.stringify(chr)}]`);
|
|
552
553
|
error.code = 'ParserError21';
|
|
553
|
-
error.parserContext = {
|
|
554
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
554
555
|
throw error;
|
|
555
556
|
}
|
|
556
557
|
if (tokenLast === '0' && (tokenLength === 1 || tokenPrev === '.') && chr !== '.') {
|
|
557
558
|
let error = new Error(`Invalid partial at position ${this.pos + i} [E22: ${JSON.stringify(chr)}]`);
|
|
558
559
|
error.code = 'ParserError22';
|
|
559
|
-
error.parserContext = {
|
|
560
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
560
561
|
throw error;
|
|
561
562
|
}
|
|
562
563
|
appendToToken(chr);
|
|
@@ -591,7 +592,7 @@ class TokenParser {
|
|
|
591
592
|
if (!('literalLength' in this.currentNode)) {
|
|
592
593
|
let error = new Error(`Unexpected literal prefix end char } at position ${this.pos + i} [E23]`);
|
|
593
594
|
error.code = 'ParserError23';
|
|
594
|
-
error.parserContext = {
|
|
595
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
595
596
|
throw error;
|
|
596
597
|
}
|
|
597
598
|
if (this.str.charAt(i + 1) === '\n') {
|
|
@@ -603,7 +604,7 @@ class TokenParser {
|
|
|
603
604
|
else {
|
|
604
605
|
let error = new Error(`Unexpected char at position ${this.pos + i} [E24: ${JSON.stringify(chr)}]`);
|
|
605
606
|
error.code = 'ParserError24';
|
|
606
|
-
error.parserContext = {
|
|
607
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
607
608
|
throw error;
|
|
608
609
|
}
|
|
609
610
|
this.currentNode.literalLength = Number(this.currentNode.literalLength);
|
|
@@ -653,7 +654,7 @@ class TokenParser {
|
|
|
653
654
|
if (literalLength > this.maxLiteralSize || literalLength > available) {
|
|
654
655
|
let overMax = literalLength > this.maxLiteralSize;
|
|
655
656
|
let error = (0, limits_js_1.createLiteralTooLargeError)(literalLength, overMax ? this.maxLiteralSize : available, overMax ? null : `the ${available} bytes available in the input`);
|
|
656
|
-
error.parserContext = {
|
|
657
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
657
658
|
throw error;
|
|
658
659
|
}
|
|
659
660
|
this.currentNode.started = true;
|
|
@@ -667,13 +668,13 @@ class TokenParser {
|
|
|
667
668
|
if (!imap_formal_syntax_js_1.default.DIGIT().includes(chr)) {
|
|
668
669
|
let error = new Error(`Unexpected char at position ${this.pos + i} [E25: ${JSON.stringify(chr)}]`);
|
|
669
670
|
error.code = 'ParserError25';
|
|
670
|
-
error.parserContext = {
|
|
671
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
671
672
|
throw error;
|
|
672
673
|
}
|
|
673
674
|
if (this.currentNode.literalLength === '0') {
|
|
674
675
|
let error = new Error(`Invalid literal at position ${this.pos + i} [E26]`);
|
|
675
676
|
error.code = 'ParserError26';
|
|
676
|
-
error.parserContext = {
|
|
677
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
677
678
|
throw error;
|
|
678
679
|
}
|
|
679
680
|
this.currentNode.literalLength = (this.currentNode.literalLength || '') + chr;
|
|
@@ -691,13 +692,13 @@ class TokenParser {
|
|
|
691
692
|
}
|
|
692
693
|
let error = new Error(`Unexpected end of sequence at position ${this.pos + i} [E27: ${JSON.stringify(chr)}]`);
|
|
693
694
|
error.code = 'ParserError27';
|
|
694
|
-
error.parserContext = {
|
|
695
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
695
696
|
throw error;
|
|
696
697
|
}
|
|
697
698
|
if (this.currentNode.value !== '*' && tokenLast === '*' && tokenPrev !== ':') {
|
|
698
699
|
let error = new Error(`Unexpected end of sequence at position ${this.pos + i} [E28: ${JSON.stringify(chr)}]`);
|
|
699
700
|
error.code = 'ParserError28';
|
|
700
|
-
error.parserContext = {
|
|
701
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
701
702
|
throw error;
|
|
702
703
|
}
|
|
703
704
|
this.currentNode.isClosed = true;
|
|
@@ -720,7 +721,7 @@ class TokenParser {
|
|
|
720
721
|
}
|
|
721
722
|
let error = new Error(`Unexpected range separator : at position ${this.pos + i} [E29]`);
|
|
722
723
|
error.code = 'ParserError29';
|
|
723
|
-
error.parserContext = {
|
|
724
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
724
725
|
throw error;
|
|
725
726
|
}
|
|
726
727
|
}
|
|
@@ -728,7 +729,7 @@ class TokenParser {
|
|
|
728
729
|
if (![',', ':'].includes(tokenLast)) {
|
|
729
730
|
let error = new Error(`Unexpected range wildcard at position ${this.pos + i} [E30]`);
|
|
730
731
|
error.code = 'ParserError30';
|
|
731
|
-
error.parserContext = {
|
|
732
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
732
733
|
throw error;
|
|
733
734
|
}
|
|
734
735
|
}
|
|
@@ -740,13 +741,13 @@ class TokenParser {
|
|
|
740
741
|
}
|
|
741
742
|
let error = new Error(`Unexpected sequence separator , at position ${this.pos + i} [E31]`);
|
|
742
743
|
error.code = 'ParserError31';
|
|
743
|
-
error.parserContext = {
|
|
744
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
744
745
|
throw error;
|
|
745
746
|
}
|
|
746
747
|
if (tokenLast === '*' && tokenPrev !== ':') {
|
|
747
748
|
let error = new Error(`Unexpected sequence separator , at position ${this.pos + i} [E32]`);
|
|
748
749
|
error.code = 'ParserError32';
|
|
749
|
-
error.parserContext = {
|
|
750
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
750
751
|
throw error;
|
|
751
752
|
}
|
|
752
753
|
}
|
|
@@ -757,13 +758,13 @@ class TokenParser {
|
|
|
757
758
|
}
|
|
758
759
|
let error = new Error(`Unexpected char at position ${this.pos + i} [E33: ${JSON.stringify(chr)}]`);
|
|
759
760
|
error.code = 'ParserError33';
|
|
760
|
-
error.parserContext = {
|
|
761
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
761
762
|
throw error;
|
|
762
763
|
}
|
|
763
764
|
if (RE_SINGLE_DIGIT.test(chr) && tokenLast === '*') {
|
|
764
765
|
let error = new Error(`Unexpected number at position ${this.pos + i} [E34: ${JSON.stringify(chr)}]`);
|
|
765
766
|
error.code = 'ParserError34';
|
|
766
|
-
error.parserContext = {
|
|
767
|
+
error.parserContext = { ...(0, limits_js_1.boundedInput)(this.str), pos: this.pos + i, chr };
|
|
767
768
|
throw error;
|
|
768
769
|
}
|
|
769
770
|
appendToToken(chr);
|
|
@@ -775,6 +776,13 @@ class TokenParser {
|
|
|
775
776
|
if (this.state === STATE_SEQUENCE && (tokenLast === ':' || tokenLast === ',') && !tokenHasStar) {
|
|
776
777
|
this.currentNode.type = 'ATOM';
|
|
777
778
|
}
|
|
779
|
+
// A star-led sequence set ("*:4") is only closed by a space or a closing delimiter, so one
|
|
780
|
+
// that ends the input is closed here, under the same rules a space applies to it. A bare "*"
|
|
781
|
+
// is left to getAttributes(), which reads it as an atom
|
|
782
|
+
if (this.state === STATE_SEQUENCE && !this.currentNode.isClosed && (RE_SINGLE_DIGIT.test(tokenLast) || (tokenLast === '*' && tokenPrev === ':'))) {
|
|
783
|
+
this.currentNode.isClosed = true;
|
|
784
|
+
this.currentNode.endPos = this.pos + this.str.length - 1;
|
|
785
|
+
}
|
|
778
786
|
}
|
|
779
787
|
}
|
|
780
788
|
exports.TokenParser = TokenParser;
|
package/dist/cjs/imap-flow.d.ts
CHANGED
|
@@ -122,8 +122,8 @@ export declare class ImapFlow extends EventEmitter {
|
|
|
122
122
|
*/
|
|
123
123
|
usable: boolean;
|
|
124
124
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
125
|
+
* `true` once the connection is authenticated (by LOGIN, AUTHENTICATE or a PREAUTH greeting),
|
|
126
|
+
* `false` before that. The user name is in `options.auth.user`
|
|
127
127
|
*/
|
|
128
128
|
authenticated: string | boolean;
|
|
129
129
|
/**
|