@bobfrankston/mailx-store 0.1.14 → 0.1.15

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 +1 -1
  2. package/db.js +15 -4
  3. package/package.json +1 -1
package/db.d.ts CHANGED
@@ -436,7 +436,7 @@ export declare class MailxDB {
436
436
  * contact can have multiple email addresses, each is its own row). */
437
437
  deleteContactByGoogleId(googleId: string): number;
438
438
  /** Full-text search across all messages. Supports qualifiers: from:, to:, subject: */
439
- searchMessages(query: string, page?: number, pageSize?: number, accountId?: string, folderId?: number): PagedResult<MessageEnvelope>;
439
+ searchMessages(query: string, page?: number, pageSize?: number, accountId?: string, folderId?: number, includeTrashSpam?: boolean): PagedResult<MessageEnvelope>;
440
440
  /** Rebuild FTS index from existing messages */
441
441
  rebuildSearchIndex(): number;
442
442
  /** Queue a local action for later sync to IMAP */
package/db.js CHANGED
@@ -488,12 +488,12 @@ export class MailxDB {
488
488
  actual = this.db.prepare(`PRAGMA table_info(${table})`).all();
489
489
  }
490
490
  catch (e) {
491
- throw new Error(`[mailx-store] schema check failed for "${table}": ${e.message}. Run 'mailx -rebuild' to rebuild the local store.`);
491
+ throw new Error(`[mailx-store] schema check failed for "${table}": ${e.message}. Run 'rmfmail -rebuild' to rebuild the local store.`);
492
492
  }
493
493
  const names = new Set(actual.map(r => r.name));
494
494
  const missing = cols.filter(c => !names.has(c));
495
495
  if (missing.length > 0) {
496
- throw new Error(`[mailx-store] table "${table}" is missing columns [${missing.join(", ")}] — schema migration did not complete. Run 'mailx -rebuild' to rebuild the local store.`);
496
+ throw new Error(`[mailx-store] table "${table}" is missing columns [${missing.join(", ")}] — schema migration did not complete. Run 'rmfmail -rebuild' to rebuild the local store.`);
497
497
  }
498
498
  }
499
499
  this.runOneShotJunkContactPurge();
@@ -2051,7 +2051,7 @@ export class MailxDB {
2051
2051
  }
2052
2052
  // ── Search ──
2053
2053
  /** Full-text search across all messages. Supports qualifiers: from:, to:, subject: */
2054
- searchMessages(query, page = 1, pageSize = 50, accountId, folderId) {
2054
+ searchMessages(query, page = 1, pageSize = 50, accountId, folderId, includeTrashSpam = false) {
2055
2055
  query = (query || "").trim();
2056
2056
  // Parse qualifiers (C45: extended set — date:, has:, is:, folder:).
2057
2057
  let ftsQuery = "";
@@ -2179,11 +2179,22 @@ export class MailxDB {
2179
2179
  scopeWhere = " AND m.account_id = ?";
2180
2180
  scopeParams.push(accountId);
2181
2181
  }
2182
+ // Global / account-wide search excludes trash + junk unless the
2183
+ // user opted in. A user typing "invoice" in the search box almost
2184
+ // never wants the deleted/spam copy that's already filtered out
2185
+ // of every other view. When the user IS explicitly scoped to
2186
+ // trash/junk via folderId, this guard is skipped.
2187
+ if (!includeTrashSpam && !folderId) {
2188
+ scopeWhere += " AND (f.special_use IS NULL OR f.special_use NOT IN ('trash','junk'))";
2189
+ }
2182
2190
  if (extraWhere.length > 0) {
2183
2191
  scopeWhere += " AND " + extraWhere.join(" AND ");
2184
2192
  scopeParams.push(...extraParams);
2185
2193
  }
2186
- const countRow = this.db.prepare(`SELECT COUNT(*) as cnt FROM messages m JOIN messages_fts fts ON m.id = fts.rowid WHERE messages_fts MATCH ?${scopeWhere}`).get(ftsQuery, ...scopeParams);
2194
+ const countRow = this.db.prepare(`SELECT COUNT(*) as cnt FROM messages m
2195
+ JOIN messages_fts fts ON m.id = fts.rowid
2196
+ LEFT JOIN folders f ON f.id = m.folder_id AND f.account_id = m.account_id
2197
+ WHERE messages_fts MATCH ?${scopeWhere}`).get(ftsQuery, ...scopeParams);
2187
2198
  const total = countRow?.cnt || 0;
2188
2199
  const rows = this.db.prepare(`SELECT m.*, f.name AS folder_name FROM messages m
2189
2200
  JOIN messages_fts fts ON m.id = fts.rowid
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx-store",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",