@bobfrankston/mailx-store 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.
Files changed (3) hide show
  1. package/db.d.ts +6 -0
  2. package/db.js +23 -1
  3. package/package.json +3 -3
package/db.d.ts CHANGED
@@ -224,6 +224,12 @@ export declare class MailxDB {
224
224
  bodyPath: string;
225
225
  providerId?: string;
226
226
  }): number;
227
+ /** Backfill the FTS5 `body_text` column for a message after its body
228
+ * has been parsed. Capped at ~64 KB of text per row — FTS5 stores the
229
+ * raw text and indexes tokens; we don't need every byte of a 1 MB
230
+ * marketing email to find a word in the first paragraph. Called from
231
+ * LocalStore.getMessage right after simpleParser succeeds. */
232
+ updateFtsBodyByUid(accountId: string, folderId: number, uid: number, bodyText: string): void;
227
233
  /** List view: messages currently in (account, folder).
228
234
  * Joins through `message_folders` so the UID + folder location come
229
235
  * from membership rows, not from the legacy messages.folder_id /
package/db.js CHANGED
@@ -1372,13 +1372,35 @@ export class MailxDB {
1372
1372
  // sync during the additive migration but reads will move to JOIN
1373
1373
  // with message_folders.
1374
1374
  this.upsertMessageFolder(rowId, msg.folderId, msg.uid);
1375
- // Index for full-text search
1375
+ // Index for full-text search. body_text seeded from `msg.preview`
1376
+ // here — the full parsed body isn't available at upsert time (we
1377
+ // store .eml on disk; parsing is on-demand). LocalStore.getMessage
1378
+ // calls `updateFtsBodyByUid` after simpleParser runs to swap the
1379
+ // preview-only seed for the full body text, so subsequent searches
1380
+ // hit body content too. Without that backfill, words that only
1381
+ // appear deep in the body (Bob 2026-05-12: "I searched for ksink
1382
+ // which is in <...>.eml but it was not found") never match.
1376
1383
  try {
1377
1384
  this.db.prepare("INSERT INTO messages_fts (rowid, subject, from_name, from_address, to_text, cc_text, body_text) VALUES (?, ?, ?, ?, ?, ?, ?)").run(rowId, msg.subject, msg.from.name, msg.from.address, toText, ccText, msg.preview);
1378
1385
  }
1379
1386
  catch { /* FTS insert may fail on rebuild, non-fatal */ }
1380
1387
  return rowId;
1381
1388
  }
1389
+ /** Backfill the FTS5 `body_text` column for a message after its body
1390
+ * has been parsed. Capped at ~64 KB of text per row — FTS5 stores the
1391
+ * raw text and indexes tokens; we don't need every byte of a 1 MB
1392
+ * marketing email to find a word in the first paragraph. Called from
1393
+ * LocalStore.getMessage right after simpleParser succeeds. */
1394
+ updateFtsBodyByUid(accountId, folderId, uid, bodyText) {
1395
+ try {
1396
+ const row = this.db.prepare("SELECT id FROM messages WHERE account_id = ? AND folder_id = ? AND uid = ?").get(accountId, folderId, uid);
1397
+ if (!row)
1398
+ return;
1399
+ const capped = bodyText.length > 64_000 ? bodyText.slice(0, 64_000) : bodyText;
1400
+ this.db.prepare("UPDATE messages_fts SET body_text = ? WHERE rowid = ?").run(capped, row.id);
1401
+ }
1402
+ catch { /* FTS update is best-effort */ }
1403
+ }
1382
1404
  /** List view: messages currently in (account, folder).
1383
1405
  * Joins through `message_folders` so the UID + folder location come
1384
1406
  * from membership rows, not from the legacy messages.folder_id /
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx-store",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
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.11",
13
- "@bobfrankston/mailx-settings": "^0.1.15"
13
+ "@bobfrankston/mailx-settings": "^0.1.16"
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
@@ -26,7 +26,7 @@
26
26
  ".transformedSnapshot": {
27
27
  "dependencies": {
28
28
  "@bobfrankston/mailx-types": "^0.1.11",
29
- "@bobfrankston/mailx-settings": "^0.1.15"
29
+ "@bobfrankston/mailx-settings": "^0.1.16"
30
30
  }
31
31
  }
32
32
  }