@bobfrankston/mailx 1.0.151 → 1.0.152

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
@@ -72,9 +72,9 @@ if (hasFlag("kill")) {
72
72
  }
73
73
  }
74
74
  catch { /* no process on port */ }
75
- // Kill any node.exe running mailx-server (uses tasklist + powershell instead of wmic)
75
+ // Kill any node.exe running mailx (server or IPC service)
76
76
  try {
77
- const ps = execSync(`powershell -NoProfile -Command "Get-CimInstance Win32_Process -Filter \\"name='node.exe'\\" | Where-Object { $_.CommandLine -match 'mailx-server|mailx\\\\packages' } | Select-Object -ExpandProperty ProcessId"`, { encoding: "utf-8" }).trim();
77
+ const ps = execSync(`powershell -NoProfile -Command "Get-CimInstance Win32_Process -Filter \\"name='node.exe'\\" | Where-Object { $_.CommandLine -match 'mailx-server|mailx\\\\packages|mailx\\\\bin' } | Select-Object -ExpandProperty ProcessId"`, { encoding: "utf-8" }).trim();
78
78
  for (const pid of ps.split("\n").map(s => s.trim()).filter(s => /^\d+$/.test(s))) {
79
79
  try {
80
80
  execSync(`taskkill /F /PID ${pid}`, { stdio: "pipe" });
@@ -368,27 +368,20 @@ async function runSetup() {
368
368
  console.log("\nmailx — first-time setup\n");
369
369
  const home = process.env.USERPROFILE || process.env.HOME || "";
370
370
  const mailxDir = path.join(home, ".mailx");
371
- console.log("Gmail is recommended as the first account (provides contacts, calendar, and cloud settings sync).\n");
372
- const account = await promptForAccount();
373
- if (!account) {
374
- console.log(`\nNo account added. Open http://127.0.0.1:${PORT} in a browser to set up via the UI.`);
371
+ // Ask for email first if it's Gmail, check Drive for existing accounts before prompting further
372
+ console.log("Enter your email address to get started (Gmail recommended for cloud sync).\n");
373
+ const email = await prompt("Email address: ");
374
+ if (!email || !email.includes("@")) {
375
+ console.log(`\nNo account added. The UI will show a setup form.`);
375
376
  fs.mkdirSync(mailxDir, { recursive: true });
376
377
  return false;
377
378
  }
378
- const name = await prompt(`Your name (for From: header) [${account.email.split("@")[0]}]: `) || account.email.split("@")[0];
379
- const settings = {
380
- name,
381
- accounts: [account],
382
- ui: { theme: "system" },
383
- sync: { intervalMinutes: 5, historyDays: 0 },
384
- };
385
- const domain = account.email.split("@")[1]?.toLowerCase() || "";
386
- // Detect if this is a Google-hosted domain (for GDrive cloud storage)
379
+ const domain = email.split("@")[1]?.toLowerCase() || "";
387
380
  let isGoogle = ["gmail.com", "googlemail.com"].includes(domain);
388
381
  if (!isGoogle) {
389
382
  try {
390
- const dns = await import("node:dns/promises");
391
- const records = await dns.resolveMx(domain);
383
+ const dnsmod = await import("node:dns/promises");
384
+ const records = await dnsmod.resolveMx(domain);
392
385
  isGoogle = records.some(mx => {
393
386
  const host = mx.exchange.toLowerCase();
394
387
  return host.endsWith(".google.com") || host.endsWith(".googlemail.com");
@@ -398,67 +391,85 @@ async function runSetup() {
398
391
  }
399
392
  catch { /* DNS lookup failed */ }
400
393
  }
401
- fs.mkdirSync(mailxDir, { recursive: true });
394
+ // For Google-hosted accounts, check Drive for existing settings first
402
395
  if (isGoogle) {
403
- // Save to Google Drive via API — merge with existing settings if present
404
- console.log("\nSaving settings to Google Drive via API...");
396
+ fs.mkdirSync(mailxDir, { recursive: true });
397
+ console.log("\nChecking Google Drive for existing mailx settings...");
405
398
  try {
406
399
  const { gDriveFindOrCreateFolder, getCloudProvider } = await import("@bobfrankston/mailx-settings/cloud.js");
407
400
  const folderId = await gDriveFindOrCreateFolder();
408
401
  if (folderId) {
409
402
  const gdrive = getCloudProvider("gdrive", folderId);
410
403
  if (gdrive) {
411
- // Read existing accounts from Drive to merge (don't overwrite other accounts)
412
- let accountsList = [account];
413
- // Check accounts.jsonc first, then legacy settings.jsonc
414
- const existingAccts = await gdrive.read("accounts.jsonc");
415
- const existingSettings = existingAccts ? null : await gdrive.read("settings.jsonc");
416
- const existingContent = existingAccts || existingSettings;
417
- if (existingContent) {
418
- try {
419
- const { parse: parseJsonc } = await import("jsonc-parser");
420
- const prev = parseJsonc(existingContent);
421
- const prevAccounts = prev?.accounts || (Array.isArray(prev) ? prev : []);
422
- if (prevAccounts.length > 0) {
423
- accountsList = [...prevAccounts];
424
- const newEmail = account.email.toLowerCase();
425
- if (!accountsList.some((a) => a.email?.toLowerCase() === newEmail)) {
426
- accountsList.push(account);
427
- }
428
- console.log(` Found ${prevAccounts.length} existing account(s) on Drive — merging`);
429
- }
404
+ // Check for existing accounts on Drive
405
+ const existing = await gdrive.read("accounts.jsonc") || await gdrive.read("settings.jsonc");
406
+ if (existing) {
407
+ const { parse: parseJsonc } = await import("jsonc-parser");
408
+ const data = parseJsonc(existing);
409
+ const accts = data?.accounts || (Array.isArray(data) ? data : []);
410
+ if (accts.length > 0) {
411
+ console.log(`\nFound ${accts.length} existing account(s) on Google Drive!`);
412
+ for (const a of accts)
413
+ console.log(` • ${a.label || a.name || a.email}`);
414
+ // Save config pointing to Drive no prompts needed
415
+ const config = { sharedDir: { provider: "gdrive", path: "mailx", folderId } };
416
+ fs.writeFileSync(path.join(mailxDir, "config.jsonc"), JSON.stringify(config, null, 2));
417
+ console.log("Local config created. Starting mailx...\n");
418
+ return true;
430
419
  }
431
- catch { /* parse failed, overwrite */ }
432
420
  }
433
- const accountsData = { name, accounts: accountsList };
434
- const content = JSON.stringify(accountsData, null, 2);
435
- const ok = await gdrive.write("accounts.jsonc", content);
421
+ }
422
+ // No existing accounts save Drive config for later
423
+ const config = { sharedDir: { provider: "gdrive", path: "mailx", folderId } };
424
+ fs.writeFileSync(path.join(mailxDir, "config.jsonc"), JSON.stringify(config, null, 2));
425
+ }
426
+ }
427
+ catch (e) {
428
+ console.log(` Drive check failed: ${e.message} — continuing with manual setup`);
429
+ }
430
+ }
431
+ // No existing accounts found — build a new account
432
+ const account = { email };
433
+ const isOAuth = ["gmail.com", "googlemail.com", "outlook.com", "hotmail.com", "live.com"].includes(domain);
434
+ if (!isOAuth) {
435
+ account.password = await prompt("Password (app password for Yahoo/AOL/iCloud): ");
436
+ }
437
+ const name = await prompt(`Your name (for From: header) [${email.split("@")[0]}]: `) || email.split("@")[0];
438
+ fs.mkdirSync(mailxDir, { recursive: true });
439
+ if (isGoogle) {
440
+ // Save to Google Drive via API
441
+ console.log("\nSaving account to Google Drive...");
442
+ try {
443
+ const { gDriveFindOrCreateFolder, getCloudProvider } = await import("@bobfrankston/mailx-settings/cloud.js");
444
+ const folderId = await gDriveFindOrCreateFolder();
445
+ if (folderId) {
446
+ const gdrive = getCloudProvider("gdrive", folderId);
447
+ if (gdrive) {
448
+ const accountsData = { name, accounts: [account] };
449
+ const ok = await gdrive.write("accounts.jsonc", JSON.stringify(accountsData, null, 2));
436
450
  if (ok) {
437
- console.log("Settings saved to Google Drive (mailx folder)");
438
- const config = { sharedDir: { provider: "gdrive", path: "mailx", folderId } };
439
- fs.writeFileSync(path.join(mailxDir, "config.jsonc"), JSON.stringify(config, null, 2));
440
- console.log("Local config created with Drive folder ID.");
451
+ console.log("Account saved to Google Drive.");
452
+ // config.jsonc may already exist from the Drive check above
453
+ if (!fs.existsSync(path.join(mailxDir, "config.jsonc"))) {
454
+ const config = { sharedDir: { provider: "gdrive", path: "mailx", folderId } };
455
+ fs.writeFileSync(path.join(mailxDir, "config.jsonc"), JSON.stringify(config, null, 2));
456
+ }
441
457
  }
442
458
  else {
443
- console.log("Google Drive write failed — saving locally instead.");
444
- fs.writeFileSync(path.join(mailxDir, "settings.jsonc"), JSON.stringify(settings, null, 2));
459
+ console.log("Drive write failed — saving locally.");
460
+ fs.writeFileSync(path.join(mailxDir, "accounts.jsonc"), JSON.stringify({ name, accounts: [account] }, null, 2));
445
461
  }
446
462
  }
447
463
  }
448
- else {
449
- console.log("Google Drive folder setup failed — saving locally.");
450
- fs.writeFileSync(path.join(mailxDir, "settings.jsonc"), JSON.stringify(settings, null, 2));
451
- }
452
464
  }
453
465
  catch (e) {
454
- console.log(`Google Drive error: ${e.message} — saving locally.`);
455
- fs.writeFileSync(path.join(mailxDir, "settings.jsonc"), JSON.stringify(settings, null, 2));
466
+ console.log(`Drive error: ${e.message} — saving locally.`);
467
+ fs.writeFileSync(path.join(mailxDir, "accounts.jsonc"), JSON.stringify({ name, accounts: [account] }, null, 2));
456
468
  }
457
469
  }
458
470
  else {
459
- // Non-Google account — save locally
460
- console.log(`\nSaving settings to ${mailxDir}...`);
461
- fs.writeFileSync(path.join(mailxDir, "settings.jsonc"), JSON.stringify(settings, null, 2));
471
+ // Non-Google — save locally
472
+ fs.writeFileSync(path.join(mailxDir, "accounts.jsonc"), JSON.stringify({ name, accounts: [account] }, null, 2));
462
473
  }
463
474
  console.log("Setup complete. Starting mailx...\n");
464
475
  return true;
package/client/app.js CHANGED
@@ -898,10 +898,6 @@ optAutocomplete?.addEventListener("change", () => {
898
898
  }).catch(() => { });
899
899
  });
900
900
  const isApp = typeof mailxapi !== "undefined" && mailxapi?.isApp;
901
- // Set baseline version text immediately (async getVersion updates it with storage info)
902
- const versionEl = document.getElementById("app-version");
903
- if (versionEl)
904
- versionEl.textContent = "mailx";
905
901
  const versionPromise = getVersion();
906
902
  versionPromise.then((d) => {
907
903
  const el = document.getElementById("app-version");
@@ -330,7 +330,14 @@ async function loadFolderTree(container) {
330
330
  container.innerHTML = `<div class="folder-loading">Loading accounts...</div>`;
331
331
  }
332
332
  try {
333
- const accounts = await getAccounts();
333
+ let accounts = await getAccounts();
334
+ // Accounts may still be registering (OAuth in progress) — retry a few times
335
+ if (accounts.length === 0) {
336
+ for (let retry = 0; retry < 5 && accounts.length === 0; retry++) {
337
+ await new Promise(r => setTimeout(r, 2000));
338
+ accounts = await getAccounts();
339
+ }
340
+ }
334
341
  if (accounts.length === 0) {
335
342
  container.innerHTML = `<div class="folder-loading">No accounts</div>`;
336
343
  // Hide the message list and show setup in the viewer pane (full width)
@@ -396,28 +403,43 @@ async function loadFolderTree(container) {
396
403
  helpEl.textContent = help || "";
397
404
  }
398
405
  });
399
- form?.addEventListener("submit", async (e) => {
400
- e.preventDefault();
401
- const name = document.getElementById("setup-name").value.trim();
406
+ // When a valid email is entered, try setup immediately — if cloud has
407
+ // existing accounts, loads them without needing name/password
408
+ let setupTriggered = false;
409
+ async function trySetup() {
402
410
  const email = emailInput.value.trim();
403
- const password = document.getElementById("setup-password").value;
404
- if (!email)
411
+ if (!email || !email.includes("@") || setupTriggered)
405
412
  return;
406
- statusEl.textContent = "Setting up account...";
413
+ const name = document.getElementById("setup-name").value.trim();
414
+ const password = document.getElementById("setup-password").value;
415
+ setupTriggered = true;
416
+ statusEl.textContent = "Checking for existing accounts...";
407
417
  try {
408
418
  const data = await setupAccount(name, email, password);
409
419
  if (data.ok) {
410
- statusEl.textContent = "Account added! Syncing...";
411
- // Wait for sync to populate folders before reloading
420
+ statusEl.textContent = data.message || "Accounts loaded! Syncing...";
412
421
  setTimeout(() => location.reload(), 5000);
413
422
  }
414
423
  else {
424
+ setupTriggered = false;
415
425
  statusEl.textContent = `Error: ${data.error || "Setup failed"}`;
416
426
  }
417
427
  }
418
428
  catch (err) {
429
+ setupTriggered = false;
419
430
  statusEl.textContent = `Error: ${err.message}`;
420
431
  }
432
+ }
433
+ form?.addEventListener("submit", async (e) => {
434
+ e.preventDefault();
435
+ await trySetup();
436
+ });
437
+ // Auto-trigger for OAuth providers when email looks complete
438
+ emailInput?.addEventListener("change", async () => {
439
+ const domain = emailInput.value.split("@")[1]?.toLowerCase() || "";
440
+ const isOAuth = ["gmail.com", "googlemail.com", "outlook.com", "hotmail.com", "live.com"].includes(domain);
441
+ if (isOAuth)
442
+ await trySetup();
421
443
  });
422
444
  // Show cloud storage status in setup form
423
445
  getVersion().then((d) => {
package/client/index.html CHANGED
@@ -39,7 +39,7 @@
39
39
  <label class="tb-menu-item"><input type="checkbox" id="opt-autocomplete"> AI autocomplete</label>
40
40
  </div>
41
41
  </div>
42
- <span id="app-version" class="app-version"></span>
42
+ <span id="app-version" class="app-version">mailx</span>
43
43
  </div>
44
44
  <div class="toolbar-right">
45
45
  <button class="tb-btn" id="btn-sync" title="Sync all folders (F5)">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx",
3
- "version": "1.0.151",
3
+ "version": "1.0.152",
4
4
  "description": "Local-first email client with IMAP sync and standalone native app",
5
5
  "type": "module",
6
6
  "main": "bin/mailx.js",
@@ -23,7 +23,7 @@
23
23
  "@bobfrankston/iflow": "^1.0.53",
24
24
  "@bobfrankston/miscinfo": "^1.0.7",
25
25
  "@bobfrankston/oauthsupport": "^1.0.20",
26
- "@bobfrankston/msger": "^0.1.201",
26
+ "@bobfrankston/msger": "^0.1.202",
27
27
  "@capacitor/android": "^8.3.0",
28
28
  "@capacitor/cli": "^8.3.0",
29
29
  "@capacitor/core": "^8.3.0",
@@ -539,12 +539,30 @@ export class MailxService {
539
539
  if (detected?.cloud) {
540
540
  await initCloudConfig(detected.cloud);
541
541
  }
542
- // Try to load existing accounts from cloud (merge, don't overwrite)
542
+ // Check cloud for existing accounts if found, just load them all
543
543
  let accounts = loadAccounts();
544
544
  if (accounts.length === 0) {
545
545
  accounts = await loadAccountsAsync();
546
546
  }
547
- // Build the new account entry
547
+ if (accounts.length > 0) {
548
+ // Existing accounts found on cloud — use them directly
549
+ console.log(` Found ${accounts.length} existing account(s) from cloud settings`);
550
+ const settings = loadSettings();
551
+ for (const acct of settings.accounts) {
552
+ if (!acct.enabled)
553
+ continue;
554
+ try {
555
+ await this.imapManager.addAccount(acct);
556
+ console.log(` Account loaded: ${acct.label || acct.name} (${acct.id})`);
557
+ }
558
+ catch (e) {
559
+ console.error(` Account ${acct.id} error: ${e.message}`);
560
+ }
561
+ }
562
+ this.imapManager.syncAll().catch(() => { });
563
+ return { ok: true, message: `Loaded ${accounts.length} existing account(s) from cloud.` };
564
+ }
565
+ // No existing accounts — create new one
548
566
  const account = { email, name: name || email.split("@")[0] };
549
567
  if (password)
550
568
  account.password = password;
@@ -552,17 +570,9 @@ export class MailxService {
552
570
  account.imap = { host: detected.imapHost, port: 993, tls: true, auth: detected.auth, user: email };
553
571
  account.smtp = { host: detected.smtpHost, port: 587, tls: true, auth: detected.auth, user: email };
554
572
  }
555
- const id = domain.split(".")[0] || "account";
556
- // Add new account if not already present
557
- if (!accounts.some((a) => a.email?.toLowerCase() === email.toLowerCase())) {
558
- account.id = id;
559
- accounts.push(account);
560
- }
561
- if (accounts.length > 0) {
562
- console.log(` Saving ${accounts.length} account(s) (merged with existing cloud settings)`);
563
- }
564
- saveAccounts(accounts);
565
- // Re-read normalized settings and register ALL accounts
573
+ account.id = domain.split(".")[0] || "account";
574
+ saveAccounts([account]);
575
+ // Re-read normalized settings and register
566
576
  const settings = loadSettings();
567
577
  for (const acct of settings.accounts) {
568
578
  if (!acct.enabled)