imapflow 1.0.183 → 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 +8 -0
- package/lib/imap-flow.js +25 -12
- package/lib/tools.js +6 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
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
|
+
|
|
3
11
|
## [1.0.183](https://github.com/postalsys/imapflow/compare/v1.0.182...v1.0.183) (2025-03-09)
|
|
4
12
|
|
|
5
13
|
|
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
|
-
|
|
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
|
|
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
|
|
1051
|
+
return true;
|
|
1049
1052
|
}
|
|
1050
1053
|
|
|
1051
|
-
if (
|
|
1052
|
-
|
|
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
|
-
|
|
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 &&
|