imapflow 1.1.0 → 1.1.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.1.0"
2
+ ".": "1.1.1"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1.1](https://github.com/postalsys/imapflow/compare/imapflow-v1.1.0...imapflow-v1.1.1) (2025-10-27)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * prevent race condition in initial IMAP greeting reception ([4841f79](https://github.com/postalsys/imapflow/commit/4841f79cd4a94067747c3139fb1de41df49ed533))
9
+
3
10
  ## [1.1.0](https://github.com/postalsys/imapflow/compare/imapflow-v1.0.200...imapflow-v1.1.0) (2025-10-23)
4
11
 
5
12
 
package/lib/imap-flow.js CHANGED
@@ -1598,6 +1598,7 @@ class ImapFlow extends EventEmitter {
1598
1598
  this.log.info(logInfo);
1599
1599
 
1600
1600
  this.setSocketHandlers();
1601
+ this.setEventHandlers();
1601
1602
  this.socket.pipe(this.streamer);
1602
1603
 
1603
1604
  // executed by initial "* OK"
@@ -1633,8 +1634,6 @@ class ImapFlow extends EventEmitter {
1633
1634
  this.log.error({ err, cid: this.id });
1634
1635
  reject(err);
1635
1636
  });
1636
-
1637
- this.setEventHandlers();
1638
1637
  });
1639
1638
  }
1640
1639
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imapflow",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "IMAP Client for Node",
5
5
  "main": "lib/imap-flow.js",
6
6
  "types": "lib/imap-flow.d.ts",
@@ -647,3 +647,56 @@ module.exports['Connection Edge: Capability update after STARTTLS'] = test => {
647
647
  test.done();
648
648
  });
649
649
  };
650
+
651
+ module.exports['Connection Edge: Event handlers attached before piping'] = test => {
652
+ let client = new ImapFlow({
653
+ host: 'imap.example.com',
654
+ port: 993,
655
+ auth: { user: 'test', pass: 'test' }
656
+ });
657
+
658
+ // Track the order of operations during the connection flow
659
+ let pipeCalledBeforeHandlers = false;
660
+ let eventHandlersAttached = false;
661
+ let pipeWasCalled = false;
662
+
663
+ // Override setEventHandlers to track when it's called
664
+ let originalSetEventHandlers = client.setEventHandlers.bind(client);
665
+ client.setEventHandlers = function () {
666
+ eventHandlersAttached = true;
667
+ return originalSetEventHandlers();
668
+ };
669
+
670
+ // Create a mock socket with pipe tracking
671
+ let mockSocket = new EventEmitter();
672
+ mockSocket.setKeepAlive = () => {};
673
+ mockSocket.setTimeout = () => {};
674
+ mockSocket.remotePort = 993;
675
+ mockSocket.remoteAddress = '127.0.0.1';
676
+ mockSocket.localAddress = '127.0.0.1';
677
+ mockSocket.localPort = 12345;
678
+ mockSocket.destroyed = false;
679
+ mockSocket.pipe = function (dest) {
680
+ pipeWasCalled = true;
681
+ if (!eventHandlersAttached) {
682
+ pipeCalledBeforeHandlers = true;
683
+ }
684
+ // Mock pipe behavior - just return the destination
685
+ return dest;
686
+ };
687
+
688
+ // Assign mock socket
689
+ client.socket = mockSocket;
690
+ client.writeSocket = mockSocket;
691
+
692
+ // Simulate the onConnect flow that happens in the actual code
693
+ client.setSocketHandlers();
694
+ client.setEventHandlers();
695
+ client.socket.pipe(client.streamer);
696
+
697
+ test.ok(eventHandlersAttached, 'Event handlers should be attached');
698
+ test.ok(pipeWasCalled, 'Socket pipe should be called');
699
+ test.ok(!pipeCalledBeforeHandlers, 'Event handlers should be attached before piping socket to streamer');
700
+
701
+ test.done();
702
+ };