imapflow 1.0.182 → 1.0.184

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,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.184](https://github.com/postalsys/imapflow/compare/v1.0.183...v1.0.184) (2025-03-11)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * Allow to call the connect method only once ([ca7ec96](https://github.com/postalsys/imapflow/commit/ca7ec969f19a93c5dc574bf3873cd7afc4d7af47))
9
+ * **Authentication:** Report errors; Fix LOGINDISABLED ([#275](https://github.com/postalsys/imapflow/issues/275)) ([a3a3fb9](https://github.com/postalsys/imapflow/commit/a3a3fb993dee66c02b34bba0e0b26fc349487b26))
10
+
11
+ ## [1.0.183](https://github.com/postalsys/imapflow/compare/v1.0.182...v1.0.183) (2025-03-09)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * Date time format in IMAP requires space before a single digit ([#272](https://github.com/postalsys/imapflow/issues/272)) ([bdb6b09](https://github.com/postalsys/imapflow/commit/bdb6b09a9939e65e0342219539e13045ce3f6995))
17
+
3
18
  ## [1.0.182](https://github.com/postalsys/imapflow/compare/v1.0.181...v1.0.182) (2025-03-04)
4
19
 
5
20
 
package/lib/imap-flow.js CHANGED
@@ -38,6 +38,7 @@ const {
38
38
  packMessageRange,
39
39
  normalizePath,
40
40
  expandRange,
41
+ AuthenticationFailure,
41
42
  getColorFlags
42
43
  } = require('./tools');
43
44
 
@@ -370,6 +371,9 @@ class ImapFlow extends EventEmitter {
370
371
  setImmediate(() => this.close());
371
372
  this.emitError(err);
372
373
  });
374
+
375
+ // Has the `connect` method already been called
376
+ this._connectCalled = false;
373
377
  }
374
378
 
375
379
  emitError(err) {
@@ -796,11 +800,7 @@ class ImapFlow extends EventEmitter {
796
800
 
797
801
  await this.upgradeToSTARTTLS();
798
802
 
799
- let authenticated = await this.authenticate();
800
- if (!authenticated) {
801
- // nothing to do here
802
- return await this.logout();
803
- }
803
+ await this.authenticate();
804
804
 
805
805
  if (!this.idRequested && this.capabilities.has('ID')) {
806
806
  // re-request ID after LOGIN
@@ -812,8 +812,7 @@ class ImapFlow extends EventEmitter {
812
812
  if (nsResponse && nsResponse.error && nsResponse.status === 'BAD' && /User is authenticated but not connected/i.test(nsResponse.text)) {
813
813
  // Not a NAMESPACE failure but authentication failure, so report as
814
814
  this.authenticated = false;
815
- let err = new Error('Authentication failed');
816
- err.authenticationFailed = true;
815
+ let err = new AuthenticationFailure('Authentication failed');
817
816
  err.response = nsResponse.text;
818
817
  throw err;
819
818
  }
@@ -1043,14 +1042,17 @@ class ImapFlow extends EventEmitter {
1043
1042
  }
1044
1043
 
1045
1044
  async authenticate() {
1045
+ if (this.state === this.states.LOGOUT) {
1046
+ throw new AuthenticationFailure('Already logged out');
1047
+ }
1048
+
1046
1049
  if (this.state !== this.states.NOT_AUTHENTICATED) {
1047
1050
  // nothing to do here, usually happens with PREAUTH greeting
1048
- return this.state !== this.states.LOGOUT;
1051
+ return true;
1049
1052
  }
1050
1053
 
1051
- if (this.capabilities.has('LOGINDISABLED') || !this.options.auth) {
1052
- // can not log in
1053
- return false;
1054
+ if (!this.options.auth) {
1055
+ throw new AuthenticationFailure('Please configure the login');
1054
1056
  }
1055
1057
 
1056
1058
  this.expectCapabilityUpdate = true;
@@ -1067,8 +1069,13 @@ class ImapFlow extends EventEmitter {
1067
1069
  if ((this.capabilities.has('AUTH=LOGIN') || this.capabilities.has('AUTH=PLAIN')) && loginMethod !== 'LOGIN') {
1068
1070
  this.authenticated = await this.run('AUTHENTICATE', this.options.auth.user, { password: this.options.auth.pass, loginMethod });
1069
1071
  } else {
1072
+ if (this.capabilities.has('LOGINDISABLED')) {
1073
+ throw new AuthenticationFailure('Login is disabled');
1074
+ }
1070
1075
  this.authenticated = await this.run('LOGIN', this.options.auth.user, this.options.auth.pass);
1071
1076
  }
1077
+ } else {
1078
+ throw new AuthenticationFailure('No password configured');
1072
1079
  }
1073
1080
 
1074
1081
  if (this.authenticated) {
@@ -1082,7 +1089,7 @@ class ImapFlow extends EventEmitter {
1082
1089
  return true;
1083
1090
  }
1084
1091
 
1085
- return false;
1092
+ throw new AuthenticationFailure('No matching authentication method');
1086
1093
  }
1087
1094
 
1088
1095
  async initialOK(message) {
@@ -1405,6 +1412,12 @@ class ImapFlow extends EventEmitter {
1405
1412
  * await client.connect();
1406
1413
  */
1407
1414
  async connect() {
1415
+ if (this._connectCalled) {
1416
+ // Prevent re-using ImapFlow instances by allowing to call connect just once.
1417
+ throw new Error('Can not re-use ImapFlow instance');
1418
+ }
1419
+ this._connectCalled = true;
1420
+
1408
1421
  let connector = this.secureConnection ? tls : net;
1409
1422
 
1410
1423
  let opts = Object.assign(
package/lib/tools.js CHANGED
@@ -11,6 +11,10 @@ const iconv = require('iconv-lite');
11
11
 
12
12
  const FLAG_COLORS = ['red', 'orange', 'yellow', 'green', 'blue', 'purple', 'grey'];
13
13
 
14
+ class AuthenticationFailure extends Error {
15
+ authenticationFailed = true;
16
+ }
17
+
14
18
  const tools = {
15
19
  encodePath(connection, path) {
16
20
  path = (path || '').toString();
@@ -90,6 +94,8 @@ const tools = {
90
94
  return map;
91
95
  },
92
96
 
97
+ AuthenticationFailure,
98
+
93
99
  getStatusCode(response) {
94
100
  return response &&
95
101
  response.attributes &&
@@ -780,7 +786,7 @@ const tools = {
780
786
  return;
781
787
  }
782
788
 
783
- let dateStr = tools.formatDate(value).replace(/^0/, ''); //starts with date-day-fixed with leading 0 replaced by SP
789
+ let dateStr = tools.formatDate(value).replace(/^0/, ' '); //starts with date-day-fixed with leading 0 replaced by SP
784
790
  let timeStr = value.toISOString().substr(11, 8);
785
791
 
786
792
  return `${dateStr} ${timeStr} +0000`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imapflow",
3
- "version": "1.0.182",
3
+ "version": "1.0.184",
4
4
  "description": "IMAP Client for Node",
5
5
  "main": "./lib/imap-flow.js",
6
6
  "scripts": {
@@ -28,11 +28,11 @@
28
28
  },
29
29
  "homepage": "https://imapflow.com/",
30
30
  "devDependencies": {
31
- "@babel/eslint-parser": "7.26.5",
31
+ "@babel/eslint-parser": "7.26.8",
32
32
  "@babel/eslint-plugin": "7.25.9",
33
33
  "@babel/plugin-syntax-class-properties": "7.12.13",
34
- "@babel/preset-env": "7.26.7",
35
- "@types/node": "22.13.1",
34
+ "@babel/preset-env": "7.26.9",
35
+ "@types/node": "22.13.10",
36
36
  "eslint": "8.57.0",
37
37
  "eslint-config-nodemailer": "1.2.0",
38
38
  "eslint-config-prettier": "9.1.0",
@@ -51,9 +51,9 @@
51
51
  "libbase64": "1.3.0",
52
52
  "libmime": "5.3.6",
53
53
  "libqp": "2.1.1",
54
- "mailsplit": "5.4.2",
54
+ "mailsplit": "5.4.3",
55
55
  "nodemailer": "6.10.0",
56
56
  "pino": "9.6.0",
57
- "socks": "2.8.3"
57
+ "socks": "2.8.4"
58
58
  }
59
59
  }