domma-cms 1.72.0 → 1.73.0

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 (86) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/package.json +1 -1
  3. package/plugins/_lib/admin/mail/body-menu.js +1 -1
  4. package/plugins/_lib/admin/mail/cms-host.js +1 -1
  5. package/plugins/_lib/admin/mail/compose-window.js +15 -1
  6. package/plugins/_lib/admin/mail/contacts.js +1 -1
  7. package/plugins/_lib/admin/mail/diagnostics-section.js +75 -41
  8. package/plugins/_lib/admin/mail/drag-drop.js +1 -1
  9. package/plugins/_lib/admin/mail/folder-tree.js +1 -1
  10. package/plugins/_lib/admin/mail/font-controls.js +1 -1
  11. package/plugins/_lib/admin/mail/fonts.js +1 -1
  12. package/plugins/_lib/admin/mail/host-context.js +1 -1
  13. package/plugins/_lib/admin/mail/identity.js +1 -1
  14. package/plugins/_lib/admin/mail/image-senders-section.js +156 -99
  15. package/plugins/_lib/admin/mail/keyboard.js +1 -1
  16. package/plugins/_lib/admin/mail/mail.css +1 -1
  17. package/plugins/_lib/admin/mail/mail.html +1 -1
  18. package/plugins/_lib/admin/mail/message-actions.js +1 -1
  19. package/plugins/_lib/admin/mail/oauth-panel.js +1 -1
  20. package/plugins/_lib/admin/mail/panes.js +1 -1
  21. package/plugins/_lib/admin/mail/reader-kit.js +12 -4
  22. package/plugins/_lib/admin/mail/reader-runtime.js +362 -95
  23. package/plugins/_lib/admin/mail/reader-view.js +1 -1
  24. package/plugins/_lib/admin/mail/resizable.js +1 -1
  25. package/plugins/_lib/admin/mail/restore-spam.js +1 -1
  26. package/plugins/_lib/admin/mail/rules.js +1 -1
  27. package/plugins/_lib/admin/mail/scheduling.js +1 -1
  28. package/plugins/_lib/admin/mail/section-kit.js +1 -1
  29. package/plugins/_lib/admin/mail/security-note.js +1 -1
  30. package/plugins/_lib/admin/mail/settings-section.js +156 -99
  31. package/plugins/_lib/admin/mail/templates.js +1 -1
  32. package/plugins/_lib/admin/mail/threads.js +1 -1
  33. package/plugins/_lib/admin/mail/vacation.js +45 -1
  34. package/plugins/_lib/admin/mail/when-closed.js +1 -1
  35. package/plugins/_lib/admin/ui/dates.js +1 -1
  36. package/plugins/_lib/admin/ui/resizable.js +1 -1
  37. package/plugins/_lib/admin/ui/rich-field.js +1 -1
  38. package/plugins/_lib/domma-mail.lock.json +83 -83
  39. package/plugins/_lib/mail/accountFileStore.js +1 -1
  40. package/plugins/_lib/mail/accountRepository.js +31 -3
  41. package/plugins/_lib/mail/accountRoutes.js +1 -1
  42. package/plugins/_lib/mail/accounts.js +1 -1
  43. package/plugins/_lib/mail/bodyTokenProvider.js +1 -1
  44. package/plugins/_lib/mail/bodyTokens.js +1 -1
  45. package/plugins/_lib/mail/compose.js +1 -1
  46. package/plugins/_lib/mail/defaults.js +1 -1
  47. package/plugins/_lib/mail/envelope.js +1 -1
  48. package/plugins/_lib/mail/folderActions.js +1 -1
  49. package/plugins/_lib/mail/folderRuntime.js +1 -1
  50. package/plugins/_lib/mail/folders.js +1 -1
  51. package/plugins/_lib/mail/imapPoolRuntime.js +1 -1
  52. package/plugins/_lib/mail/mbox.js +1 -1
  53. package/plugins/_lib/mail/message-action.js +1 -1
  54. package/plugins/_lib/mail/messageSecurity.js +1 -1
  55. package/plugins/_lib/mail/messageSecurityProvider.js +1 -1
  56. package/plugins/_lib/mail/networkAddresses.js +1 -1
  57. package/plugins/_lib/mail/networkPolicy.js +1 -1
  58. package/plugins/_lib/mail/oauthAccounts.js +1 -1
  59. package/plugins/_lib/mail/oauthRouteRuntime.js +1 -1
  60. package/plugins/_lib/mail/oauthRuntime.js +1 -1
  61. package/plugins/_lib/mail/pollSchedule.js +1 -1
  62. package/plugins/_lib/mail/poller.js +1 -1
  63. package/plugins/_lib/mail/pollerRuntime.js +1 -1
  64. package/plugins/_lib/mail/priority.js +1 -1
  65. package/plugins/_lib/mail/publicMailbox.js +1 -1
  66. package/plugins/_lib/mail/readRuntime.js +1 -1
  67. package/plugins/_lib/mail/render.js +1 -1
  68. package/plugins/_lib/mail/ruleRunner.js +1 -1
  69. package/plugins/_lib/mail/schedulerRuntime.js +1 -1
  70. package/plugins/_lib/mail/secretProvider.js +1 -1
  71. package/plugins/_lib/mail/secretbox.js +1 -1
  72. package/plugins/_lib/mail/senderAuth.js +1 -1
  73. package/plugins/_lib/mail/sieve.js +1 -1
  74. package/plugins/_lib/mail/smtpService.js +1 -1
  75. package/plugins/_lib/mail/snoozeRuntime.js +1 -1
  76. package/plugins/_lib/mail/store.js +1 -1
  77. package/plugins/_lib/mail/subscriptions.js +1 -1
  78. package/plugins/_lib/mail/syncPlan.js +1 -1
  79. package/plugins/_lib/mail/syncRuntime.js +1 -1
  80. package/plugins/_lib/mail/syncSelection.js +1 -1
  81. package/plugins/_lib/mail/unreadBadge.js +1 -1
  82. package/plugins/_lib/mail/unsubscribe.js +1 -1
  83. package/plugins/_lib/mail/vacationRuntime.js +1 -1
  84. package/plugins/_lib/mail/write.js +1 -1
  85. package/plugins/_lib/public/rich-text.mjs +1 -1
  86. package/plugins/_lib/rich-text.js +1 -1
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.31.0, packages/core/src/admin/mail/reader-runtime.js.
1
+ // Source: @domma-mail/core 0.32.0, packages/core/src/admin/mail/reader-runtime.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  const MAIL_MODULE_VERSION = new URL(import.meta.url).searchParams.get('v') ?? '1';
4
4
  const {createMailHost} = await import(new URL(`./host-context.js?v=${MAIL_MODULE_VERSION}`, import.meta.url).href);
@@ -121,9 +121,13 @@ function formatSize(bytes) {
121
121
  * recipientsChanged?(recipients), close?()}`, an edition's part of every
122
122
  * compose window: it may draw into `context.slot` (shown with
123
123
  * `context.show()`), and `fields()` is added to what Save and Send post.
124
+ * `context.identities` / `setIdentity(id)` / `hideFrom()` let it offer the senders itself.
124
125
  * Optional, checked and feature-detected: an edition that passes it to an
125
126
  * older reader just does not get the entries. Item actions run on the next
126
127
  * task, so one picked with Enter cannot hand its own Enter to a dialog.
128
+ * `settingsScreen: {title?, groups: [{label, sections: [id]}]}` shows Settings as a screen of its own in
129
+ * place of the reader (grouped navigation down the left, Back to mail) rather than a slideover of tabs.
130
+ * Sections in no group go under "More". Without it, the slideover as before.
127
131
  * `settingsSections` lets an edition contribute settings without forking the
128
132
  * view: each is `{id, label, render(container, context)}`, and the shell
129
133
  * handles the tabs, the lazy drawing and a section that throws.
@@ -134,7 +138,7 @@ function formatSize(bytes) {
134
138
  * @returns {object} a Domma view
135
139
  */
136
140
  export function createReaderView({pluginName, assetVersion = ASSET_VERSION, settingsSections = [], features = {},
137
- extensions = {}, host: mailHost = null}) {
141
+ extensions = {}, host: mailHost = null, settingsScreen = null}) {
138
142
  mailHost ??= createMailHost({pluginName});
139
143
  const {api, storage: S, Domma, M, E, F, $} = mailHost;
140
144
  const {viewLifetime, helpPopovers, openMenuAt, promptWith, sidebarCount, loading} = mailHost.helpers;
@@ -918,6 +922,58 @@ return {
918
922
  *
919
923
  * @returns {void}
920
924
  */
925
+ /**
926
+ * A stand-in for a slideover that is a screen in place of the reader: the same
927
+ * open/close/on('close') a panel has, so the guard, the close question and the
928
+ * clean-up treat both alike. Back to mail (or Escape on the screen) closes it.
929
+ *
930
+ * @returns {{element: HTMLElement, open: Function, close: Function, on: Function, destroy: Function}}
931
+ */
932
+ function settingsScreenPanel() {
933
+ const root = $container.get(0);
934
+ const layout = root.querySelector('.mail-layout');
935
+ const element = document.createElement('section');
936
+ element.className = 'mail-settings-screen';
937
+ element.hidden = true;
938
+ const head = document.createElement('div');
939
+ head.className = 'mail-settings-head';
940
+ const back = document.createElement('button');
941
+ back.type = 'button';
942
+ back.className = 'btn btn-sm btn-ghost';
943
+ back.textContent = '\u2190 Back to mail';
944
+ const title = document.createElement('h2');
945
+ title.className = 'mail-settings-title';
946
+ title.textContent = settingsScreen?.title || 'Email settings';
947
+ head.append(back, title);
948
+ element.appendChild(head);
949
+ layout.after(element);
950
+ const listeners = {close: [], open: []};
951
+ let open = false;
952
+ const panel = {
953
+ element,
954
+ on(event, fn) { (listeners[event] ??= []).push(fn); },
955
+ open() {
956
+ open = true;
957
+ layout.hidden = true;
958
+ element.hidden = false;
959
+ listeners.open.forEach(fn => { try { fn(panel); } catch { /* ignore */ } });
960
+ back.focus();
961
+ },
962
+ close() {
963
+ if (!open) return;
964
+ open = false;
965
+ element.hidden = true;
966
+ layout.hidden = false;
967
+ listeners.close.forEach(fn => { try { fn(panel); } catch { /* ignore */ } });
968
+ element.remove();
969
+ },
970
+ destroy() { element.remove(); layout.hidden = false; }
971
+ };
972
+ // Through the property, so the guarded close (the unsaved question) is the one called.
973
+ back.addEventListener('click', () => panel.close());
974
+ return panel;
975
+ }
976
+
921
977
  function openSettings(target = null) {
922
978
  // One at a time: a second click, or a needs-password error while
923
979
  // it is open, must not stack a second panel on the first.
@@ -955,7 +1011,10 @@ return {
955
1011
  const dirtyGuards = () => [...guards].filter(g => { try { return Boolean(g.dirty?.()); } catch { return false; } });
956
1012
  // Each section saves on its own button; the panel asks only for
957
1013
  // sections that said (ctx.guard) they hold unsaved work.
958
- const slideover = guardPanel(E.slideover({title: 'Mail Settings', size: 'lg', position: 'right'}),
1014
+ const navProviders = new Map();
1015
+ const asScreen = Array.isArray(settingsScreen?.groups) && settingsScreen.groups.length > 0
1016
+ && Boolean($container.get(0)?.querySelector('.mail-layout'));
1017
+ const slideover = guardPanel(asScreen ? settingsScreenPanel() : E.slideover({title: 'Mail Settings', size: 'lg', position: 'right'}),
959
1018
  () => dirtyGuards().length > 0,
960
1019
  () => settingsDiscardQuestion(dirtyGuards().map(g => g.label)),
961
1020
  () => {
@@ -973,7 +1032,7 @@ return {
973
1032
  // width someone wants depends on their screen - the same reason
974
1033
  // compose is resizable. Its own remembered width, because the two
975
1034
  // are opened for different things.
976
- const stopSettingsResize = makeResizable(slideover, {
1035
+ const stopSettingsResize = asScreen ? () => {} : makeResizable(slideover, {
977
1036
  storage: mailHost.storage,
978
1037
  storageKey: 'domma-mail.settings-width',
979
1038
  defaultWidth: 760
@@ -996,8 +1055,19 @@ return {
996
1055
  {
997
1056
  id: 'mailboxes',
998
1057
  label: 'Mailboxes',
1058
+ collection: true,
999
1059
  icon: 'inbox',
1000
1060
  help: 'The IMAP accounts this screen reads. Each person\'s mailboxes are their own - nobody else in the admin can see them. Passwords are stored sealed and never sent back to the browser.',
1061
+ guide: `<p>A mailbox is an email account this screen reads (IMAP) - and, where the edition sends, its outgoing server. Each person's mailboxes are their own: nobody else in the admin can see them.</p>
1062
+ <h4>The list</h4>
1063
+ <ul><li>Click a mailbox, or press Enter on it, to edit its server, port, security and sign-in.</li>
1064
+ <li>Right-click it, use its <b>⋮</b>, or press Shift+F10 for <b>Edit</b>, <b>Open in the reader</b>, <b>Make default</b> and <b>Remove</b>.</li>
1065
+ <li>The <b>Default</b> mailbox is the one the screen opens on. <b>Open</b> marks the one you are reading now.</li>
1066
+ <li><b>+ Add mailbox</b> under the list adds another account.</li></ul>
1067
+ <h4>Passwords and sign-in</h4>
1068
+ <p>Passwords are stored sealed on the server and never sent back to the browser. A Microsoft or Google mailbox can sign in instead of using a password; a chip on its row says when it needs signing in again.</p>
1069
+ <h4>Unsaved changes</h4>
1070
+ <p>Changes left in a mailbox's form are kept in this browser (never the password) and the row says <b>Unsaved changes</b> - Edit to pick them up or throw them away.</p>`,
1001
1071
  render: renderMailboxSection
1002
1072
  },
1003
1073
  // Blocking remote images is not a Pro feature, and neither is
@@ -1034,6 +1104,10 @@ return {
1034
1104
  */
1035
1105
  function context(section = null) {
1036
1106
  return {
1107
+ // Screen mode only: a section that keeps a list (identities, away messages,
1108
+ // templates…) hands its items to the section list's right-click menu instead
1109
+ // of drawing a list column, so the editor gets the width.
1110
+ navMenu: asScreen && section ? (provider) => { navProviders.set(section.id, provider); } : undefined,
1037
1111
  // What opened this section, when something did (a menu
1038
1112
  // item asking for a new rule). Only for that section.
1039
1113
  request: target && section?.id === target.section ? (target.request ?? null) : null,
@@ -1115,6 +1189,25 @@ return {
1115
1189
  marker.setAttribute('data-help-title', section.label);
1116
1190
  marker.setAttribute('data-help', section.help);
1117
1191
  head.append(title, marker);
1192
+ // Longer help in a slideover, for a section that brings it: `guide` is the
1193
+ // section's own static HTML (written in code, never user text).
1194
+ if (section.guide) {
1195
+ const more = document.createElement('button');
1196
+ more.type = 'button';
1197
+ more.className = 'btn btn-sm btn-ghost mail-section-help';
1198
+ more.textContent = 'Help';
1199
+ more.setAttribute('aria-haspopup', 'dialog');
1200
+ more.addEventListener('click', () => {
1201
+ const help = E.slideover({title: `${section.label} - help`, size: 'md', position: 'right'});
1202
+ const box = document.createElement('div');
1203
+ box.className = 'mail-help-body';
1204
+ box.innerHTML = section.guide;
1205
+ help.element.appendChild(box);
1206
+ help.open();
1207
+ whenClosed(help, () => setTimeout(() => { try { help.element?.remove(); } catch { /* gone */ } }, 400));
1208
+ });
1209
+ head.appendChild(more);
1210
+ }
1118
1211
  panel.appendChild(head);
1119
1212
  }
1120
1213
  try {
@@ -1129,6 +1222,134 @@ return {
1129
1222
  helpDisposers.push(helpPopovers(panel, {position: 'bottom'}));
1130
1223
  }
1131
1224
 
1225
+ /**
1226
+ * Settings as a screen: the groups down the left, one section at a time on the right.
1227
+ * Sections are drawn on first view and kept, as the tabs are.
1228
+ */
1229
+ function drawScreen() {
1230
+ const byId = new Map(sections.map(section => [section.id, section]));
1231
+ const placed = new Set();
1232
+ const groups = settingsScreen.groups.map(group => ({
1233
+ label: String(group.label ?? ''),
1234
+ sections: (group.sections ?? []).map(id => byId.get(id)).filter(section => section && !placed.has(section.id) && placed.add(section.id))
1235
+ })).filter(group => group.sections.length);
1236
+ const rest = sections.filter(section => !placed.has(section.id));
1237
+ if (rest.length) groups.push({label: 'More', sections: rest});
1238
+
1239
+ // Built with domma-reactive: one flat list of group headings and section links (a
1240
+ // nested data-each renders an unbound copy), each link's state an observable.
1241
+ const items = [];
1242
+ for (const group of groups) {
1243
+ items.push({key: `g:${group.label}`, isGroup: true, label: group.label, id: '',
1244
+ active: M.observable(false), dirty: M.observable(false)});
1245
+ for (const section of group.sections) {
1246
+ items.push({key: `s:${section.id}`, isGroup: false, label: section.label, id: section.id,
1247
+ active: M.observable(false), dirty: M.observable(false)});
1248
+ }
1249
+ }
1250
+ const body = document.createElement('div');
1251
+ body.className = 'mail-settings-body';
1252
+ body.innerHTML = `<nav class="mail-settings-nav" aria-label="Settings" data-each="items key=key">
1253
+ <div class="mail-settings-group-label" data-bind-hidden="!isGroup" data-bind-text="label"></div>
1254
+ <button type="button" class="mail-settings-link" data-bind-hidden="isGroup" data-bind-class="active.value && 'is-active'"
1255
+ data-bind-aria-current="active.value ? 'page' : 'false'" data-bind-aria-description="dirty.value ? 'Unsaved changes' : ''"
1256
+ data-on-click="$root.show(id)"><span data-bind-text="label"></span><span class="mail-tab-pip" aria-hidden="true" data-bind-hidden="!dirty.value"></span></button>
1257
+ </nav><div class="mail-settings-main"></div>`;
1258
+ const main = body.querySelector('.mail-settings-main');
1259
+ const panels = new Map();
1260
+ function ensure(id) {
1261
+ const section = byId.get(id);
1262
+ if (!section) return null;
1263
+ let panel = panels.get(id);
1264
+ // Drawn for another mailbox (Folders to sync… on a mailbox's menu opens that one
1265
+ // first): drawn again, so a section never shows one mailbox's settings under another.
1266
+ if (panel && panel.dataset.account !== String(currentAccountId ?? '')) {
1267
+ panel.remove();
1268
+ panels.delete(id);
1269
+ panel = null;
1270
+ }
1271
+ if (!panel) {
1272
+ panel = document.createElement('div');
1273
+ panel.className = 'mail-settings-panel';
1274
+ panel.dataset.account = String(currentAccountId ?? '');
1275
+ main.appendChild(panel);
1276
+ panels.set(id, panel);
1277
+ panel.hidden = true;
1278
+ draw(section, panel);
1279
+ }
1280
+ return panel;
1281
+ }
1282
+ function show(id) {
1283
+ if (!ensure(id)) return;
1284
+ for (const item of items) item.active.value = item.id === id;
1285
+ for (const [key, el] of panels) el.hidden = key !== id;
1286
+ try { S.set('domma-mail.settings-section', id); } catch { /* storage off */ }
1287
+ }
1288
+ const navBindings = M.applyBindings({items, show}, body.querySelector('.mail-settings-nav'));
1289
+ // List sections are drawn (hidden) at once, so their items are in the menu on the first right-click.
1290
+ setTimeout(() => { for (const section of sections) if (section.collection) ensure(section.id); }, 0);
1291
+ closeFns.add(() => { try { navBindings?.dispose?.(); } catch { /* gone */ } });
1292
+ // The section list's own menu: right-click a section (or Shift+F10 on it).
1293
+ const navEl = body.querySelector('.mail-settings-nav');
1294
+ const navMenu = E?.contextMenu?.(navEl, {
1295
+ match: '.mail-settings-link', inherit: false, items: [],
1296
+ onBeforeOpen: (c) => {
1297
+ const label = c?.target?.closest?.('.mail-settings-link')?.textContent?.trim();
1298
+ const item = items.find(i => !i.isGroup && label && label.startsWith(i.label));
1299
+ if (!item) return false;
1300
+ const section = byId.get(item.id);
1301
+ // A list section's own items: drawn (hidden) first so they are known.
1302
+ if (section?.collection) ensure(item.id);
1303
+ let own = [];
1304
+ try { own = navProviders.get(item.id)?.() ?? []; } catch { own = []; }
1305
+ if (section?.collection && !navProviders.has(item.id)) own = [{label: 'Loading…', icon: 'clock', disabled: () => true, action: () => {}}];
1306
+ // Every action (and those in submenus) first brings its section into view.
1307
+ const wrap = (entry) => (entry.type === 'divider' || entry.type === 'header' ? entry
1308
+ : Array.isArray(entry.submenu) ? {...entry, submenu: entry.submenu.map(wrap)}
1309
+ : !entry.action ? entry : {...entry, action: () => { show(item.id); entry.action(); }});
1310
+ navMenu.setItems([
1311
+ ...own.map(wrap),
1312
+ ...(own.length ? [{type: 'divider'}] : [{label: `Open ${item.label}`, icon: 'arrow-right', action: () => show(item.id)}]),
1313
+ ...(section?.guide ? [{label: `Help for ${item.label}`, icon: 'help-circle', action: () => {
1314
+ show(item.id);
1315
+ setTimeout(() => panels.get(item.id)?.querySelector('.mail-section-help')?.click(), 50);
1316
+ }}] : []),
1317
+ {type: 'divider'},
1318
+ {label: 'Back to mail', icon: 'arrow-left', action: () => slideover.close()}
1319
+ ]);
1320
+ return true;
1321
+ }
1322
+ });
1323
+ const onNavKey = (event) => {
1324
+ if (event.key === 'F10' && event.shiftKey && event.target.closest?.('.mail-settings-link')) {
1325
+ event.preventDefault();
1326
+ openMenuAt(event.target.closest('.mail-settings-link'));
1327
+ }
1328
+ };
1329
+ navEl.addEventListener('keydown', onNavKey);
1330
+ closeFns.add(() => { navEl.removeEventListener('keydown', onNavKey); try { navMenu?.destroy?.(); } catch { /* gone */ } });
1331
+
1332
+ refreshPips = () => {
1333
+ const dirty = new Set(dirtyGuards().map(g => guardSection.get(g)).filter(Boolean));
1334
+ for (const item of items) if (!item.isGroup) item.dirty.value = dirty.has(item.id);
1335
+ };
1336
+ const onEdit = () => setTimeout(() => refreshPips(), 0);
1337
+ for (const type of ['input', 'change', 'keyup', 'click']) body.addEventListener(type, onEdit, true);
1338
+ const pipTimer = setInterval(() => refreshPips(), 1000);
1339
+ closeFns.add(() => clearInterval(pipTimer));
1340
+
1341
+ slideover.element.appendChild(body);
1342
+ let remembered = null;
1343
+ try { remembered = S.get('domma-mail.settings-section'); } catch { /* storage off */ }
1344
+ const first = [target?.section, remembered, groups[0]?.sections[0]?.id].find(id => byId.has(id));
1345
+ slideover.open();
1346
+ show(first);
1347
+ }
1348
+
1349
+ if (asScreen) {
1350
+ drawScreen();
1351
+ return;
1352
+ }
1132
1353
  if (sections.length === 1) {
1133
1354
  host.appendChild(document.createElement('div'));
1134
1355
  draw(sections[0], host.lastChild);
@@ -1234,6 +1455,7 @@ return {
1234
1455
  function redraw() {
1235
1456
  const focused = document.activeElement?.closest?.('.mail-box-row')?.dataset.id ?? null;
1236
1457
  const next = mailboxSectionBody(redraw);
1458
+ try { body.__dispose?.(); } catch { /* gone */ }
1237
1459
  body.replaceWith(next);
1238
1460
  body = next;
1239
1461
  Domma.icons.scan(body);
@@ -1246,6 +1468,15 @@ return {
1246
1468
  };
1247
1469
  const boxOf = (row) => mailboxes.find(b => b.id === row?.dataset.id) ?? null;
1248
1470
 
1471
+ // The settings list's right-click on "Mailboxes": each mailbox, then Add mailbox.
1472
+ ctx?.navMenu?.(() => [
1473
+ ...mailboxes.map(box => ({label: box.label || box.username || 'Mailbox', icon: box.id === currentAccountId ? 'check' : 'inbox',
1474
+ submenu: mailboxRowItems(box, redraw, container).filter(e => !/^Add /.test(e.label ?? ''))
1475
+ .filter((e, n, all) => e.type !== 'divider' || (n < all.length - 1 && all[n + 1].type !== 'divider'))})),
1476
+ {type: 'divider'},
1477
+ {label: 'Add mailbox…', icon: 'plus', action: () => openMailboxForm(null)}
1478
+ ]);
1479
+
1249
1480
  const elements = (typeof E !== 'undefined' && E?.contextMenu) ? E
1250
1481
  : (typeof Domma !== 'undefined' ? Domma?.elements : null);
1251
1482
  let menu = null;
@@ -1257,7 +1488,7 @@ return {
1257
1488
  onBeforeOpen: (c) => {
1258
1489
  const box = boxOf(rowOf(c?.target));
1259
1490
  if (!box) return false;
1260
- menu.setItems(mailboxRowItems(box, redraw));
1491
+ menu.setItems(mailboxRowItems(box, redraw, container));
1261
1492
  return true;
1262
1493
  }
1263
1494
  });
@@ -1279,11 +1510,21 @@ return {
1279
1510
  }
1280
1511
  };
1281
1512
  container.addEventListener('keydown', onKey);
1513
+ // A click on a row (not its buttons) edits it - the row's main action.
1514
+ const onClick = (event) => {
1515
+ const row = rowOf(event.target);
1516
+ if (!row || event.target.closest('button')) return;
1517
+ const box = boxOf(row);
1518
+ if (box) openMailboxForm(box);
1519
+ };
1520
+ container.addEventListener('click', onClick);
1521
+ ctx?.onClose?.(() => container.removeEventListener('click', onClick));
1282
1522
  // Saved, removed or connected elsewhere (the form, the folder
1283
1523
  // pane's menu): the rows follow.
1284
1524
  mailboxRedraws.add(redraw);
1285
1525
  ctx?.onClose?.(() => {
1286
1526
  mailboxRedraws.delete(redraw);
1527
+ try { body.__dispose?.(); } catch { /* gone */ }
1287
1528
  container.removeEventListener('keydown', onKey);
1288
1529
  try { menu?.destroy?.(); } catch { /* gone */ }
1289
1530
  });
@@ -1303,15 +1544,78 @@ return {
1303
1544
  * @param {Function} redraw
1304
1545
  * @returns {object[]}
1305
1546
  */
1306
- function mailboxRowItems(box, redraw) {
1307
- return menuItems(mailboxRowMenuModel({isDefault: box.isDefault === true, count: mailboxes.length}), {
1547
+ function mailboxRowItems(box, redraw, container = null) {
1548
+ const signIn = describeSignIn?.(box) ?? null;
1549
+ return menuItems(mailboxRowMenuModel({isDefault: box.isDefault === true, count: mailboxes.length,
1550
+ oauth: Boolean(box.oauth), needsSignIn: Boolean(signIn && signIn.tone !== 'ok'),
1551
+ isOpen: box.id === currentAccountId}), {
1308
1552
  edit: () => openMailboxForm(box),
1309
1553
  open: () => openMailboxInReader(box),
1554
+ refresh: () => checkMailboxNow(box),
1555
+ test: () => testMailbox(box),
1556
+ // The sign-in (Connect / Reconnect) lives in the mailbox's form.
1557
+ reconnect: () => openMailboxForm(box),
1558
+ folders: () => showMailboxFolders(box, container),
1310
1559
  default: () => toggleDefaultMailbox(box, redraw),
1311
- remove: () => removeMailbox(box, redraw)
1560
+ remove: () => removeMailbox(box, redraw),
1561
+ add: () => openMailboxForm(null)
1312
1562
  });
1313
1563
  }
1314
1564
 
1565
+ /**
1566
+ * Try a saved mailbox's connection as stored (the server uses the stored password or
1567
+ * sign-in), and say how it went.
1568
+ *
1569
+ * @param {object} box
1570
+ * @returns {Promise<void>}
1571
+ */
1572
+ async function testMailbox(box) {
1573
+ E.toast(`Connecting to "${box.label}"…`, {type: 'info'});
1574
+ try {
1575
+ const result = await api(`${BASE}/accounts/test`, 'POST', {
1576
+ id: box.id, label: box.label, host: box.host, port: box.port, secure: box.secure,
1577
+ username: box.username, password: '', ...(box.oauth ? {oauth: box.oauth} : {})
1578
+ });
1579
+ if (!here()) return;
1580
+ E.toast(result.ok ? `"${box.label}" connected successfully.` : (result.error || 'It did not connect.'),
1581
+ {type: result.ok ? 'success' : 'error'});
1582
+ } catch (err) {
1583
+ if (here()) E.toast(err.message, {type: 'error'});
1584
+ }
1585
+ }
1586
+
1587
+ /**
1588
+ * Check a mailbox for new mail now - opening it in the reader first if it is not the one open.
1589
+ *
1590
+ * @param {object} box
1591
+ * @returns {Promise<void>}
1592
+ */
1593
+ async function checkMailboxNow(box) {
1594
+ if (box.id !== currentAccountId) await selectAccount(box.id);
1595
+ if (!here()) return;
1596
+ await refreshMailbox();
1597
+ E.toast(`Checked "${box.label}".`, {type: 'success'});
1598
+ }
1599
+
1600
+ /**
1601
+ * Go to the Folders settings for this mailbox: it becomes the open mailbox (settings
1602
+ * apply to the open one), then the Folders section is shown - by its nav link on the
1603
+ * settings screen, or the Folders tab in the slideover.
1604
+ *
1605
+ * @param {object} box
1606
+ * @param {HTMLElement|null} container
1607
+ * @returns {Promise<void>}
1608
+ */
1609
+ async function showMailboxFolders(box, container) {
1610
+ if (box.id !== currentAccountId) await selectAccount(box.id);
1611
+ if (!here()) return;
1612
+ const shell = container?.closest?.('.mail-settings-screen, .dm-slideover');
1613
+ const link = [...(shell?.querySelectorAll('.mail-settings-link, .tab-item') ?? [])]
1614
+ .find(el => el.textContent.trim().replace(/\s+/g, ' ').startsWith('Folders'));
1615
+ if (link) link.click();
1616
+ else E.toast('Open Settings > Folders to choose which folders are kept in step.', {type: 'info'});
1617
+ }
1618
+
1315
1619
  /**
1316
1620
  * Show a mailbox in the reader, closing Settings to do it.
1317
1621
  *
@@ -1382,95 +1686,58 @@ return {
1382
1686
  * @returns {HTMLElement}
1383
1687
  */
1384
1688
  function mailboxSectionBody(redraw) {
1689
+ // Built with domma-reactive: one row per mailbox, drawn from plain values worked out
1690
+ // here (the body is rebuilt whole when the list changes, so no row needs to follow
1691
+ // a change in place). Chips and labels are text, never markup.
1692
+ const rows = mailboxes.map(box => {
1693
+ const signIn = describeSignIn?.(box) ?? null;
1694
+ const draft = Boolean(readMailboxDraft(box.id));
1695
+ return {
1696
+ id: box.id,
1697
+ label: box.label,
1698
+ sub: signIn
1699
+ ? `${box.username} · ${box.oauth.provider === 'google' ? 'Google' : 'Microsoft'} sign-in`
1700
+ : `${box.username} · ${box.host}:${box.port}${box.secure ? '' : ' (no TLS)'}`,
1701
+ isDefault: box.isDefault === true && mailboxes.length > 1,
1702
+ isOpen: box.id === currentAccountId && mailboxes.length > 1,
1703
+ signInChip: signIn && signIn.tone !== 'ok' ? signIn.chip : '',
1704
+ signInText: signIn && signIn.tone !== 'ok' ? signIn.text : '',
1705
+ signInClass: signIn && signIn.tone !== 'ok' ? `badge mail-oauth-chip mail-oauth-chip--${signIn.tone}` : 'badge',
1706
+ draft,
1707
+ aria: `${box.label} - Enter to edit, Shift+F10 for actions`
1708
+ };
1709
+ });
1385
1710
  const body = document.createElement('div');
1386
1711
  body.className = 'flex flex-col gap-2';
1387
-
1388
- if (!mailboxes.length) {
1389
- const empty = document.createElement('p');
1390
- empty.className = 'text-sm text-muted mail-empty-line';
1391
- empty.textContent = 'No mailboxes yet. Add one to read its mail here.';
1392
- body.appendChild(empty);
1393
- }
1394
-
1395
- for (const box of mailboxes) {
1396
- const row = document.createElement('div');
1397
- row.className = 'mail-box-row';
1398
- row.dataset.id = box.id;
1399
- row.tabIndex = 0;
1400
- row.setAttribute('aria-label', `${box.label} - Enter to edit, Shift+F10 for actions`);
1401
- row.title = 'Right-click, ⋮ or Shift+F10 for actions';
1402
-
1403
- const info = document.createElement('div');
1404
- info.className = 'flex-1 mail-ellipsis';
1405
- const name = document.createElement('div');
1406
- name.className = 'font-semibold text-sm';
1407
- name.textContent = box.label;
1408
- if (box.isDefault && mailboxes.length > 1) {
1409
- const badge = document.createElement('span');
1410
- badge.className = 'badge badge-primary mail-default-badge';
1411
- badge.textContent = 'Default';
1412
- name.appendChild(badge);
1413
- }
1414
- if (box.id === currentAccountId && mailboxes.length > 1) {
1415
- const open = document.createElement('span');
1416
- open.className = 'badge badge-secondary mail-default-badge';
1417
- open.textContent = 'Open';
1418
- name.appendChild(open);
1419
- }
1420
- const sub = document.createElement('div');
1421
- sub.className = 'text-xs text-muted mail-box-sub';
1422
- const signIn = describeSignIn?.(box) ?? null;
1423
- sub.textContent = signIn
1424
- ? `${box.username} · ${box.oauth.provider === 'google' ? 'Google' : 'Microsoft'} sign-in`
1425
- : `${box.username} · ${box.host}:${box.port}${box.secure ? '' : ' (no TLS)'}`;
1426
- if (signIn && signIn.tone !== 'ok') {
1427
- const chip = document.createElement('span');
1428
- chip.className = `badge mail-oauth-chip mail-oauth-chip--${signIn.tone}`;
1429
- chip.textContent = signIn.chip;
1430
- chip.title = signIn.text;
1431
- name.appendChild(chip);
1432
- }
1433
- if (readMailboxDraft(box.id)) {
1434
- const chip = document.createElement('span');
1435
- chip.className = 'badge badge-warning mail-default-badge';
1436
- chip.textContent = 'Unsaved changes';
1437
- chip.title = 'You left changes to this mailbox unsaved - Edit to pick them up or throw them away';
1438
- name.appendChild(chip);
1439
- }
1440
- info.appendChild(name);
1441
- info.appendChild(sub);
1442
- row.appendChild(info);
1443
-
1444
- const editBtn = document.createElement('button');
1445
- editBtn.type = 'button';
1446
- editBtn.className = 'btn btn-sm btn-ghost';
1447
- editBtn.textContent = 'Edit';
1448
- editBtn.addEventListener('click', () => openMailboxForm(box));
1449
- row.appendChild(editBtn);
1450
-
1451
- const more = document.createElement('button');
1452
- more.type = 'button';
1453
- more.className = 'btn btn-sm btn-ghost mail-row-more';
1454
- more.title = 'More actions';
1455
- more.setAttribute('aria-label', 'More actions');
1456
- more.setAttribute('aria-haspopup', 'menu');
1457
- const glyph = document.createElement('span');
1458
- glyph.setAttribute('data-icon', 'more-vertical');
1459
- glyph.setAttribute('data-icon-size', '14');
1460
- more.appendChild(glyph);
1461
- more.addEventListener('click', () => openMenuAt(more));
1462
- row.appendChild(more);
1463
-
1464
- body.appendChild(row);
1465
- }
1466
-
1467
- const addBtn = document.createElement('button');
1468
- addBtn.type = 'button';
1469
- addBtn.className = 'btn btn-sm btn-primary';
1470
- addBtn.classList.add('mail-add-btn');
1471
- addBtn.textContent = readMailboxDraft(null) ? 'Add mailbox (unsaved changes)' : 'Add mailbox';
1472
- addBtn.addEventListener('click', () => openMailboxForm(null));
1473
- body.appendChild(addBtn);
1712
+ body.innerHTML = `
1713
+ <p class="text-sm text-muted mail-empty-line" data-bind-hidden="rows.length">No mailboxes yet. Add one to read its mail here.</p>
1714
+ <div class="flex flex-col gap-2" data-each="rows key=id">
1715
+ <div class="mail-box-row" tabindex="0" data-bind-data-id="id" data-bind-aria-label="aria" title="Click to edit - right-click, ⋮ or Shift+F10 for actions">
1716
+ <div class="flex-1 mail-ellipsis">
1717
+ <div class="font-semibold text-sm"><span data-bind-text="label"></span><span class="badge badge-primary mail-default-badge" data-bind-hidden="!isDefault">Default</span><span class="badge badge-secondary mail-default-badge" data-bind-hidden="!isOpen">Open</span><span data-bind-class="signInClass" data-bind-hidden="!signInChip" data-bind-text="signInChip" data-bind-title="signInText"></span><span class="badge badge-warning mail-default-badge" data-bind-hidden="!draft" title="You left changes to this mailbox unsaved - Edit to pick them up or throw them away">Unsaved changes</span></div>
1718
+ <div class="text-xs text-muted mail-box-sub" data-bind-text="sub"></div>
1719
+ </div>
1720
+ <button type="button" class="btn btn-sm btn-ghost" data-on-click="$root.edit($data)">Edit</button>
1721
+ <button type="button" class="btn btn-sm btn-ghost mail-row-more" title="More actions" aria-label="More actions" aria-haspopup="menu" data-on-click="$root.more($data)"><span data-icon="more-vertical" data-icon-size="14"></span></button>
1722
+ </div>
1723
+ </div>
1724
+ <hr class="mail-list-divider">
1725
+ <div class="flex items-center gap-2">
1726
+ <button type="button" class="btn btn-sm btn-primary mail-add-btn" data-on-click="add" data-bind-text="addLabel"></button>
1727
+ <span data-help-title="Add a mailbox" data-help="Any IMAP account: your server's address, port and security, and the username and password you sign in with. A Microsoft or Google mailbox can sign in with its own button where the edition offers it."></span>
1728
+ </div>`;
1729
+ const model = {
1730
+ rows,
1731
+ addLabel: readMailboxDraft(null) ? '+ Add mailbox (unsaved changes)' : '+ Add mailbox',
1732
+ edit(row) { const box = mailboxes.find(b => b.id === row.id); if (box) openMailboxForm(box); },
1733
+ more(row, event) {
1734
+ event?.stopPropagation?.();
1735
+ openMenuAt(event?.currentTarget ?? body.querySelector(`.mail-box-row[data-id="${CSS.escape(row.id)}"] .mail-row-more`));
1736
+ },
1737
+ add() { openMailboxForm(null); }
1738
+ };
1739
+ const bindings = M.applyBindings(model, body);
1740
+ body.__dispose = () => { try { bindings?.dispose?.(); } catch { /* gone */ } };
1474
1741
  Domma.icons.scan(body);
1475
1742
 
1476
1743
  return body;
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.31.0, packages/core/src/admin/mail/reader-view.js.
1
+ // Source: @domma-mail/core 0.32.0, packages/core/src/admin/mail/reader-view.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /** Existing CMS entry point for the shared mail view. */
4
4
  const version = new URL(import.meta.url).searchParams.get('v') ?? '1';
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.31.0, packages/core/src/admin/mail/resizable.js.
1
+ // Source: @domma-mail/core 0.32.0, packages/core/src/admin/mail/resizable.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * The mail reader's resizable slideovers.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.31.0, packages/core/src/admin/mail/restore-spam.js.
1
+ // Source: @domma-mail/core 0.32.0, packages/core/src/admin/mail/restore-spam.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /** Undo restores both junk status and the original folder, following each UID remap. */
4
4
  export async function restoreSpam({api, base, account, from, destination, uids, spam}) {
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.31.0, packages/core/src/admin/mail/rules.js.
1
+ // Source: @domma-mail/core 0.32.0, packages/core/src/admin/mail/rules.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Filing rules.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.31.0, packages/core/src/admin/mail/scheduling.js.
1
+ // Source: @domma-mail/core 0.32.0, packages/core/src/admin/mail/scheduling.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  const MAIL_MODULE_VERSION = new URL(import.meta.url).searchParams.get('v') ?? '1';
4
4
  /**
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.31.0, packages/core/src/admin/mail/section-kit.js.
1
+ // Source: @domma-mail/core 0.32.0, packages/core/src/admin/mail/section-kit.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  const MAIL_MODULE_VERSION = new URL(import.meta.url).searchParams.get('v') ?? '1';
4
4
  /**
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.31.0, packages/core/src/admin/mail/security-note.js.
1
+ // Source: @domma-mail/core 0.32.0, packages/core/src/admin/mail/security-note.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * What the reader says about a signed or encrypted (S/MIME) message.