imapflow 1.0.173 → 1.0.175

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,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.175](https://github.com/postalsys/imapflow/compare/v1.0.174...v1.0.175) (2025-01-15)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **socket:** Throw an error if trying to write to a closed socket ([1d8e941](https://github.com/postalsys/imapflow/commit/1d8e941485223c76c4f22080e985587349c0e458))
9
+
10
+ ## [1.0.174](https://github.com/postalsys/imapflow/compare/v1.0.173...v1.0.174) (2025-01-08)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **auth:** Fixed AUTHENTICATE LOGIN if server uses 'VXNlciBOYW1lAA==' for username ([86c08a7](https://github.com/postalsys/imapflow/commit/86c08a769e2a98fe59375857cd16661e804f79a7))
16
+
3
17
  ## [1.0.173](https://github.com/postalsys/imapflow/compare/v1.0.172...v1.0.173) (2025-01-08)
4
18
 
5
19
 
@@ -66,17 +66,22 @@ async function authLogin(connection, username, password) {
66
66
  onPlusTag: async resp => {
67
67
  if (resp.attributes && resp.attributes[0] && resp.attributes[0].type === 'TEXT') {
68
68
  let question = Buffer.from(resp.attributes[0].value, 'base64').toString();
69
- switch (question.toLowerCase().replace(/:$/, '')) {
70
- case 'username': {
69
+ switch (
70
+ question.toLowerCase().replace(/[:\x00]*$/, '') // eslint-disable-line no-control-regex
71
+ ) {
72
+ case 'username':
73
+ case 'user name': {
71
74
  let encodedUsername = Buffer.from(username).toString('base64');
72
75
  connection.log.debug({ src: 'c', msg: encodedUsername, comment: `Encoded username for AUTH=LOGIN` });
73
76
  connection.write(encodedUsername);
74
77
  break;
75
78
  }
79
+
76
80
  case 'password':
77
81
  connection.log.debug({ src: 'c', msg: '(* value hidden *)', comment: `Encoded password for AUTH=LOGIN` });
78
82
  connection.write(Buffer.from(password).toString('base64'));
79
83
  break;
84
+
80
85
  default: {
81
86
  let error = new Error(`Unknown LOGIN question "${question}"`);
82
87
  throw error;
package/lib/imap-flow.js CHANGED
@@ -387,9 +387,18 @@ class ImapFlow extends EventEmitter {
387
387
  }
388
388
 
389
389
  write(chunk) {
390
- if (this.socket.destroyed || this.state === this.states.LOGOUT) {
390
+ if (this.socket.destroyed) {
391
391
  // do not write after connection end or logout
392
- return;
392
+ const error = new Error('Socket is already closed');
393
+ error.code = 'NoConnection';
394
+ throw error;
395
+ }
396
+
397
+ if (this.state === this.states.LOGOUT) {
398
+ // should not happen
399
+ const error = new Error('Can not send data after logged out');
400
+ error.code = 'StateLogout';
401
+ throw error;
393
402
  }
394
403
 
395
404
  if (this.writeSocket.destroyed) {
@@ -471,6 +480,7 @@ class ImapFlow extends EventEmitter {
471
480
  let options = data.options || {};
472
481
 
473
482
  this.log.debug({ src: 's', msg: logCompiled.toString(), cid: this.id, comment: options.comment });
483
+
474
484
  this.write(this.commandParts.shift());
475
485
 
476
486
  if (typeof options.onSend === 'function') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imapflow",
3
- "version": "1.0.173",
3
+ "version": "1.0.175",
4
4
  "description": "IMAP Client for Node",
5
5
  "main": "./lib/imap-flow.js",
6
6
  "scripts": {