imapflow 1.0.110 → 1.0.112

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,16 @@
1
1
  # CHANGELOG
2
2
 
3
+ - 1.0.112 - 2022-10-16
4
+
5
+ - Improved ID compatiblity with servers that allow ID only after login
6
+
7
+ - 1.0.111 - 2022-10-13
8
+
9
+ - Added new connection options
10
+ - connectionTimeout=90000: how many milliseconds to wait for the connection to establish (default is 90 seconds)
11
+ - greetingTimeout=16000: how many milliseconds to wait for the greeting after connection is established (default is 16 seconds)
12
+ - socketTimeout=300000: how many milliseconds of inactivity to allow (default is 5 minutes)
13
+
3
14
  - 1.0.110 - 2022-10-10
4
15
 
5
16
  - Allow unicode atoms by default
package/lib/imap-flow.js CHANGED
@@ -132,6 +132,9 @@ class ImapFlow extends EventEmitter {
132
132
  * @param {Number} [options.maxIdleTime] If set, then breaks and restarts IDLE every maxIdleTime ms
133
133
  * @param {Boolean} [options.disableBinary=false] If true, then ignores the BINARY extension when making FETCH and APPEND calls
134
134
  * @param {Boolean} [options.disableAutoEnable] Do not enable supported extensions by default
135
+ * @param {Number} [options.connectionTimeout=90000] how many milliseconds to wait for the connection to establish (default is 90 seconds)
136
+ * @param {Number} [options.greetingTimeout=16000] how many milliseconds to wait for the greeting after connection is established (default is 16 seconds)
137
+ * @param {Number} [options.socketTimeout=300000] how many milliseconds of inactivity to allow (default is 5 minutes)
135
138
  */
136
139
  constructor(options) {
137
140
  super({ captureRejections: true });
@@ -265,6 +268,8 @@ class ImapFlow extends EventEmitter {
265
268
  this.currentLock = false;
266
269
  this.locks = [];
267
270
 
271
+ this.idRequested = false;
272
+
268
273
  this.maxIdleTime = this.options.maxIdleTime || false;
269
274
 
270
275
  this.disableBinary = !!this.options.disableBinary;
@@ -610,7 +615,10 @@ class ImapFlow extends EventEmitter {
610
615
 
611
616
  async startSession() {
612
617
  await this.run('CAPABILITY');
613
- await this.run('ID', this.clientInfo);
618
+
619
+ if (this.capabilities.has('ID')) {
620
+ this.idRequested = await this.run('ID', this.clientInfo);
621
+ }
614
622
 
615
623
  // try to use STARTTLS is possible
616
624
  if (!this.secureConnection) {
@@ -623,6 +631,11 @@ class ImapFlow extends EventEmitter {
623
631
  return await this.logout();
624
632
  }
625
633
 
634
+ if (!this.idRequested && this.capabilities.has('ID')) {
635
+ // re-request ID after LOGIN
636
+ this.idRequested = await this.run('ID', this.clientInfo);
637
+ }
638
+
626
639
  // Make sure we have namespace set. This should also throw if Exchange actually failed authentication
627
640
  let nsResponse = await this.run('NAMESPACE');
628
641
  if (nsResponse && nsResponse.error && nsResponse.status === 'BAD' && /User is authenticated but not connected/i.test(nsResponse.text)) {
@@ -1187,23 +1200,29 @@ class ImapFlow extends EventEmitter {
1187
1200
  this.connectTimeout = setTimeout(() => {
1188
1201
  let err = new Error('Failed to established connection in required time');
1189
1202
  err.code = 'CONNECT_TIMEOUT';
1203
+ err.details = {
1204
+ connectionTimeout: this.options.connectionTimeout || CONNECT_TIMEOUT
1205
+ };
1190
1206
  this.log.error({ err, cid: this.id });
1191
1207
  setImmediate(() => this.close());
1192
1208
  reject(err);
1193
- }, CONNECT_TIMEOUT);
1209
+ }, this.options.connectionTimeout || CONNECT_TIMEOUT);
1194
1210
 
1195
1211
  let onConnect = () => {
1196
1212
  clearTimeout(this.connectTimeout);
1197
1213
  this.socket.setKeepAlive(true, 5 * 1000);
1198
- this.socket.setTimeout(SOCKET_TIMEOUT);
1214
+ this.socket.setTimeout(this.options.socketTimeout || SOCKET_TIMEOUT);
1199
1215
 
1200
1216
  this.greetingTimeout = setTimeout(() => {
1201
1217
  let err = new Error(`Failed to receive greeting from server in required time${!this.secureConnection ? '. Maybe should use TLS?' : ''}`);
1202
1218
  err.code = 'GREEETING_TIMEOUT';
1219
+ err.details = {
1220
+ greetingTimeout: this.options.greetingTimeout || GREETING_TIMEOUT
1221
+ };
1203
1222
  this.log.error({ err, cid: this.id });
1204
1223
  setImmediate(() => this.close());
1205
1224
  reject(err);
1206
- }, GREETING_TIMEOUT);
1225
+ }, this.options.greetingTimeout || GREETING_TIMEOUT);
1207
1226
 
1208
1227
  this.tls = typeof this.socket.getCipher === 'function' ? this.socket.getCipher() : false;
1209
1228
 
package/lib/types.d.ts CHANGED
@@ -31,6 +31,9 @@ declare module "imapflow" {
31
31
  * @param [options.maxIdleTime] - If set, then breaks and restarts IDLE every maxIdleTime ms
32
32
  * @param [options.disableBinary = false] - If true, then ignores the BINARY extension when making FETCH and APPEND calls
33
33
  * @param [options.disableAutoEnable] - Do not enable supported extensions by default
34
+ * @param [options.connectionTimeout = 90000] - how many milliseconds to wait for the connection to establish (default is 90 seconds)
35
+ * @param [options.greetingTimeout = 16000] - how many milliseconds to wait for the greeting after connection is established (default is 16 seconds)
36
+ * @param [options.socketTimeout = 300000] - how many milliseconds of inactivity to allow (default is 5 minutes)
34
37
  */
35
38
  class ImapFlow extends EventEmitter {
36
39
  constructor(options: {
@@ -60,6 +63,9 @@ declare module "imapflow" {
60
63
  maxIdleTime?: number;
61
64
  disableBinary?: boolean;
62
65
  disableAutoEnable?: boolean;
66
+ connectionTimeout?: number;
67
+ greetingTimeout?: number;
68
+ socketTimeout?: number;
63
69
  });
64
70
  /**
65
71
  * Current module version as a static class property
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imapflow",
3
- "version": "1.0.110",
3
+ "version": "1.0.112",
4
4
  "description": "IMAP Client for Node",
5
5
  "main": "./lib/imap-flow.js",
6
6
  "scripts": {
@@ -30,8 +30,8 @@
30
30
  "@babel/eslint-parser": "7.19.1",
31
31
  "@babel/eslint-plugin": "7.19.1",
32
32
  "@babel/plugin-syntax-class-properties": "7.12.13",
33
- "@babel/preset-env": "7.19.3",
34
- "@types/node": "18.8.3",
33
+ "@babel/preset-env": "7.19.4",
34
+ "@types/node": "18.11.0",
35
35
  "braintree-jsdoc-template": "3.3.0",
36
36
  "eslint": "8.25.0",
37
37
  "eslint-config-nodemailer": "1.2.0",