imapflow 1.0.105 → 1.0.106

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.
@@ -22,8 +22,6 @@ class ParserInstance {
22
22
  }
23
23
 
24
24
  async getCommand() {
25
- let responseCode;
26
-
27
25
  if (this.tag === '+') {
28
26
  // special case
29
27
  this.humanReadable = this.remainder.trim();
@@ -42,13 +40,28 @@ class ParserInstance {
42
40
  case 'BAD':
43
41
  case 'PREAUTH':
44
42
  case 'BYE':
45
- responseCode = this.remainder.match(/^ \[(?:[^\]]*\])+/);
46
- if (responseCode) {
47
- this.humanReadable = this.remainder.substr(responseCode[0].length).trim();
48
- this.remainder = responseCode[0];
49
- } else {
50
- this.humanReadable = this.remainder.trim();
51
- this.remainder = '';
43
+ {
44
+ let match = this.remainder.match(/^\s+\[/);
45
+ if (match) {
46
+ let nesting = 1;
47
+ for (let i = match[0].length; i <= this.remainder.length; i++) {
48
+ let c = this.remainder[i];
49
+
50
+ if (c === '[') {
51
+ nesting++;
52
+ } else if (c === ']') {
53
+ nesting--;
54
+ }
55
+ if (!nesting) {
56
+ this.humanReadable = this.remainder.substring(i + 1).trim();
57
+ this.remainder = this.remainder.substring(0, i + 1);
58
+ break;
59
+ }
60
+ }
61
+ } else {
62
+ this.humanReadable = this.remainder.trim();
63
+ this.remainder = '';
64
+ }
52
65
  }
53
66
  break;
54
67
  }
@@ -167,6 +167,7 @@ class TokenParser {
167
167
  this.currentNode.isClosed = true;
168
168
  this.currentNode.endPos = this.pos + i;
169
169
  this.currentNode = this.currentNode.parentNode;
170
+
170
171
  checkSP();
171
172
  break;
172
173
 
@@ -222,7 +223,7 @@ class TokenParser {
222
223
  // [ starts section
223
224
  case '[':
224
225
  // If it is the *first* element after response command, then process as a response argument list
225
- if (['OK', 'NO', 'BAD', 'BYE', 'PREAUTH'].indexOf(this.parent.command.toUpperCase()) >= 0 && this.currentNode === this.tree) {
226
+ if (['OK', 'NO', 'BAD', 'BYE', 'PREAUTH'].includes(this.parent.command.toUpperCase()) && this.currentNode === this.tree) {
226
227
  this.currentNode.endPos = this.pos + i;
227
228
 
228
229
  this.currentNode = this.createNode(this.currentNode, this.pos + i);
@@ -258,6 +259,7 @@ class TokenParser {
258
259
  // close out the SECTION
259
260
  this.currentNode.isClosed = true;
260
261
  this.currentNode = this.currentNode.parentNode;
262
+
261
263
  checkSP();
262
264
  }
263
265
 
@@ -302,8 +304,8 @@ class TokenParser {
302
304
  this.currentNode.endPos = this.pos + i;
303
305
  this.currentNode = this.currentNode.parentNode;
304
306
  this.state = 'NORMAL';
305
-
306
307
  checkSP();
308
+
307
309
  break;
308
310
  }
309
311
 
@@ -541,6 +543,10 @@ class TokenParser {
541
543
 
542
544
  this.currentNode.value += chr;
543
545
  break;
546
+
547
+ case 'TEXT':
548
+ this.currentNode.value += chr;
549
+ break;
544
550
  }
545
551
  }
546
552
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imapflow",
3
- "version": "1.0.105",
3
+ "version": "1.0.106",
4
4
  "description": "IMAP Client for Node",
5
5
  "main": "./lib/imap-flow.js",
6
6
  "scripts": {
@@ -31,7 +31,7 @@
31
31
  "@babel/eslint-plugin": "7.18.10",
32
32
  "@babel/plugin-syntax-class-properties": "7.12.13",
33
33
  "@babel/preset-env": "7.18.10",
34
- "@types/node": "18.7.9",
34
+ "@types/node": "18.7.11",
35
35
  "braintree-jsdoc-template": "3.3.0",
36
36
  "eslint": "8.22.0",
37
37
  "eslint-config-nodemailer": "1.2.0",
@@ -914,11 +914,19 @@ module.exports['IMAP Parser, unicode select'] = test =>
914
914
  value: '',
915
915
  section: [{ type: 'ATOM', value: 'READ-WRITE' }]
916
916
  },
917
- { type: 'ATOM', value: '[Gmail]/Visi' },
918
- { type: 'ATOM', value: 'laiškai' },
919
- { type: 'ATOM', value: 'selected.' },
920
- [{ type: 'ATOM', value: 'Success' }],
921
- { type: 'ATOM', value: '[THROTTLED]' }
917
+ { type: 'TEXT', value: '[Gmail]/Visi laiškai selected. (Success) [THROTTLED]' }
918
+ ])
919
+ );
920
+
921
+ module.exports['IMAP Parser, unicode select 2'] = test =>
922
+ asyncWrapper(test, async test =>
923
+ test.deepEqual((await parser('E OK [READ-WRITE] [Gmail]/Вся почта selected. (Success) [THROTTLED]')).attributes, [
924
+ {
925
+ type: 'ATOM',
926
+ value: '',
927
+ section: [{ type: 'ATOM', value: 'READ-WRITE' }]
928
+ },
929
+ { type: 'TEXT', value: '[Gmail]/Вся почта selected. (Success) [THROTTLED]' }
922
930
  ])
923
931
  );
924
932