@bobfrankston/mailx 1.0.95 → 1.0.97

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx",
3
- "version": "1.0.95",
3
+ "version": "1.0.97",
4
4
  "description": "Local-first email client with IMAP sync and standalone native app",
5
5
  "type": "module",
6
6
  "main": "bin/mailx.js",
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { ImapClient, createAutoImapConfig, CompatImapClient, NodeTransport } from "@bobfrankston/iflow";
7
7
  import { FileMessageStore } from "@bobfrankston/mailx-store";
8
- import { loadSettings, getStorePath, getConfigDir } from "@bobfrankston/mailx-settings";
8
+ import { loadSettings, getStorePath, getConfigDir, getHistoryDays } from "@bobfrankston/mailx-settings";
9
9
  import { EventEmitter } from "node:events";
10
10
  import * as fs from "node:fs";
11
11
  import * as path from "node:path";
@@ -267,8 +267,7 @@ export class ImapManager extends EventEmitter {
267
267
  }
268
268
  else {
269
269
  // First sync: use date-based fetch with bodies for local-first
270
- const settings = loadSettings();
271
- const historyDays = settings.sync.historyDays || 0;
270
+ const historyDays = getHistoryDays(accountId);
272
271
  const startDate = historyDays > 0
273
272
  ? new Date(Date.now() - historyDays * 86400000)
274
273
  : new Date(0);
@@ -214,11 +214,19 @@ imapManager.on("accountError", (accountId, error, hint, isOAuth) => {
214
214
  // ── Startup ──
215
215
  async function start() {
216
216
  console.log("mailx server starting...");
217
+ // Start HTTP server FIRST so UI is always reachable (even during IMAP startup)
218
+ const externalAccess = process.argv.includes("--external");
219
+ const hostname = externalAccess ? "0.0.0.0" : "127.0.0.1";
220
+ server = createServer(app);
221
+ wss = new WebSocketServer({ server });
222
+ wireWebSocket();
223
+ await new Promise((resolve) => server.listen(PORT, hostname, resolve));
224
+ console.log(`mailx server running on http://${hostname}:${PORT}`);
217
225
  // Seed contacts (fast — skips existing)
218
226
  const seeded = db.seedContactsFromMessages();
219
227
  if (seeded > 0)
220
228
  console.log(` Seeded ${seeded} contacts`);
221
- // Search index — rebuild in background after server starts (non-blocking)
229
+ // Search index — rebuild in background (non-blocking)
222
230
  setTimeout(() => {
223
231
  let ftsCount = 0;
224
232
  try {
@@ -260,14 +268,6 @@ async function start() {
260
268
  imapManager.startPeriodicSync(settings.sync.intervalMinutes);
261
269
  // Outbox worker — processes queued outgoing messages
262
270
  imapManager.startOutboxWorker();
263
- // Start server — localhost only by default, --external for network access
264
- const externalAccess = process.argv.includes("--external");
265
- const hostname = externalAccess ? "0.0.0.0" : "127.0.0.1";
266
- server = createServer(app);
267
- wss = new WebSocketServer({ server });
268
- wireWebSocket();
269
- await new Promise((resolve) => server.listen(PORT, hostname, resolve));
270
- console.log(`mailx server running on http://${hostname}:${PORT}`);
271
271
  }
272
272
  // ── Graceful Shutdown ──
273
273
  async function shutdown() {
@@ -72,5 +72,7 @@ export { getSharedDir };
72
72
  /** Initialize local config if it doesn't exist */
73
73
  export declare function initLocalConfig(sharedDir?: string, storePath?: string): void;
74
74
  declare const DEFAULT_SETTINGS: MailxSettings;
75
+ /** Get historyDays for an account: per-account override > system override > shared default */
76
+ export declare function getHistoryDays(accountId?: string): number;
75
77
  export { DEFAULT_SETTINGS, DEFAULT_ALLOWLIST, DEFAULT_PREFERENCES, LOCAL_DIR };
76
78
  //# sourceMappingURL=index.d.ts.map
@@ -346,14 +346,30 @@ export function loadAccounts() {
346
346
  }
347
347
  const raw = accounts.accounts || accounts;
348
348
  const globalName = accounts.name || "";
349
- return raw.map((a) => normalizeAccount(a, globalName));
349
+ const result = raw.map((a) => normalizeAccount(a, globalName));
350
+ return applyAccountOverrides(result);
350
351
  }
351
352
  // Legacy: read from settings.jsonc
352
353
  const legacy = loadLegacySettings();
353
354
  if (legacy?.accounts)
354
- return legacy.accounts.map((a) => normalizeAccount(a, legacy.name));
355
+ return applyAccountOverrides(legacy.accounts.map((a) => normalizeAccount(a, legacy.name)));
355
356
  return DEFAULT_ACCOUNTS;
356
357
  }
358
+ /** Apply local per-account overrides (enabled, etc.) */
359
+ function applyAccountOverrides(accounts) {
360
+ const localConfig = readLocalConfig();
361
+ const overrides = localConfig.accountOverrides;
362
+ if (!overrides)
363
+ return accounts;
364
+ for (const acct of accounts) {
365
+ const ov = overrides[acct.id];
366
+ if (!ov)
367
+ continue;
368
+ if (ov.enabled !== undefined)
369
+ acct.enabled = ov.enabled;
370
+ }
371
+ return accounts;
372
+ }
357
373
  /** Save account configs */
358
374
  export function saveAccounts(accounts) {
359
375
  saveFile("accounts.jsonc", { accounts });
@@ -498,5 +514,16 @@ const DEFAULT_SETTINGS = {
498
514
  sync: DEFAULT_PREFERENCES.sync,
499
515
  store: { basePath: DEFAULT_STORE_PATH, compressionBoundaryDays: 365 },
500
516
  };
517
+ /** Get historyDays for an account: per-account override > system override > shared default */
518
+ export function getHistoryDays(accountId) {
519
+ const localConfig = readLocalConfig();
520
+ if (accountId && localConfig.accountOverrides?.[accountId]?.historyDays !== undefined) {
521
+ return localConfig.accountOverrides[accountId].historyDays;
522
+ }
523
+ if (localConfig.historyDays !== undefined)
524
+ return localConfig.historyDays;
525
+ const prefs = loadPreferences();
526
+ return prefs.sync.historyDays || 0;
527
+ }
501
528
  export { DEFAULT_SETTINGS, DEFAULT_ALLOWLIST, DEFAULT_PREFERENCES, LOCAL_DIR };
502
529
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx-settings",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",