@bobfrankston/mailx-store 0.1.41 → 0.1.43
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/db.d.ts +12 -4
- package/db.js +60 -8
- package/package.json +3 -3
package/db.d.ts
CHANGED
|
@@ -334,15 +334,23 @@ export declare class MailxDB {
|
|
|
334
334
|
findPendingSyncAction(accountId: string, action: string, uid: number, folderId: number, targetFolderId?: number): {
|
|
335
335
|
id: number;
|
|
336
336
|
} | null;
|
|
337
|
-
|
|
337
|
+
/** folderId REQUIRED — same UID-collision bug class as deleteMessage /
|
|
338
|
+
* updateMessageFlags. The same numeric UID exists in many folders for
|
|
339
|
+
* DIFFERENT messages; a (account, uid) UPDATE writes the body_path onto
|
|
340
|
+
* EVERY folder's uid=N row, so 22 unrelated messages ended up sharing one
|
|
341
|
+
* .eml and showed each other's bodies (Bob 2026-05-29 — subject/letter
|
|
342
|
+
* mismatch). Never write body_path without folder_id. */
|
|
343
|
+
updateBodyPath(accountId: string, folderId: number, uid: number, bodyPath: string): void;
|
|
338
344
|
/** Write the post-download metadata in one go: body file path, parsed
|
|
339
345
|
* attachment flag, preview text, and the parse timestamp. Called from
|
|
340
346
|
* prefetch after the body has been written to disk and parsed — without
|
|
341
347
|
* this, IMAP metadata-only sync leaves has_attachments=0 and preview=""
|
|
342
348
|
* forever (the paperclip 📎 never renders for non-Gmail accounts).
|
|
343
349
|
* Pass bodyPath = "" to update only the parsed fields (used by the
|
|
344
|
-
* backfill worker re-parsing existing .eml files on disk).
|
|
345
|
-
|
|
350
|
+
* backfill worker re-parsing existing .eml files on disk).
|
|
351
|
+
* folderId REQUIRED — see updateBodyPath: the (account, uid) form
|
|
352
|
+
* cross-wired body_path across every folder sharing the numeric UID. */
|
|
353
|
+
updateBodyMeta(accountId: string, folderId: number, uid: number, bodyPath: string, hasAttachments: boolean, preview: string): void;
|
|
346
354
|
/** Find rows whose body is on disk but was never run through extractPreview
|
|
347
355
|
* (has_attachments/preview reflect "no body source at sync time", typical
|
|
348
356
|
* of the IMAP metadata-only path). Used by the backfill worker to walk
|
|
@@ -363,7 +371,7 @@ export declare class MailxDB {
|
|
|
363
371
|
* reply arrives. Idempotent — UPDATE on an already-1 row is a no-op. */
|
|
364
372
|
markRepliedByMessageId(accountId: string, messageId: string): boolean;
|
|
365
373
|
/** Get messages without cached bodies (for background prefetch) */
|
|
366
|
-
getMessagesWithoutBody(accountId: string, limit?: number): {
|
|
374
|
+
getMessagesWithoutBody(accountId: string, limit?: number, excludeFolderIds?: number[]): {
|
|
367
375
|
uid: number;
|
|
368
376
|
folderId: number;
|
|
369
377
|
}[];
|
package/db.js
CHANGED
|
@@ -501,6 +501,40 @@ export class MailxDB {
|
|
|
501
501
|
catch (e) {
|
|
502
502
|
console.error(` [migration] synthetic-UID cleanup failed: ${e?.message || e}`);
|
|
503
503
|
}
|
|
504
|
+
// Heal body_path cross-wiring caused by the pre-fix updateBodyMeta /
|
|
505
|
+
// updateBodyPath (which wrote body_path WHERE (account, uid) with no
|
|
506
|
+
// folder_id, so 22+ unrelated messages sharing a numeric UID across
|
|
507
|
+
// folders ended up pointing at ONE .eml and rendered each other's
|
|
508
|
+
// bodies — Bob 2026-05-29 "subject and summary unrelated"). Any
|
|
509
|
+
// body_path referenced by more than one row is, by construction,
|
|
510
|
+
// cross-wired (each (folder,uid) gets its own .eml via putMessage).
|
|
511
|
+
// Clear those rows' body_path + body_parsed_at so the prefetch /
|
|
512
|
+
// on-demand fetch re-downloads the CORRECT body per (folder, uid) with
|
|
513
|
+
// the now-folder-scoped writers. This is a cache re-download, not a
|
|
514
|
+
// data backfill — safe. KV-flagged so it runs once.
|
|
515
|
+
try {
|
|
516
|
+
const healedFlag = this.getKv("schema", "fix_crosswired_bodypath_v1");
|
|
517
|
+
if (!healedFlag) {
|
|
518
|
+
const r = this.db.prepare(`
|
|
519
|
+
UPDATE messages SET body_path = '', body_parsed_at = NULL
|
|
520
|
+
WHERE body_path IS NOT NULL AND body_path != ''
|
|
521
|
+
AND body_path IN (
|
|
522
|
+
SELECT body_path FROM messages
|
|
523
|
+
WHERE body_path IS NOT NULL AND body_path != ''
|
|
524
|
+
GROUP BY body_path HAVING COUNT(*) > 1
|
|
525
|
+
)
|
|
526
|
+
`).run();
|
|
527
|
+
const count = r.changes || 0;
|
|
528
|
+
if (count > 0) {
|
|
529
|
+
console.log(` [migration] cleared ${count} cross-wired body_path rows — will re-fetch correct bodies`);
|
|
530
|
+
this.audit({ kind: "migration", count, reason: "fix_crosswired_bodypath_v1 — clear body_path shared across multiple (folder,uid) rows", source: "MailxDB constructor" });
|
|
531
|
+
}
|
|
532
|
+
this.setKv("schema", "fix_crosswired_bodypath_v1", "1");
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
catch (e) {
|
|
536
|
+
console.error(` [migration] body_path cross-wire cleanup failed: ${e?.message || e}`);
|
|
537
|
+
}
|
|
504
538
|
// One-shot: backfill message_folders from existing messages rows.
|
|
505
539
|
// After this runs, every existing (account, folder, uid) row in
|
|
506
540
|
// messages has a corresponding membership row in message_folders.
|
|
@@ -1913,8 +1947,14 @@ export class MailxDB {
|
|
|
1913
1947
|
const r = this.db.prepare(sql).get(...params);
|
|
1914
1948
|
return r || null;
|
|
1915
1949
|
}
|
|
1916
|
-
|
|
1917
|
-
|
|
1950
|
+
/** folderId REQUIRED — same UID-collision bug class as deleteMessage /
|
|
1951
|
+
* updateMessageFlags. The same numeric UID exists in many folders for
|
|
1952
|
+
* DIFFERENT messages; a (account, uid) UPDATE writes the body_path onto
|
|
1953
|
+
* EVERY folder's uid=N row, so 22 unrelated messages ended up sharing one
|
|
1954
|
+
* .eml and showed each other's bodies (Bob 2026-05-29 — subject/letter
|
|
1955
|
+
* mismatch). Never write body_path without folder_id. */
|
|
1956
|
+
updateBodyPath(accountId, folderId, uid, bodyPath) {
|
|
1957
|
+
this.db.prepare("UPDATE messages SET body_path = ? WHERE account_id = ? AND folder_id = ? AND uid = ?").run(bodyPath, accountId, folderId, uid);
|
|
1918
1958
|
}
|
|
1919
1959
|
/** Write the post-download metadata in one go: body file path, parsed
|
|
1920
1960
|
* attachment flag, preview text, and the parse timestamp. Called from
|
|
@@ -1922,13 +1962,15 @@ export class MailxDB {
|
|
|
1922
1962
|
* this, IMAP metadata-only sync leaves has_attachments=0 and preview=""
|
|
1923
1963
|
* forever (the paperclip 📎 never renders for non-Gmail accounts).
|
|
1924
1964
|
* Pass bodyPath = "" to update only the parsed fields (used by the
|
|
1925
|
-
* backfill worker re-parsing existing .eml files on disk).
|
|
1926
|
-
|
|
1965
|
+
* backfill worker re-parsing existing .eml files on disk).
|
|
1966
|
+
* folderId REQUIRED — see updateBodyPath: the (account, uid) form
|
|
1967
|
+
* cross-wired body_path across every folder sharing the numeric UID. */
|
|
1968
|
+
updateBodyMeta(accountId, folderId, uid, bodyPath, hasAttachments, preview) {
|
|
1927
1969
|
if (bodyPath) {
|
|
1928
|
-
this.db.prepare("UPDATE messages SET body_path = ?, has_attachments = ?, preview = ?, body_parsed_at = ? WHERE account_id = ? AND uid = ?").run(bodyPath, hasAttachments ? 1 : 0, preview, Date.now(), accountId, uid);
|
|
1970
|
+
this.db.prepare("UPDATE messages SET body_path = ?, has_attachments = ?, preview = ?, body_parsed_at = ? WHERE account_id = ? AND folder_id = ? AND uid = ?").run(bodyPath, hasAttachments ? 1 : 0, preview, Date.now(), accountId, folderId, uid);
|
|
1929
1971
|
}
|
|
1930
1972
|
else {
|
|
1931
|
-
this.db.prepare("UPDATE messages SET has_attachments = ?, preview = ?, body_parsed_at = ? WHERE account_id = ? AND uid = ?").run(hasAttachments ? 1 : 0, preview, Date.now(), accountId, uid);
|
|
1973
|
+
this.db.prepare("UPDATE messages SET has_attachments = ?, preview = ?, body_parsed_at = ? WHERE account_id = ? AND folder_id = ? AND uid = ?").run(hasAttachments ? 1 : 0, preview, Date.now(), accountId, folderId, uid);
|
|
1932
1974
|
}
|
|
1933
1975
|
}
|
|
1934
1976
|
/** Find rows whose body is on disk but was never run through extractPreview
|
|
@@ -1956,14 +1998,24 @@ export class MailxDB {
|
|
|
1956
1998
|
return r.changes > 0;
|
|
1957
1999
|
}
|
|
1958
2000
|
/** Get messages without cached bodies (for background prefetch) */
|
|
1959
|
-
getMessagesWithoutBody(accountId, limit = 50) {
|
|
2001
|
+
getMessagesWithoutBody(accountId, limit = 50, excludeFolderIds = []) {
|
|
1960
2002
|
// Prefetch order: smallest first, NULLs last, recent within tiebreak.
|
|
1961
2003
|
// Reasoning: on slow / metered Android networks, the user feels the
|
|
1962
2004
|
// cache "fill up" much faster when the queue is dominated by short
|
|
1963
2005
|
// notification mails (a handful of KB each) instead of a single
|
|
1964
2006
|
// multi-megabyte attachment that monopolizes bandwidth for minutes.
|
|
1965
2007
|
// Size 0 / NULL fall to the end so they don't masquerade as small.
|
|
1966
|
-
|
|
2008
|
+
//
|
|
2009
|
+
// excludeFolderIds: folders the caller has put in error-cooldown. We
|
|
2010
|
+
// exclude them HERE (at the query) rather than after slicing, because a
|
|
2011
|
+
// single bloated/failing folder (e.g. a server-side Outbox stuffed with
|
|
2012
|
+
// hundreds of stuck messages) would otherwise fill the entire size-asc
|
|
2013
|
+
// result and starve every healthy folder of its prefetch turn — the
|
|
2014
|
+
// "so much unfetched, nothing draining" symptom (Bob 2026-06-01).
|
|
2015
|
+
const exclusion = excludeFolderIds.length
|
|
2016
|
+
? ` AND folder_id NOT IN (${excludeFolderIds.map(() => "?").join(",")})`
|
|
2017
|
+
: "";
|
|
2018
|
+
return this.db.prepare(`SELECT uid, folder_id as folderId FROM messages WHERE account_id = ? AND (body_path IS NULL OR body_path = '')${exclusion} ORDER BY (size IS NULL OR size = 0), size ASC, date DESC LIMIT ?`).all(accountId, ...excludeFolderIds, limit);
|
|
1967
2019
|
}
|
|
1968
2020
|
/** Highest server UID we've seen in this folder. After the
|
|
1969
2021
|
* message_folders refactor, this reads from the membership table
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bobfrankston/mailx-store",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.43",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@bobfrankston/mailx-types": "^0.1.18",
|
|
13
|
-
"@bobfrankston/mailx-settings": "^0.1.
|
|
13
|
+
"@bobfrankston/mailx-settings": "^0.1.26",
|
|
14
14
|
"@bobfrankston/mailx-bus": "^0.1.2",
|
|
15
15
|
"mailparser": "^3.7.2"
|
|
16
16
|
},
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
".transformedSnapshot": {
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@bobfrankston/mailx-types": "^0.1.18",
|
|
33
|
-
"@bobfrankston/mailx-settings": "^0.1.
|
|
33
|
+
"@bobfrankston/mailx-settings": "^0.1.26",
|
|
34
34
|
"@bobfrankston/mailx-bus": "^0.1.2",
|
|
35
35
|
"mailparser": "^3.7.2"
|
|
36
36
|
}
|