@bobfrankston/mailx-imap 0.1.111 → 0.1.113

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 +23 -5
  2. package/package.json +9 -9
package/index.js CHANGED
@@ -1307,7 +1307,7 @@ export class ImapManager extends EventEmitter {
1307
1307
  return dbFolders;
1308
1308
  }
1309
1309
  /** Store a batch of messages to DB immediately — used by onChunk for incremental sync */
1310
- async storeMessages(accountId, folderId, folder, msgs, highestUid) {
1310
+ async storeMessages(accountId, folderId, folder, msgs, highestUid, liveServerUids) {
1311
1311
  // Chunked transactions: better-sqlite3 is synchronous and an open
1312
1312
  // transaction blocks every other query on the same DB. A 1881-row
1313
1313
  // INBOX sync inside ONE transaction locked the connection for ~1.5 s
@@ -1384,6 +1384,7 @@ export class ImapManager extends EventEmitter {
1384
1384
  cc: toEmailAddresses(msg.cc || []),
1385
1385
  flags, size: msg.size || 0, hasAttachments, preview, bodyPath,
1386
1386
  exclusive: true, // IMAP path → one folder per message
1387
+ liveServerUids,
1387
1388
  },
1388
1389
  ftsBody,
1389
1390
  });
@@ -1581,7 +1582,10 @@ export class ImapManager extends EventEmitter {
1581
1582
  const chunk = toFetch.slice(i, i + BACKFILL_CHUNK_SIZE);
1582
1583
  try {
1583
1584
  const got = await client.fetchMessages(folderPath, chunk.join(","), { source: false });
1584
- recoveredCount += await this.storeMessages(accountId, folderId, folder, got, 0);
1585
+ // Pass the server's live UID list so move-detect can tell a
1586
+ // duplicate delivery (both uids live in this folder) from a
1587
+ // real move — see upsertMessage.liveServerUids.
1588
+ recoveredCount += await this.storeMessages(accountId, folderId, folder, got, 0, new Set(serverUids));
1585
1589
  }
1586
1590
  catch (e) {
1587
1591
  console.error(` ${folderPath}: backfill chunk ${i}-${i + chunk.length} failed (${e?.message || e}) — keeping ${recoveredCount} so far, resuming next cycle`);
@@ -5724,10 +5728,11 @@ export class ImapManager extends EventEmitter {
5724
5728
  // Compare after the debounce window and only emit on a real change.
5725
5729
  const normalize = (s) => s.replace(/^\uFEFF/, "").replace(/\r\n/g, "\n").replace(/[ \t\r\n]+$/, "");
5726
5730
  const lastContent = new Map();
5727
- for (const filename of files) {
5731
+ const watched = new Set();
5732
+ const watchOne = (filename) => {
5728
5733
  const full = path.join(configDir, filename);
5729
5734
  if (!fs.existsSync(full))
5730
- continue;
5735
+ return false;
5731
5736
  try {
5732
5737
  lastContent.set(filename, normalize(fs.readFileSync(full, "utf-8")));
5733
5738
  }
@@ -5769,11 +5774,16 @@ export class ImapManager extends EventEmitter {
5769
5774
  }, 500));
5770
5775
  });
5771
5776
  this.configWatchers.push(watcher);
5777
+ watched.add(filename);
5778
+ return true;
5772
5779
  }
5773
5780
  catch (e) {
5774
5781
  console.error(` [watch] Failed to watch ${filename}: ${e.message}`);
5782
+ return false;
5775
5783
  }
5776
- }
5784
+ };
5785
+ for (const filename of files)
5786
+ watchOne(filename);
5777
5787
  // GDrive has no push/watch for arbitrary Drive files, so edits on
5778
5788
  // another device (or via Drive web) never fire fs.watch locally.
5779
5789
  // Poll the cloud copies of the replicated-to-cloud config files
@@ -5824,6 +5834,14 @@ export class ImapManager extends EventEmitter {
5824
5834
  }
5825
5835
  fs.writeFileSync(localPath, cloudContent);
5826
5836
  console.log(` [cloud-poll] ${filename} updated from cloud copy`);
5837
+ // A file that didn't exist at startup never got an
5838
+ // fs.watch (watchOne skipped it), so the write above
5839
+ // fires nothing and the cloud edit would be applied to
5840
+ // disk but never loaded. Register the watcher now and
5841
+ // emit configChanged directly for this first change.
5842
+ if (!watched.has(filename) && watchOne(filename)) {
5843
+ this.emit("configChanged", filename);
5844
+ }
5827
5845
  }
5828
5846
  catch (e) {
5829
5847
  console.log(` [cloud-poll] ${filename} check skipped: ${e?.message || e}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx-imap",
3
- "version": "0.1.111",
3
+ "version": "0.1.113",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -9,13 +9,13 @@
9
9
  },
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
- "@bobfrankston/mailx-types": "^0.1.21",
13
- "@bobfrankston/mailx-settings": "^0.1.32",
14
- "@bobfrankston/mailx-store": "^0.1.56",
12
+ "@bobfrankston/mailx-types": "^0.1.22",
13
+ "@bobfrankston/mailx-settings": "^0.1.33",
14
+ "@bobfrankston/mailx-store": "^0.1.58",
15
15
  "@bobfrankston/iflow-direct": "^0.1.56",
16
16
  "@bobfrankston/tcp-transport": "^0.1.7",
17
17
  "@bobfrankston/smtp-direct": "^0.1.9",
18
- "@bobfrankston/mailx-sync": "^0.1.25",
18
+ "@bobfrankston/mailx-sync": "^0.1.27",
19
19
  "@bobfrankston/oauthsupport": "^1.0.33"
20
20
  },
21
21
  "repository": {
@@ -37,13 +37,13 @@
37
37
  },
38
38
  ".transformedSnapshot": {
39
39
  "dependencies": {
40
- "@bobfrankston/mailx-types": "^0.1.21",
41
- "@bobfrankston/mailx-settings": "^0.1.32",
42
- "@bobfrankston/mailx-store": "^0.1.56",
40
+ "@bobfrankston/mailx-types": "^0.1.22",
41
+ "@bobfrankston/mailx-settings": "^0.1.33",
42
+ "@bobfrankston/mailx-store": "^0.1.58",
43
43
  "@bobfrankston/iflow-direct": "^0.1.56",
44
44
  "@bobfrankston/tcp-transport": "^0.1.7",
45
45
  "@bobfrankston/smtp-direct": "^0.1.9",
46
- "@bobfrankston/mailx-sync": "^0.1.25",
46
+ "@bobfrankston/mailx-sync": "^0.1.27",
47
47
  "@bobfrankston/oauthsupport": "^1.0.33"
48
48
  }
49
49
  }