@bobfrankston/mailx-imap 0.1.15 → 0.1.16

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.
Files changed (2) hide show
  1. package/index.js +26 -4
  2. package/package.json +7 -7
package/index.js CHANGED
@@ -956,9 +956,22 @@ export class ImapManager extends EventEmitter {
956
956
  this.emit("folderCountsChanged", accountId, {});
957
957
  }
958
958
  };
959
- const tomorrow = new Date(Date.now() + 86400000); // IMAP BEFORE is exclusive
960
- // First sync: metadata only for fast UI — bodies prefetched in background after
961
- messages = await client.fetchMessageByDate(folder.path, startDate, tomorrow, { source: false }, onChunk);
959
+ // Fast first-sync: fetch the most recent N messages by sequence
960
+ // number rather than running SEARCH SINCE 30-days-ago. SEARCH
961
+ // SINCE walks INTERNALDATE on every message in the mailbox,
962
+ // which takes minutes on a cold Dovecot mailbox of any size;
963
+ // sequence FETCH is O(1) per message because the server reads
964
+ // message slots directly. The 30-day window is recovered by
965
+ // the existing backfill logic in subsequent sync cycles.
966
+ const FIRST_SYNC_RECENT_COUNT = 200;
967
+ if (typeof client.fetchLatestN === "function") {
968
+ messages = await client.fetchLatestN(folder.path, FIRST_SYNC_RECENT_COUNT, { source: false }, onChunk);
969
+ }
970
+ else {
971
+ // Older iflow-direct without fetchLatestN — fall back to date.
972
+ const tomorrow = new Date(Date.now() + 86400000);
973
+ messages = await client.fetchMessageByDate(folder.path, startDate, tomorrow, { source: false }, onChunk);
974
+ }
962
975
  if (totalStored > 0) {
963
976
  console.log(` ${folder.path}: ${totalStored} messages (streamed)`);
964
977
  this.db.recalcFolderCounts(folderId);
@@ -1247,7 +1260,16 @@ export class ImapManager extends EventEmitter {
1247
1260
  return pa - pb;
1248
1261
  });
1249
1262
  const CONCURRENCY = 2;
1250
- const PER_FOLDER_TIMEOUT_MS = 60_000;
1263
+ // First-sync of a fresh account on a cold Dovecot is dominated by
1264
+ // `UID SEARCH SINCE 30-days-ago`, which can take 5+ minutes on a
1265
+ // large mailbox while the server walks INTERNALDATE on every
1266
+ // message. The previous 60s cap killed every non-INBOX folder
1267
+ // before SEARCH returned, leaving "all subfolders empty" — even
1268
+ // though the connection itself was healthy. After first sync,
1269
+ // incremental fetches (UID > highestUid) are fast, so the long
1270
+ // timeout only hurts on the very first sync of a busy account.
1271
+ // 6 minutes matches Dovecot's 300s inactivity timeout + buffer.
1272
+ const PER_FOLDER_TIMEOUT_MS = 360_000;
1251
1273
  const total = remaining.length;
1252
1274
  let done = 0;
1253
1275
  let idx = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx-imap",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -11,12 +11,12 @@
11
11
  "dependencies": {
12
12
  "@bobfrankston/mailx-types": "^0.1.5",
13
13
  "@bobfrankston/mailx-settings": "^0.1.6",
14
- "@bobfrankston/mailx-store": "^0.1.5",
15
- "@bobfrankston/iflow-direct": "^0.1.27",
14
+ "@bobfrankston/mailx-store": "^0.1.6",
15
+ "@bobfrankston/iflow-direct": "^0.1.28",
16
16
  "@bobfrankston/tcp-transport": "^0.1.5",
17
17
  "@bobfrankston/smtp-direct": "^0.1.5",
18
18
  "@bobfrankston/mailx-sync": "^0.1.10",
19
- "@bobfrankston/oauthsupport": "^1.0.25"
19
+ "@bobfrankston/oauthsupport": "^1.0.26"
20
20
  },
21
21
  "repository": {
22
22
  "type": "git",
@@ -39,12 +39,12 @@
39
39
  "dependencies": {
40
40
  "@bobfrankston/mailx-types": "^0.1.5",
41
41
  "@bobfrankston/mailx-settings": "^0.1.6",
42
- "@bobfrankston/mailx-store": "^0.1.5",
43
- "@bobfrankston/iflow-direct": "^0.1.27",
42
+ "@bobfrankston/mailx-store": "^0.1.6",
43
+ "@bobfrankston/iflow-direct": "^0.1.28",
44
44
  "@bobfrankston/tcp-transport": "^0.1.5",
45
45
  "@bobfrankston/smtp-direct": "^0.1.5",
46
46
  "@bobfrankston/mailx-sync": "^0.1.10",
47
- "@bobfrankston/oauthsupport": "^1.0.25"
47
+ "@bobfrankston/oauthsupport": "^1.0.26"
48
48
  }
49
49
  }
50
50
  }