@bobfrankston/mailx 1.0.122 → 1.0.123

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/client/app.js CHANGED
@@ -546,18 +546,25 @@ onWsEvent((event) => {
546
546
  statusSync.textContent = `Syncing ${event.accountId}: ${event.phase} ${event.progress || 0}%`;
547
547
  if (startupStatus)
548
548
  startupStatus.textContent = `Syncing ${event.accountId}: ${event.phase}`;
549
- // Mark syncing folder in tree
549
+ // Mark syncing folder in tree — bubble up to visible parent if collapsed
550
550
  const syncPath = event.phase?.startsWith("sync:") ? event.phase.slice(5) : null;
551
551
  // Clear previous syncing markers for this account
552
552
  document.querySelectorAll(`.ft-folder.ft-syncing[data-account-id="${event.accountId}"]`).forEach(el => el.classList.remove("ft-syncing"));
553
- if (syncPath) {
554
- const folderEl = document.querySelector(`.ft-folder[data-account-id="${event.accountId}"][data-folder-path="${CSS.escape(syncPath)}"]`);
555
- if (folderEl) {
556
- if (event.progress < 100)
557
- folderEl.classList.add("ft-syncing");
558
- else
559
- folderEl.classList.remove("ft-syncing");
553
+ if (syncPath && event.progress < 100) {
554
+ // Try exact match first
555
+ let folderEl = document.querySelector(`.ft-folder[data-account-id="${event.accountId}"][data-folder-path="${CSS.escape(syncPath)}"]`);
556
+ if (!folderEl) {
557
+ // Folder not visible (parent collapsed) — find nearest visible ancestor
558
+ const parts = syncPath.split(/[./]/);
559
+ for (let i = parts.length - 1; i >= 1; i--) {
560
+ const parentPath = parts.slice(0, i).join(".");
561
+ folderEl = document.querySelector(`.ft-folder[data-account-id="${event.accountId}"][data-folder-path="${CSS.escape(parentPath)}"]`);
562
+ if (folderEl)
563
+ break;
564
+ }
560
565
  }
566
+ if (folderEl)
567
+ folderEl.classList.add("ft-syncing");
561
568
  }
562
569
  break;
563
570
  }
@@ -74,6 +74,19 @@ function buildTree(folders, delimiter, accountId) {
74
74
  root.push(node);
75
75
  }
76
76
  }
77
+ // Aggregate counts from children to parents (so collapsed parents show totals)
78
+ function aggregateCounts(nodes) {
79
+ let unread = 0, total = 0;
80
+ for (const n of nodes) {
81
+ const child = aggregateCounts(n.children);
82
+ n.unreadCount += child.unread;
83
+ n.totalCount += child.total;
84
+ unread += n.unreadCount;
85
+ total += n.totalCount;
86
+ }
87
+ return { unread, total };
88
+ }
89
+ aggregateCounts(root);
77
90
  return root;
78
91
  }
79
92
  /** Sort: INBOX first, then special folders, then alphabetical */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx",
3
- "version": "1.0.122",
3
+ "version": "1.0.123",
4
4
  "description": "Local-first email client with IMAP sync and standalone native app",
5
5
  "type": "module",
6
6
  "main": "bin/mailx.js",
@@ -319,15 +319,15 @@ export class ImapManager extends EventEmitter {
319
319
  ? new Date(Date.now() - historyDays * 86400000)
320
320
  : new Date(0);
321
321
  if (highestUid > 0) {
322
- // Incremental: only fetch messages newer than what we have
323
- const fetched = await client.fetchMessagesSinceUid(folder.path, highestUid, { source: true });
322
+ // Incremental: fetch new messages metadata only for speed, bodies on demand
323
+ const fetched = await client.fetchMessagesSinceUid(folder.path, highestUid, { source: false });
324
324
  // Filter out the last known message (IMAP * always returns at least one)
325
325
  messages = fetched.filter(m => m.uid > highestUid);
326
326
  // Backfill: if historyDays extends further back than our oldest message, fetch the gap
327
327
  const oldestDate = this.db.getOldestDate(accountId, folderId);
328
328
  if (oldestDate > 0 && startDate.getTime() < oldestDate) {
329
329
  const existingUids = new Set(this.db.getUidsForFolder(accountId, folderId));
330
- const backfill = await client.fetchMessageByDate(folder.path, startDate, new Date(oldestDate), { source: true });
330
+ const backfill = await client.fetchMessageByDate(folder.path, startDate, new Date(oldestDate), { source: false });
331
331
  const newBackfill = backfill.filter(m => !existingUids.has(m.uid));
332
332
  if (newBackfill.length > 0) {
333
333
  console.log(` ${folder.path}: backfilling ${newBackfill.length} older messages`);
@@ -336,8 +336,8 @@ export class ImapManager extends EventEmitter {
336
336
  }
337
337
  }
338
338
  else {
339
- // First sync: use date-based fetch with bodies for local-first
340
- messages = await client.fetchMessageByDate(folder.path, startDate, new Date(), { source: true });
339
+ // First sync: metadata only bodies fetched on demand when user clicks a message
340
+ messages = await client.fetchMessageByDate(folder.path, startDate, new Date(), { source: false });
341
341
  }
342
342
  // Sort newest first so most recent messages appear in the UI immediately
343
343
  messages.sort((a, b) => {