@bobfrankston/iflow-direct 0.1.19 → 0.1.20

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/imap-compat.d.ts CHANGED
@@ -27,10 +27,10 @@ export declare class CompatImapClient {
27
27
  /** Connect and authenticate */
28
28
  connect(): Promise<void>;
29
29
  /**
30
- * Ensure connected (lazy connect). Delegates to the native client's
31
- * `connected` flag, which is cleared by transport close/error, inactivity
32
- * timeout, and write failures so a silently dead socket reconnects on the
33
- * next call instead of cascading ENOTFOUND across every folder.
30
+ * Ensure connected (lazy connect). Checks both the native client's connected
31
+ * flag AND the transport's connected state. The transport flag catches cases
32
+ * where the socket died without a close/error event reaching NativeImapClient
33
+ * (common on Android where the bridge may not relay all TCP events).
34
34
  */
35
35
  private ensureConnected;
36
36
  logout(): Promise<void>;
package/imap-compat.js CHANGED
@@ -19,14 +19,17 @@ export class CompatImapClient {
19
19
  await this.native.connect();
20
20
  }
21
21
  /**
22
- * Ensure connected (lazy connect). Delegates to the native client's
23
- * `connected` flag, which is cleared by transport close/error, inactivity
24
- * timeout, and write failures so a silently dead socket reconnects on the
25
- * next call instead of cascading ENOTFOUND across every folder.
22
+ * Ensure connected (lazy connect). Checks both the native client's connected
23
+ * flag AND the transport's connected state. The transport flag catches cases
24
+ * where the socket died without a close/error event reaching NativeImapClient
25
+ * (common on Android where the bridge may not relay all TCP events).
26
26
  */
27
27
  async ensureConnected() {
28
- if (!this.native.connected)
28
+ if (!this.native.connected || !this.native.transportConnected) {
29
+ // Force a fresh transport — the old one may be in a bad state.
30
+ this.native.resetTransport();
29
31
  await this.connect();
32
+ }
30
33
  }
31
34
  async logout() {
32
35
  await this.native.logout();
package/imap-native.d.ts CHANGED
@@ -65,6 +65,11 @@ export declare class NativeImapClient {
65
65
  private continuationResolve;
66
66
  constructor(config: ImapClientConfig, transportFactory: TransportFactory);
67
67
  get connected(): boolean;
68
+ /** Check the underlying transport's connected state — catches silently dead sockets. */
69
+ get transportConnected(): boolean;
70
+ /** Replace the transport with a fresh one from the factory. Call before reconnect
71
+ * when the old transport is in a bad state (dead socket, stale bridge stream). */
72
+ resetTransport(): void;
68
73
  connect(): Promise<void>;
69
74
  private readGreeting;
70
75
  private authenticate;
package/imap-native.js CHANGED
@@ -36,6 +36,21 @@ export class NativeImapClient {
36
36
  this.fetchChunkSizeMax = config.fetchChunkSizeMax ?? 500;
37
37
  }
38
38
  get connected() { return this._connected; }
39
+ /** Check the underlying transport's connected state — catches silently dead sockets. */
40
+ get transportConnected() { return this.transport?.connected ?? false; }
41
+ /** Replace the transport with a fresh one from the factory. Call before reconnect
42
+ * when the old transport is in a bad state (dead socket, stale bridge stream). */
43
+ resetTransport() {
44
+ try {
45
+ this.transport?.close?.();
46
+ }
47
+ catch { /* ignore */ }
48
+ this.transport = this.transportFactory();
49
+ this._connected = false;
50
+ this.buffer = "";
51
+ this.pendingCommand = null;
52
+ this.selectedMailbox = null;
53
+ }
39
54
  // ── Connection ──
40
55
  async connect() {
41
56
  const useTls = this.config.port === 993;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/iflow-direct",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "Direct IMAP client — transport-agnostic, no Node.js dependencies, browser-ready",
5
5
  "main": "index.js",
6
6
  "types": "index.ts",