imapflow 1.0.82 → 1.0.85

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # CHANGELOG
2
2
 
3
+ - 1.0.85 - 2022-02-23
4
+
5
+ - Trim null bytes in the beginning of IMAP responses to deal with a buggy server that pads responses with null bytes
6
+
7
+ - 1.0.84 - 2022-02-17
8
+
9
+ - QRESYNC tweaks
10
+
11
+ - 1.0.83 - 2022-02-16
12
+
13
+ - QRESYNC tweaks
14
+
3
15
  - 1.0.82 - 2022-02-15
4
16
 
5
17
  - Added extra option `expungeHandler`
@@ -40,10 +40,11 @@ module.exports = async (connection, path, options) => {
40
40
  extraArgs.push([
41
41
  { type: 'ATOM', value: 'QRESYNC' },
42
42
  [
43
- { type: 'ATOM', value: options.uidValidity },
44
- { type: 'ATOM', value: options.changedSince }
43
+ { type: 'ATOM', value: options.uidValidity.toString() },
44
+ { type: 'ATOM', value: options.changedSince.toString() }
45
45
  ]
46
46
  ]);
47
+ map.qresync = true;
47
48
  }
48
49
 
49
50
  response = await connection.exec(!options.readOnly ? 'SELECT' : 'EXAMINE', [{ type: 'ATOM', value: path }].concat(extraArgs || []), {
@@ -155,6 +156,19 @@ module.exports = async (connection, path, options) => {
155
156
  }
156
157
  }
157
158
 
159
+ if (
160
+ map.qresync &&
161
+ // UIDVALIDITY must be the same
162
+ (options.uidValidity !== map.uidValidity ||
163
+ // HIGHESTMODSEQ response must be present
164
+ !map.highestModseq ||
165
+ // NOMODSEQ is not allowed
166
+ map.noModseq)
167
+ ) {
168
+ // QRESYNC does not apply here, so unset it
169
+ map.qresync = false;
170
+ }
171
+
158
172
  let currentMailbox = connection.mailbox;
159
173
  connection.mailbox = false;
160
174
 
@@ -6,6 +6,21 @@ const { ParserInstance } = require('./parser-instance');
6
6
  module.exports = async (command, options) => {
7
7
  options = options || {};
8
8
 
9
+ let nullBytesRemoved = 0;
10
+
11
+ // special case with a buggy IMAP server where responses are padded with zero bytes
12
+ if (command[0] === 0) {
13
+ // find the first non null byte and trim
14
+ for (let i = 0; i < command.length; i++) {
15
+ if (command[i] !== 0) {
16
+ // trim to here
17
+ command = command.slice(i);
18
+ nullBytesRemoved = i;
19
+ break;
20
+ }
21
+ }
22
+ }
23
+
9
24
  const parser = new ParserInstance(command, options);
10
25
  const response = {};
11
26
 
@@ -13,6 +28,10 @@ module.exports = async (command, options) => {
13
28
  await parser.getSpace();
14
29
  response.command = await parser.getCommand();
15
30
 
31
+ if (nullBytesRemoved) {
32
+ response.nullBytesRemoved = nullBytesRemoved;
33
+ }
34
+
16
35
  if (['UID', 'AUTHENTICATE'].indexOf((response.command || '').toUpperCase()) >= 0) {
17
36
  await parser.getSpace();
18
37
  response.command += ' ' + (await parser.getElement(imapFormalSyntax.command()));
package/lib/imap-flow.js CHANGED
@@ -424,9 +424,9 @@ class ImapFlow extends EventEmitter {
424
424
 
425
425
  if (/^\d+$/.test(parsed.command) && parsed.attributes && parsed.attributes[0] && parsed.attributes[0].value === 'FETCH') {
426
426
  // too many FETCH responses, might want to filter these out
427
- this.log.trace({ src: 's', msg: logCompiled.toString(), cid: this.id });
427
+ this.log.trace({ src: 's', msg: logCompiled.toString(), cid: this.id, nullBytesRemoved: parsed.nullBytesRemoved });
428
428
  } else {
429
- this.log.debug({ src: 's', msg: logCompiled.toString(), cid: this.id });
429
+ this.log.debug({ src: 's', msg: logCompiled.toString(), cid: this.id, nullBytesRemoved: parsed.nullBytesRemoved });
430
430
  }
431
431
 
432
432
  if (parsed.tag === '+' && this.currentRequest && this.currentRequest.options && typeof this.currentRequest.options.onPlusTag === 'function') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imapflow",
3
- "version": "1.0.82",
3
+ "version": "1.0.85",
4
4
  "description": "IMAP Client for Node",
5
5
  "main": "./lib/imap-flow.js",
6
6
  "scripts": {
@@ -30,11 +30,11 @@
30
30
  "@babel/eslint-plugin": "7.16.5",
31
31
  "@babel/plugin-syntax-class-properties": "7.12.13",
32
32
  "@babel/preset-env": "7.16.11",
33
- "@types/node": "17.0.18",
33
+ "@types/node": "17.0.19",
34
34
  "braintree-jsdoc-template": "3.3.0",
35
35
  "eslint": "8.9.0",
36
36
  "eslint-config-nodemailer": "1.2.0",
37
- "eslint-config-prettier": "8.3.0",
37
+ "eslint-config-prettier": "8.4.0",
38
38
  "grunt": "1.4.1",
39
39
  "grunt-cli": "1.4.3",
40
40
  "grunt-contrib-nodeunit": "4.0.0",