@bobfrankston/mailx 1.0.46 → 1.0.47

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/bin/mailx.js CHANGED
@@ -28,14 +28,15 @@ const verbose = hasFlag("verbose");
28
28
  const setupMode = hasFlag("setup");
29
29
  const addMode = hasFlag("add");
30
30
  const testMode = hasFlag("test");
31
+ const rebuildMode = hasFlag("rebuild");
31
32
 
32
33
  // Validate arguments
33
- const knownFlags = ["server", "no-browser", "verbose", "external", "kill", "v", "version", "setup", "add", "test"];
34
+ const knownFlags = ["server", "no-browser", "verbose", "external", "kill", "v", "version", "setup", "add", "test", "rebuild"];
34
35
  for (const arg of args) {
35
36
  const flag = arg.replace(/^--?/, "");
36
37
  if (arg.startsWith("-") && !knownFlags.includes(flag)) {
37
38
  console.error(`Unknown option: ${arg}`);
38
- console.error("Usage: mailx [-server] [-verbose] [-kill] [-v] [-setup] [-no-browser] [-external]");
39
+ console.error("Usage: mailx [-server] [-verbose] [-kill] [-rebuild] [-v] [-setup] [-no-browser] [-external]");
39
40
  process.exit(1);
40
41
  }
41
42
  }
@@ -86,6 +87,31 @@ if (hasFlag("kill")) {
86
87
  process.exit(0);
87
88
  }
88
89
 
90
+ // Rebuild: wipe DB + message store, keep accounts/settings
91
+ if (rebuildMode) {
92
+ const { getConfigDir, getStorePath } = await import("@bobfrankston/mailx-settings");
93
+ const dbDir = getConfigDir();
94
+ const storePath = getStorePath();
95
+
96
+ console.log("Rebuilding mailx local cache...");
97
+ console.log(" Accounts and settings will be preserved.");
98
+
99
+ // Remove DB files
100
+ for (const f of ["mailx.db", "mailx.db-wal", "mailx.db-shm"]) {
101
+ const p = path.join(dbDir, f);
102
+ if (fs.existsSync(p)) { fs.unlinkSync(p); console.log(` Deleted ${f}`); }
103
+ }
104
+
105
+ // Remove message store
106
+ if (fs.existsSync(storePath)) {
107
+ fs.rmSync(storePath, { recursive: true });
108
+ console.log(` Deleted message store`);
109
+ }
110
+
111
+ console.log(" Rebuild complete. Run 'mailx' to start fresh.");
112
+ process.exit(0);
113
+ }
114
+
89
115
  // Version
90
116
  if (hasFlag("v") || hasFlag("version")) {
91
117
  const root = path.join(import.meta.dirname, "..");
package/client/index.html CHANGED
@@ -24,6 +24,7 @@
24
24
  <div class="tb-menu-dropdown" id="view-dropdown" hidden>
25
25
  <label class="tb-menu-item"><input type="checkbox" id="opt-two-line"> Two-line view</label>
26
26
  <label class="tb-menu-item"><input type="checkbox" id="opt-preview" checked> Preview pane</label>
27
+ <label class="tb-menu-item"><input type="checkbox" id="opt-snippet" checked> Preview snippets</label>
27
28
  <label class="tb-menu-item"><input type="checkbox" id="opt-flagged"> ★ Flagged only</label>
28
29
  </div>
29
30
  </div>
@@ -33,9 +34,17 @@
33
34
  <button class="tb-btn" id="btn-sync" title="Sync all folders (F5)">
34
35
  <span class="tb-icon">↻</span> Sync
35
36
  </button>
36
- <button class="tb-btn" id="btn-restart" title="Restart server and reload page">
37
- <span class="tb-icon">⚡</span> Restart
38
- </button>
37
+ <div class="tb-menu" id="restart-menu">
38
+ <button class="tb-btn" id="btn-restart" title="Restart server and reload page">
39
+ <span class="tb-icon">⚡</span> Restart ▾
40
+ </button>
41
+ <div class="tb-menu-dropdown" id="restart-dropdown" hidden>
42
+ <button class="tb-menu-item" id="btn-restart-quick" title="Restart the server process">Restart server</button>
43
+ <button class="tb-menu-item" id="btn-rebuild" title="Wipe local DB and message cache, re-download everything. Accounts and settings are preserved. Safe and fast.">Rebuild local cache</button>
44
+ <hr class="tb-menu-sep">
45
+ <span class="tb-menu-hint">CLI: mailx --rebuild for full reset</span>
46
+ </div>
47
+ </div>
39
48
  </div>
40
49
  </header>
41
50
 
@@ -91,6 +91,9 @@
91
91
  }
92
92
  .tb-menu-item:hover { background: var(--color-bg-hover); }
93
93
  .tb-menu-item input[type="checkbox"] { accent-color: var(--color-accent); }
94
+ button.tb-menu-item { background: none; border: none; color: inherit; width: 100%; text-align: left; }
95
+ .tb-menu-sep { border: none; border-top: 1px solid var(--color-border); margin: var(--gap-xs) 0; }
96
+ .tb-menu-hint { display: block; padding: var(--gap-xs) var(--gap-md); font-size: 0.75rem; color: var(--color-text-muted); }
94
97
  .tb-sep { width: 1px; height: 1.2rem; background: var(--color-border); margin: 0 var(--gap-xs); }
95
98
 
96
99
  .search-bar {
@@ -338,6 +341,7 @@
338
341
  margin-left: var(--gap-xs);
339
342
  }
340
343
  }
344
+ .no-snippets .ml-preview { display: none; }
341
345
  .ml-date { white-space: nowrap; text-align: right; color: var(--color-text-muted); font-family: var(--font-mono); font-size: var(--font-size-sm); }
342
346
 
343
347
  .ml-empty {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx",
3
- "version": "1.0.46",
3
+ "version": "1.0.47",
4
4
  "description": "Local-first email client with IMAP sync and standalone native app",
5
5
  "type": "module",
6
6
  "main": "bin/mailx.js",
@@ -20,7 +20,7 @@
20
20
  "postinstall": "node launcher/builder/postinstall.js"
21
21
  },
22
22
  "dependencies": {
23
- "@bobfrankston/iflow": "^1.0.26",
23
+ "@bobfrankston/iflow": "^1.0.28",
24
24
  "@bobfrankston/miscinfo": "^1.0.6",
25
25
  "@bobfrankston/oauthsupport": "^1.0.11",
26
26
  "@bobfrankston/rust-builder": "^0.1.2",
@@ -6,7 +6,7 @@
6
6
  import { ImapClient, createAutoImapConfig } from "@bobfrankston/iflow";
7
7
  import { authenticateOAuth } from "@bobfrankston/oauthsupport";
8
8
  import { FileMessageStore } from "@bobfrankston/mailx-store";
9
- import { loadSettings, getStorePath } from "@bobfrankston/mailx-settings";
9
+ import { loadSettings, getStorePath, getConfigDir } from "@bobfrankston/mailx-settings";
10
10
  import { EventEmitter } from "node:events";
11
11
  import * as fs from "node:fs";
12
12
  import * as path from "node:path";
@@ -26,13 +26,23 @@ function toEmailAddresses(addrs) {
26
26
  return [];
27
27
  return addrs.map(toEmailAddress);
28
28
  }
29
+ /** Decode HTML entities (&#8199; &amp; etc.) to plain characters */
30
+ function decodeEntities(text) {
31
+ return text
32
+ .replace(/&#(\d+);/g, (_, n) => String.fromCodePoint(Number(n)))
33
+ .replace(/&#x([0-9a-fA-F]+);/g, (_, h) => String.fromCodePoint(parseInt(h, 16)))
34
+ .replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">")
35
+ .replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&nbsp;/g, " ");
36
+ }
29
37
  /** Extract a plain-text preview from message source */
30
38
  async function extractPreview(source) {
31
39
  try {
32
40
  const parsed = await simpleParser(source);
33
41
  const bodyText = parsed.text || "";
34
42
  const bodyHtml = parsed.html || "";
35
- const preview = bodyText.replace(/\s+/g, " ").trim().slice(0, 200);
43
+ // Use text part; fall back to stripping HTML tags if text is empty
44
+ let raw = bodyText || bodyHtml.replace(/<[^>]+>/g, " ");
45
+ const preview = decodeEntities(raw).replace(/\s+/g, " ").trim().slice(0, 200);
36
46
  const hasAttachments = (parsed.attachments?.length || 0) > 0;
37
47
  return { bodyHtml, bodyText, preview, hasAttachments };
38
48
  }
@@ -105,11 +115,13 @@ export class ImapManager extends EventEmitter {
105
115
  if (this.configs.has(account.id))
106
116
  return;
107
117
  // createAutoImapConfig auto-detects Gmail from server/username and sets up OAuth
118
+ // Token directory in ~/.mailx/ so tokens persist across npm reinstalls
108
119
  const config = createAutoImapConfig({
109
120
  server: account.imap.host,
110
121
  port: account.imap.port,
111
122
  username: account.imap.user,
112
- password: account.imap.password
123
+ password: account.imap.password,
124
+ tokenDirectory: getConfigDir()
113
125
  });
114
126
  this.configs.set(account.id, config);
115
127
  // Register account in DB
@@ -9,7 +9,7 @@ import * as fs from "node:fs";
9
9
  import { MailxDB } from "@bobfrankston/mailx-store";
10
10
  import { ImapManager } from "@bobfrankston/mailx-imap";
11
11
  import { createApiRouter } from "@bobfrankston/mailx-api";
12
- import { loadSettings, getConfigDir, getSharedDir, initLocalConfig } from "@bobfrankston/mailx-settings";
12
+ import { loadSettings, getConfigDir, getStorePath, getSharedDir, initLocalConfig } from "@bobfrankston/mailx-settings";
13
13
  import { ports } from "@bobfrankston/miscinfo";
14
14
  import { createServer } from "node:http";
15
15
  const PORT = ports.mailx;
@@ -67,7 +67,7 @@ app.use((req, res, next) => {
67
67
  res.on("finish", () => {
68
68
  const ms = Date.now() - start;
69
69
  // Skip noisy polling endpoints
70
- if (req.path === "/api/sync/pending")
70
+ if (req.path.endsWith("/sync/pending"))
71
71
  return;
72
72
  console.log(` ${req.method} ${req.path} ${res.statusCode} ${ms}ms`);
73
73
  });
@@ -125,12 +125,43 @@ ${accountInfo.map((a) => `<tr><td>${a.name}</td><td>${a.folders}</td><td>${a.inb
125
125
  app.post("/api/restart", (req, res) => {
126
126
  res.json({ ok: true });
127
127
  broadcast({ type: "reload" });
128
- // Graceful shutdown — node --watch will auto-restart
129
128
  setTimeout(async () => {
130
129
  console.log(" Restart requested via API");
131
130
  await shutdown();
132
131
  }, 500);
133
132
  });
133
+ // Rebuild: wipe DB + message store, keep accounts/settings, restart
134
+ app.post("/api/rebuild", (req, res) => {
135
+ res.json({ ok: true });
136
+ broadcast({ type: "reload" });
137
+ setTimeout(async () => {
138
+ console.log(" Rebuild requested — wiping DB and message store...");
139
+ imapManager.stopPeriodicSync();
140
+ try {
141
+ await imapManager.shutdown();
142
+ }
143
+ catch { /* proceed */ }
144
+ db.close();
145
+ // Remove DB files
146
+ const dbDir = getConfigDir();
147
+ for (const f of ["mailx.db", "mailx.db-wal", "mailx.db-shm"]) {
148
+ const p = path.join(dbDir, f);
149
+ if (fs.existsSync(p)) {
150
+ fs.unlinkSync(p);
151
+ console.log(` Deleted ${f}`);
152
+ }
153
+ }
154
+ // Remove message store
155
+ const storePath = getStorePath();
156
+ if (fs.existsSync(storePath)) {
157
+ fs.rmSync(storePath, { recursive: true });
158
+ console.log(` Deleted ${storePath}`);
159
+ }
160
+ console.log(" Rebuild complete — restarting...");
161
+ server?.close();
162
+ process.exit(0);
163
+ }, 500);
164
+ });
134
165
  // SPA fallback
135
166
  app.get("*", (req, res) => {
136
167
  if (!req.path.startsWith("/api"))
@@ -107,11 +107,13 @@ function getSharedDir() {
107
107
  if (resolved)
108
108
  return resolved;
109
109
  }
110
- // Nothing mounted — save last provider entry for API fallback
111
- const lastProvider = [...entries].reverse().find(e => typeof e !== "string");
112
- if (lastProvider) {
113
- pendingCloudConfig = lastProvider;
114
- console.log(` No cloud drive mounted — will try ${lastProvider.provider} API`);
110
+ // Nothing mounted — save last provider entry for API fallback (log once)
111
+ if (!pendingCloudConfig) {
112
+ const lastProvider = [...entries].reverse().find(e => typeof e !== "string");
113
+ if (lastProvider) {
114
+ pendingCloudConfig = lastProvider;
115
+ console.log(` No cloud drive mounted — will try ${lastProvider.provider} API`);
116
+ }
115
117
  }
116
118
  }
117
119
  // Legacy: derive from settingsPath