imapflow 1.2.0 → 1.2.1

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.
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "1.2.0"
2
+ ".": "1.2.1"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.2.1](https://github.com/postalsys/imapflow/compare/v1.2.0...v1.2.1) (2025-12-17)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * Defer promise rejections on connection close to prevent unhandled rejections ([e53d9a8](https://github.com/postalsys/imapflow/commit/e53d9a8e0028197a5ff3c7cda342e0c11b64f228))
9
+
3
10
  ## [1.2.0](https://github.com/postalsys/imapflow/compare/v1.1.1...v1.2.0) (2025-12-11)
4
11
 
5
12
 
package/lib/imap-flow.js CHANGED
@@ -1252,7 +1252,17 @@ class ImapFlow extends EventEmitter {
1252
1252
  });
1253
1253
  }
1254
1254
 
1255
- async serverBye() {
1255
+ async serverBye(parsed) {
1256
+ // Extract BYE reason from response for better error messages
1257
+ let reason =
1258
+ parsed &&
1259
+ parsed.attributes &&
1260
+ parsed.attributes
1261
+ .filter(val => val.type === 'TEXT')
1262
+ .map(val => val.value.trim())
1263
+ .join(' ');
1264
+
1265
+ this.byeReason = reason || 'Server closed connection';
1256
1266
  this.untaggedHandlers.BYE = null;
1257
1267
  this.state = this.states.LOGOUT;
1258
1268
  }
@@ -1695,14 +1705,15 @@ class ImapFlow extends EventEmitter {
1695
1705
  this.preCheck().catch(err => this.log.warn({ err, cid: this.id }));
1696
1706
  }
1697
1707
 
1708
+ // Collect all pending requests to reject
1709
+ let pendingRequests = [];
1710
+
1698
1711
  // reject command that is currently processed
1699
1712
  if (this.currentRequest && this.requestTagMap.has(this.currentRequest.tag)) {
1700
1713
  let request = this.requestTagMap.get(this.currentRequest.tag);
1701
1714
  if (request) {
1702
1715
  this.requestTagMap.delete(request.tag);
1703
- const error = new Error('Connection not available');
1704
- error.code = 'NoConnection';
1705
- request.reject(error);
1716
+ pendingRequests.push(request);
1706
1717
  }
1707
1718
  this.currentRequest = false;
1708
1719
  }
@@ -1714,11 +1725,25 @@ class ImapFlow extends EventEmitter {
1714
1725
  let request = this.requestTagMap.get(req.tag);
1715
1726
  if (request) {
1716
1727
  this.requestTagMap.delete(request.tag);
1728
+ pendingRequests.push(request);
1729
+ }
1730
+ }
1731
+ }
1732
+
1733
+ // Defer rejections to next tick to allow event handlers to be properly set up
1734
+ // This helps prevent unhandled rejections when connection closes unexpectedly
1735
+ if (pendingRequests.length) {
1736
+ let byeReason = this.byeReason;
1737
+ setImmediate(() => {
1738
+ for (let request of pendingRequests) {
1717
1739
  const error = new Error('Connection not available');
1718
1740
  error.code = 'NoConnection';
1741
+ if (byeReason) {
1742
+ error.reason = byeReason;
1743
+ }
1719
1744
  request.reject(error);
1720
1745
  }
1721
- }
1746
+ });
1722
1747
  }
1723
1748
 
1724
1749
  // cleanup compression streams if they exist
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imapflow",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "IMAP Client for Node",
5
5
  "main": "lib/imap-flow.js",
6
6
  "types": "lib/imap-flow.d.ts",