domma-cms 1.79.0 → 1.81.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 (123) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/admin/css/site-settings.css +1 -1
  3. package/admin/js/lib/site-settings-arrange.js +3 -3
  4. package/admin/js/templates/docs/usage-site-settings.html +29 -3
  5. package/admin/js/templates/settings.html +94 -4
  6. package/admin/js/views/settings.js +3 -3
  7. package/docs/DommaFeatures.md +51 -2
  8. package/docs/plans/2026-11-19-brand-kit-design.md +1 -1
  9. package/docs/plugin-development.md +6 -0
  10. package/package.json +1 -1
  11. package/plugins/_lib/admin/mail/attach-arrange.js +132 -5
  12. package/plugins/_lib/admin/mail/body-menu.js +1 -1
  13. package/plugins/_lib/admin/mail/cms-attach.js +79 -7
  14. package/plugins/_lib/admin/mail/cms-host.js +1 -1
  15. package/plugins/_lib/admin/mail/compose-window.js +15 -5
  16. package/plugins/_lib/admin/mail/contacts.js +1 -1
  17. package/plugins/_lib/admin/mail/diagnostics-section.js +1 -1
  18. package/plugins/_lib/admin/mail/drag-drop.js +33 -1
  19. package/plugins/_lib/admin/mail/folder-tree.js +1 -1
  20. package/plugins/_lib/admin/mail/font-controls.js +1 -1
  21. package/plugins/_lib/admin/mail/fonts.js +1 -1
  22. package/plugins/_lib/admin/mail/host-context.js +1 -1
  23. package/plugins/_lib/admin/mail/identity.js +1 -1
  24. package/plugins/_lib/admin/mail/image-senders-section.js +1 -1
  25. package/plugins/_lib/admin/mail/keyboard.js +1 -1
  26. package/plugins/_lib/admin/mail/mail.html +1 -1
  27. package/plugins/_lib/admin/mail/message-actions.js +1 -1
  28. package/plugins/_lib/admin/mail/oauth-panel.js +1 -1
  29. package/plugins/_lib/admin/mail/panes.js +1 -1
  30. package/plugins/_lib/admin/mail/reader-kit.js +1 -1
  31. package/plugins/_lib/admin/mail/reader-runtime.js +119 -63
  32. package/plugins/_lib/admin/mail/reader-view.js +1 -1
  33. package/plugins/_lib/admin/mail/resizable.js +1 -1
  34. package/plugins/_lib/admin/mail/restore-spam.js +1 -1
  35. package/plugins/_lib/admin/mail/rules.js +1 -1
  36. package/plugins/_lib/admin/mail/scheduling.js +1 -1
  37. package/plugins/_lib/admin/mail/section-kit.js +1 -1
  38. package/plugins/_lib/admin/mail/security-note.js +1 -1
  39. package/plugins/_lib/admin/mail/settings-section.js +6 -3
  40. package/plugins/_lib/admin/mail/templates.js +1 -1
  41. package/plugins/_lib/admin/mail/threads.js +1 -1
  42. package/plugins/_lib/admin/mail/vacation.js +1 -1
  43. package/plugins/_lib/admin/mail/when-closed.js +1 -1
  44. package/plugins/_lib/admin/ui/dates.js +1 -1
  45. package/plugins/_lib/admin/ui/resizable.js +1 -1
  46. package/plugins/_lib/admin/ui/rich-field.js +1 -1
  47. package/plugins/_lib/domma-mail.lock.json +85 -85
  48. package/plugins/_lib/mail/accountFileStore.js +1 -1
  49. package/plugins/_lib/mail/accountRepository.js +41 -2
  50. package/plugins/_lib/mail/accountRoutes.js +1 -1
  51. package/plugins/_lib/mail/bodyTokenProvider.js +1 -1
  52. package/plugins/_lib/mail/bodyTokens.js +1 -1
  53. package/plugins/_lib/mail/compose.js +1 -1
  54. package/plugins/_lib/mail/defaults.js +1 -1
  55. package/plugins/_lib/mail/envelope.js +1 -1
  56. package/plugins/_lib/mail/folderActions.js +1 -1
  57. package/plugins/_lib/mail/folderRuntime.js +1 -1
  58. package/plugins/_lib/mail/folders.js +1 -1
  59. package/plugins/_lib/mail/imapPoolRuntime.js +1 -1
  60. package/plugins/_lib/mail/mbox.js +1 -1
  61. package/plugins/_lib/mail/message-action.js +1 -1
  62. package/plugins/_lib/mail/messageSecurity.js +1 -1
  63. package/plugins/_lib/mail/messageSecurityProvider.js +1 -1
  64. package/plugins/_lib/mail/networkAddresses.js +1 -1
  65. package/plugins/_lib/mail/networkPolicy.js +1 -1
  66. package/plugins/_lib/mail/oauthAccounts.js +1 -1
  67. package/plugins/_lib/mail/oauthRouteRuntime.js +1 -1
  68. package/plugins/_lib/mail/oauthRuntime.js +1 -1
  69. package/plugins/_lib/mail/pollSchedule.js +1 -1
  70. package/plugins/_lib/mail/poller.js +1 -1
  71. package/plugins/_lib/mail/pollerRuntime.js +1 -1
  72. package/plugins/_lib/mail/priority.js +1 -1
  73. package/plugins/_lib/mail/publicMailbox.js +1 -1
  74. package/plugins/_lib/mail/readRuntime.js +1 -1
  75. package/plugins/_lib/mail/render.js +1 -1
  76. package/plugins/_lib/mail/ruleRunner.js +1 -1
  77. package/plugins/_lib/mail/schedulerRuntime.js +1 -1
  78. package/plugins/_lib/mail/secretProvider.js +1 -1
  79. package/plugins/_lib/mail/secretbox.js +1 -1
  80. package/plugins/_lib/mail/senderAuth.js +1 -1
  81. package/plugins/_lib/mail/sieve.js +1 -1
  82. package/plugins/_lib/mail/smtpService.js +1 -1
  83. package/plugins/_lib/mail/snoozeRuntime.js +1 -1
  84. package/plugins/_lib/mail/store.js +1 -1
  85. package/plugins/_lib/mail/subscriptions.js +1 -1
  86. package/plugins/_lib/mail/syncPlan.js +1 -1
  87. package/plugins/_lib/mail/syncRuntime.js +1 -1
  88. package/plugins/_lib/mail/syncSelection.js +1 -1
  89. package/plugins/_lib/mail/unreadBadge.js +1 -1
  90. package/plugins/_lib/mail/unsubscribe.js +1 -1
  91. package/plugins/_lib/mail/vacationRuntime.js +1 -1
  92. package/plugins/_lib/mail/write.js +1 -1
  93. package/plugins/_lib/public/rich-text.mjs +1 -1
  94. package/plugins/_lib/rich-text.js +1 -1
  95. package/plugins/_lib/telegram/bot.js +120 -0
  96. package/plugins/free-tier.lock.json +26 -1
  97. package/plugins/telegram/CHANGELOG.md +5 -0
  98. package/plugins/telegram/CLAUDE.md +77 -0
  99. package/plugins/telegram/admin/css/index.css +68 -0
  100. package/plugins/telegram/admin/lib/arrange.js +103 -0
  101. package/plugins/telegram/admin/lib/kit.js +153 -0
  102. package/plugins/telegram/admin/templates/telegram.html +1 -0
  103. package/plugins/telegram/admin/views/chats.js +223 -0
  104. package/plugins/telegram/admin/views/connection.js +90 -0
  105. package/plugins/telegram/admin/views/telegram.js +89 -0
  106. package/plugins/telegram/admin/views/test.js +84 -0
  107. package/plugins/telegram/config.js +21 -0
  108. package/plugins/telegram/docs/guide.md +87 -0
  109. package/plugins/telegram/lib/messages.js +176 -0
  110. package/plugins/telegram/lib/queue.js +72 -0
  111. package/plugins/telegram/plugin.js +490 -0
  112. package/plugins/telegram/plugin.json +71 -0
  113. package/plugins/telegram/tests/api.test.js +381 -0
  114. package/plugins/telegram/tests/arrange.test.js +41 -0
  115. package/plugins/telegram/tests/messages.test.js +110 -0
  116. package/plugins/telegram/tests/queue.test.js +47 -0
  117. package/server/routes/api/brand-kit.js +55 -0
  118. package/server/routes/api/settings.js +17 -1
  119. package/server/server.js +2 -0
  120. package/server/services/brandKit.js +268 -0
  121. package/server/services/emailBrand.js +31 -13
  122. package/server/services/notify.js +20 -2
  123. package/server/services/plugins.js +3 -0
@@ -443,6 +443,12 @@ options.hooks.on('content:pageCreated', ({ page, urlPath }) => {
443
443
  In `data`, a file field is `{url, name, size, mime}`, a list of them when the field is `multiple`, or `''`;
444
444
  `fileRefs(value)` from `public/js/form-files.mjs` reads any of the three as a list.
445
445
 
446
+ #### Notification events
447
+
448
+ | Event | Payload | Fired when |
449
+ |-----------------------|----------------------------|------------|
450
+ | `notification:raised` | the stored entry `{ id, data, meta }` | A notification is stored by `notify()` (core or a plugin's), or a repeat with the same `dedupeKey` grows worse. Not fired for a quiet repeat, a switched-off source, a payload with no title or one held by the hourly cap. `data` has `title, body, severity, source, sourceLabel, link, audience, createdAt`. The Telegram Tool listens to it. |
451
+
446
452
  #### Auth events
447
453
 
448
454
  | Event | Payload | Fired when |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "domma-cms",
3
- "version": "1.79.0",
3
+ "version": "1.81.0",
4
4
  "description": "File-based CMS powered by Domma and Fastify. Run npx domma-cms my-site to create a new project.",
5
5
  "type": "module",
6
6
  "main": "server/server.js",
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/attach-arrange.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/attach-arrange.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Attachments from somewhere other than this computer: the pure part.
@@ -162,15 +162,142 @@ export function storeView(payload, {place = 'mine'} = {}) {
162
162
  * @param {Array<{size: number}>} chosen
163
163
  * @param {number} room - bytes left in the message before its limit (Infinity when unknown)
164
164
  */
165
- export function choiceSummary(chosen, room = Infinity) {
165
+ export function choiceSummary(chosen, room = Infinity, {canLink = false} = {}) {
166
166
  const n = chosen.length;
167
167
  const total = chosen.reduce((sum, f) => sum + sizeOf(f.size), 0);
168
- if (!n) return {text: 'Tick the files to attach.', ok: false, over: false};
168
+ if (!n) return {text: 'Tick the files to attach.', ok: false, over: false, linkOk: false};
169
169
  const many = n > MAX_PICK;
170
170
  const over = Number.isFinite(room) && total > room;
171
171
  const base = `${n} file${n === 1 ? '' : 's'}, ${formatSize(total)}`;
172
172
  return {
173
- text: many ? `${base}. No more than ${MAX_PICK} at a time.` : over ? `${base} - more than the ${formatSize(Math.max(0, room))} this message has room for.` : base,
174
- ok: !many && !over, over: over || many
173
+ text: many ? `${base}. No more than ${MAX_PICK} at a time.` : over ? `${base} - more than the ${formatSize(Math.max(0, room))} this message has room for.${canLink ? ' Send them as links instead.' : ''}` : base,
174
+ ok: !many && !over, over: over || many,
175
+ // Links carry no bytes, so only the count limits them.
176
+ linkOk: canLink && !many
175
177
  };
176
178
  }
179
+
180
+ const escHtml = (v) => String(v ?? '').replace(/[&<>"']/g, c => ({'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;'}[c]));
181
+
182
+ /**
183
+ * Links a source handed back instead of files (a file too big to attach, shared from where it is kept): only
184
+ * http(s) addresses, with a plain name.
185
+ *
186
+ * @returns {Array<{name: string, url: string, size: number}>}
187
+ */
188
+ export function cleanLinks(items, {max = MAX_PICK} = {}) {
189
+ const out = [];
190
+ for (const item of Array.isArray(items) ? items : []) {
191
+ if (!item || typeof item !== 'object') continue;
192
+ let u;
193
+ try { u = new URL(String(item.url ?? '')); } catch { continue; }
194
+ if (!/^https?:$/.test(u.protocol) || u.username || u.password) continue;
195
+ out.push({name: safeName(item.name), url: u.href, size: sizeOf(item.size)});
196
+ if (out.length === max) break;
197
+ }
198
+ return out;
199
+ }
200
+
201
+ /** "19 December 2026" from an ISO date, or '' when there is none or it cannot be read. */
202
+ export function linkDay(iso) {
203
+ // An ISO date and nothing looser: Date.parse reads "5" as a day in 2001.
204
+ const t = /^\d{4}-\d\d-\d\dT/.test(String(iso ?? '')) ? Date.parse(String(iso)) : NaN;
205
+ return Number.isFinite(t) ? new Date(t).toLocaleDateString('en-GB', {day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC'}) : '';
206
+ }
207
+
208
+ /**
209
+ * The paragraph a message gets for links: as HTML for the editor and as plain text for a plain body. Every name
210
+ * and address is escaped; `links` is what cleanLinks() returned.
211
+ */
212
+ export function linkBlock(links, {expiresAt = ''} = {}) {
213
+ if (!links.length) return {html: '', text: ''};
214
+ const many = links.length > 1;
215
+ const until = linkDay(expiresAt);
216
+ // Said plainly, and true whether the file was too large to attach or simply better sent this way.
217
+ const lead = many ? 'Here are links to download the files:' : 'Here is a link to download the file:';
218
+ const tail = until ? `${many ? 'The links work' : 'The link works'} until ${until}.` : '';
219
+ const size = (l) => (l.size ? ` (${formatSize(l.size)})` : '');
220
+ return {
221
+ // The address itself is the link's text: it survives into the plain-text part of the mail, and a name that
222
+ // looks like another address cannot dress up where the link goes.
223
+ html: `<p>${lead}</p><ul>${links.map(l => `<li>${escHtml(l.name)}${escHtml(size(l))}: <a href="${escHtml(l.url)}">${escHtml(l.url)}</a></li>`).join('')}</ul>${tail ? `<p>${tail}</p>` : ''}`,
224
+ text: [lead, ...links.map(l => `- ${l.name}${size(l)}: ${l.url}`), ...(tail ? [tail] : [])].join('\n')
225
+ };
226
+ }
227
+
228
+ /** The words in a piece of HTML, with tags, spaces and non-breaking spaces gone: '' means "nothing a person wrote". */
229
+ const wordsIn = (html) => String(html).replace(/<[^>]*>/g, '').replace(/&nbsp;|&#160;|\s/g, '');
230
+
231
+ const SIGNATURE = /<div\b[^>]*\bclass=(["'])[^"']*\bdm-mail-signature\b[^"']*\1[^>]*>/gi;
232
+
233
+ /** Where each top-level blockquote starts and ends, and how deep in blockquotes any index is. */
234
+ function quotesOf(html) {
235
+ const tops = [];
236
+ const marks = [];
237
+ let depth = 0;
238
+ let start = -1;
239
+ for (const m of html.matchAll(/<(\/?)blockquote\b[^>]*>/gi)) {
240
+ if (!m[1]) { if (depth === 0) start = m.index; depth++; }
241
+ else if (depth > 0) { depth--; if (depth === 0) tops.push({start, end: m.index + m[0].length}); }
242
+ marks.push({at: m.index, depth});
243
+ }
244
+ const depthAt = (i) => { let d = 0; for (const k of marks) { if (k.at >= i) break; d = k.depth; } return d; };
245
+ return {tops, depthAt};
246
+ }
247
+
248
+ /**
249
+ * A message's HTML with a block put where the writer's own words end.
250
+ *
251
+ * - A reply or forward written above the quoted message (the usual way): before the line that introduces the
252
+ * quote ("On 3 Nov, Sam wrote:") - or before the writer's signature, if that comes first.
253
+ * - Otherwise before the writer's signature, if there is one outside any quotation (a signature inside quoted
254
+ * text is the other person's).
255
+ * - Otherwise at the end. That covers a new message, an answer written under the quote, and a quotation the
256
+ * writer put in the middle of their own text.
257
+ */
258
+ export function placeBlock(html, block) {
259
+ const body = String(html ?? '');
260
+ if (!block) return body;
261
+ const {tops, depthAt} = quotesOf(body);
262
+ const sig = [...body.matchAll(SIGNATURE)].map(m => m.index).find(i => depthAt(i) === 0) ?? -1;
263
+ const put = (at) => body.slice(0, at) + block + body.slice(at);
264
+ const last = tops.at(-1);
265
+ if (last) {
266
+ // Nothing of the writer's after the quote (their signature aside): the message was written above it.
267
+ const after = sig >= last.end ? body.slice(last.end, sig) : body.slice(last.end);
268
+ if (!wordsIn(after)) {
269
+ let at = last.start;
270
+ const lead = /(?:<p>(?:<br\s*\/?>|\s|&nbsp;)*<\/p>\s*)?<p>(?:(?!<\/p>)[\s\S])*<\/p>\s*$/i.exec(body.slice(0, at));
271
+ if (lead && wordsIn(lead[0])) at = lead.index;
272
+ return put(sig >= 0 && sig < at ? sig : at);
273
+ }
274
+ }
275
+ return sig >= 0 ? put(sig) : body + block;
276
+ }
277
+
278
+ /** The same for a plain-text body: above the line introducing quoted text, or above the "-- " signature, or at the end. */
279
+ export function placeText(body, block) {
280
+ const text = String(body ?? '');
281
+ if (!block) return text;
282
+ const lines = text.split('\n');
283
+ const isQuote = (l) => l.startsWith('>');
284
+ const sig = lines.findIndex(l => l === '-- ' || l === '--');
285
+ const first = lines.findIndex(isQuote);
286
+ const lastQuote = lines.findLastIndex(isQuote);
287
+ const put = (at) => {
288
+ const head = lines.slice(0, at).join('\n').replace(/\s+$/, '');
289
+ const tail = lines.slice(at).join('\n');
290
+ return `${head}${head ? '\n\n' : ''}${block}${tail ? `\n\n${tail}` : '\n'}`;
291
+ };
292
+ if (first >= 0) {
293
+ const end = sig > lastQuote ? sig : lines.length;
294
+ const wroteBelow = lines.slice(lastQuote + 1, end).some(l => l.trim());
295
+ if (!wroteBelow) {
296
+ // Step back over the line that introduces the quote ("On 3 Nov, Sam wrote:").
297
+ let at = first;
298
+ if (at > 0 && lines[at - 1].trim()) at--;
299
+ return put(sig >= 0 && sig < at ? sig : at);
300
+ }
301
+ }
302
+ return put(sig >= 0 ? sig : lines.length);
303
+ }
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/body-menu.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/body-menu.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * The reading pane's right-click menu - the pure parts.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/cms-attach.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/cms-attach.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Attachments from the CMS: Media and the File Store. CMS shell boundary - only cms-host.js imports this, and
@@ -16,6 +16,9 @@ const {choiceSummary, formatSize, mediaCrumbs, mediaEntries, mediaPath, mediaVie
16
16
  await import(new URL(`./attach-arrange.js?v=${version}`, import.meta.url).href);
17
17
 
18
18
  const STORE = '/api/plugins/file-store';
19
+ const STORE_PRO = '/api/plugins/file-store-pro';
20
+ /** How long a link made from compose lasts, in days: the choices offered, the first the default. */
21
+ const LINK_DAYS = [30, 7, 90];
19
22
 
20
23
  function el(tag, attrs = {}, ...kids) {
21
24
  const node = document.createElement(tag);
@@ -91,6 +94,29 @@ function storeProvider(host) {
91
94
  const res = await host.fetch(`${STORE}/files/${encodeURIComponent(file.fileId)}/download`, {headers: host.authHeaders(), redirect: 'error', signal});
92
95
  if (!res.ok) throw new Error(`${file.name} could not be fetched (${res.status}).`);
93
96
  return res.blob();
97
+ },
98
+ /**
99
+ * Share links, where File Store Pro is on and this person may make them: a file too big to attach goes as
100
+ * a link to where it already is. Asked each time the chooser opens; a failure only means no button.
101
+ */
102
+ async linking() {
103
+ try {
104
+ const st = await host.api(`${STORE_PRO}/status`);
105
+ if (!st?.ready || !st?.can?.share) return null;
106
+ const max = Number(st.maxDays) > 0 ? Number(st.maxDays) : LINK_DAYS[0];
107
+ return {days: [...new Set(LINK_DAYS.map(d => Math.min(d, max)))]};
108
+ } catch { return null; }
109
+ },
110
+ /** One share link for one file. File Store Pro decides: only the file's owner (or a manager) may make one. */
111
+ async link(file, days) {
112
+ const made = await host.api(`${STORE_PRO}/links`, 'POST', {kind: 'share', fileId: file.fileId, expiresDays: days, note: 'Sent by email'});
113
+ // A share link's own shape and nothing else: `/_share/../x` would be some other page of the site.
114
+ if (typeof made?.path !== 'string' || !/^\/_share\/[A-Za-z0-9_-]{16,64}$/.test(made.path)) throw new Error('The link could not be made.');
115
+ return {id: String(made.id || ''), name: file.name, size: file.size, url: new URL(made.path, location.origin).href, expiresAt: made.expiresAt || ''};
116
+ },
117
+ /** Take back a link that will not be used (the chooser was closed before its message got it). */
118
+ async unlink(id) {
119
+ if (/^[A-Za-z0-9_-]{1,64}$/.test(String(id))) await host.api(`${STORE_PRO}/links/${encodeURIComponent(id)}`, 'DELETE');
94
120
  }
95
121
  };
96
122
  }
@@ -115,6 +141,8 @@ const STYLE = `
115
141
  .mail-pick-meta { flex: none; font-size: var(--dm-text-xs, .75rem); color: var(--dm-text-muted); white-space: nowrap; max-width: 45%; overflow: hidden; text-overflow: ellipsis; }
116
142
  .mail-pick-note { padding: 1rem; margin: 0; color: var(--dm-text-muted); font-size: var(--dm-text-sm, .875rem); }
117
143
  .mail-pick-foot { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
144
+ .mail-pick-days { width: auto; flex: none; }
145
+ .mail-pick-foot [hidden] { display: none !important; }
118
146
  .mail-pick-sum { flex: 1; font-size: var(--dm-text-sm, .875rem); color: var(--dm-text-muted); }
119
147
  .mail-pick-sum[data-over="true"] { color: var(--dm-danger); }
120
148
  `;
@@ -125,7 +153,8 @@ const STYLE = `
125
153
  * @param {object} host - the mail host
126
154
  * @param {object} provider
127
155
  * @param {{remainingBytes?: number}} opts
128
- * @returns {Promise<Array<{filename, contentType, content}>>}
156
+ * @returns {Promise<Array<{filename, contentType, content}>|{attachments: [], links: Array<{name, url, size}>, expiresAt: string}>}
157
+ * files to attach, or - from "Send as links" - links for the message's body
129
158
  */
130
159
  function choose(host, provider, {remainingBytes = Infinity} = {}) {
131
160
  const {E} = host;
@@ -133,7 +162,7 @@ function choose(host, provider, {remainingBytes = Infinity} = {}) {
133
162
  let settled = false;
134
163
  const done = (list) => { if (!settled) { settled = true; resolve(list); } };
135
164
  const so = E.slideover({title: provider.title, size: 'md', position: 'right'});
136
- const chosen = new Map(); // id -> record, kept as the person moves between folders
165
+ const chosen = new Map(); // id -> record (with the place it was ticked in), kept as the person moves between folders and places
137
166
  let place = provider.places[0].id;
138
167
  let folder = '';
139
168
  let query = '';
@@ -150,15 +179,26 @@ function choose(host, provider, {remainingBytes = Infinity} = {}) {
150
179
  const sum = el('span', {class: 'mail-pick-sum', 'aria-live': 'polite'});
151
180
  const attach = el('button', {type: 'button', class: 'btn btn-primary btn-sm', text: 'Attach', disabled: true});
152
181
  const cancel = el('button', {type: 'button', class: 'btn btn-ghost btn-sm', text: 'Cancel', onclick: () => so.close()});
182
+ // "Send as links": drawn only once the provider has said this person can make them.
183
+ let linking = null;
184
+ const linkDays = el('select', {class: 'form-select mail-pick-days', 'aria-label': 'How long the links last', hidden: true});
185
+ const asLinks = el('button', {type: 'button', class: 'btn btn-outline btn-sm', text: 'Send as links', hidden: true, disabled: true,
186
+ title: 'Instead of attaching, put a link to each file in the message. For files too large to attach.'});
153
187
  const panel = el('div', {class: 'mail-pick'},
154
188
  el('div', {class: 'mail-pick-bar'}, provider.places.length > 1 ? places : null, search), crumbs, list,
155
- el('div', {class: 'mail-pick-foot'}, sum, cancel, attach));
189
+ el('div', {class: 'mail-pick-foot'}, sum, linkDays, cancel, asLinks, attach));
156
190
 
157
191
  const drawSum = () => {
158
- const s = choiceSummary([...chosen.values()], remainingBytes);
192
+ // Only a person's own files can be shared by link: the button is there while every ticked file is one of theirs.
193
+ const all = [...chosen.values()];
194
+ const canLink = Boolean(linking) && (all.length ? all.every(f => f.from === 'mine') : place === 'mine');
195
+ const s = choiceSummary([...chosen.values()], remainingBytes, {canLink});
159
196
  sum.textContent = fetching ? sum.textContent : s.text;
160
- sum.dataset.over = String(s.over);
197
+ sum.dataset.over = String(s.over && !s.linkOk);
161
198
  attach.disabled = fetching || !s.ok;
199
+ asLinks.hidden = linkDays.hidden = !canLink;
200
+ asLinks.disabled = fetching || !s.linkOk;
201
+ asLinks.textContent = chosen.size > 1 ? `Send ${chosen.size} as links` : 'Send as a link';
162
202
  attach.textContent = chosen.size > 1 ? `Attach ${chosen.size} files` : 'Attach';
163
203
  };
164
204
 
@@ -177,6 +217,7 @@ function choose(host, provider, {remainingBytes = Infinity} = {}) {
177
217
  async function load({focus = false} = {}) {
178
218
  const mine = ++visit;
179
219
  drawPlaces();
220
+ drawSum();
180
221
  list.replaceChildren(el('p', {class: 'mail-pick-note', text: 'Loading…'}));
181
222
  let view;
182
223
  try { view = await provider.browse({place, folder, query}); }
@@ -193,7 +234,7 @@ function choose(host, provider, {remainingBytes = Infinity} = {}) {
193
234
  const row = el('button', {type: 'button', class: 'mail-pick-row', role: 'checkbox', 'aria-checked': String(chosen.has(f.id)), onclick: () => {
194
235
  // What is being fetched is what was ticked when Attach was pressed.
195
236
  if (fetching) return;
196
- if (chosen.has(f.id)) chosen.delete(f.id); else chosen.set(f.id, f);
237
+ if (chosen.has(f.id)) chosen.delete(f.id); else chosen.set(f.id, {...f, from: place});
197
238
  box.textContent = chosen.has(f.id) ? '✓' : ''; row.setAttribute('aria-checked', String(chosen.has(f.id)));
198
239
  drawSum();
199
240
  }}, box, el('span', {class: 'mail-pick-name', text: f.name, title: f.name}), el('span', {class: 'mail-pick-meta', text: [f.where, formatSize(f.size)].filter(Boolean).join(' · ')}));
@@ -235,6 +276,29 @@ function choose(host, provider, {remainingBytes = Infinity} = {}) {
235
276
  }
236
277
  });
237
278
 
279
+ asLinks.addEventListener('click', async () => {
280
+ if (fetching || !linking) return;
281
+ fetching = true; drawSum();
282
+ const files = [...chosen.values()];
283
+ const days = Number(linkDays.value) || linking.days[0];
284
+ const links = [];
285
+ const refused = [];
286
+ // A link is live the moment it is made, so one that will reach no message is taken back.
287
+ const takeBack = () => { for (const l of links) provider.unlink?.(l.id).catch(() => {}); };
288
+ cancel.disabled = true;
289
+ for (const [i, f] of files.entries()) {
290
+ sum.textContent = `Making link ${i + 1} of ${files.length}: ${f.name}`;
291
+ try { links.push(await provider.link(f, days)); } catch (err) { refused.push({name: f.name, why: err?.status === 404 ? 'only its owner can share it' : (err?.message || 'the request failed')}); }
292
+ if (settled) { takeBack(); return; }
293
+ }
294
+ cancel.disabled = false;
295
+ if (refused.length) E.toast(refused.length === 1 ? `${refused[0].name} was not shared by link: ${refused[0].why}.` : `${refused.length} files were not shared by link. The first: ${refused[0].why}.`, {type: 'warning'});
296
+ if (!links.length) { fetching = false; drawSum(); return; }
297
+ done({attachments: [], links: links.map(({name, url, size}) => ({name, url, size})), expiresAt: links[0].expiresAt});
298
+ closedByUs = true;
299
+ so.close();
300
+ });
301
+
238
302
  const style = el('style', {text: STYLE});
239
303
  so.element.append(panel, style);
240
304
  const closed = () => { clearTimeout(typing); visit++; done([]); if (!closedByUs) stop.abort(); };
@@ -244,6 +308,14 @@ function choose(host, provider, {remainingBytes = Infinity} = {}) {
244
308
  so.open();
245
309
  drawSum();
246
310
  load();
311
+ if (typeof provider.linking === 'function') {
312
+ provider.linking().then((answer) => {
313
+ if (settled || !answer) return;
314
+ linking = answer;
315
+ linkDays.replaceChildren(...answer.days.map(d => el('option', {value: String(d), text: `Links last ${d} ${d === 1 ? 'day' : 'days'}`})));
316
+ drawSum();
317
+ }).catch(() => {});
318
+ }
247
319
  setTimeout(() => search.focus(), 60);
248
320
  });
249
321
  }
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/cms-host.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/cms-host.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /** The CMS shell boundary. Standalone never imports this adapter. */
4
4
  const version = new URL(import.meta.url).searchParams.get('v') ?? '1';
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/compose-window.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/compose-window.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);
@@ -11,7 +11,7 @@ const {makeResizable} = await import(new URL(`./resizable.js?v=${MAIL_MODULE_VER
11
11
  const {whenClosed} = await import(new URL(`./when-closed.js?v=${MAIL_MODULE_VERSION}`, import.meta.url).href);
12
12
  const {esc} = await import(new URL(`./reader-kit.js?v=${MAIL_MODULE_VERSION}`, import.meta.url).href);
13
13
  const {installFontControls} = await import(new URL(`./font-controls.js?v=${MAIL_MODULE_VERSION}`, import.meta.url).href);
14
- const {cleanPicked, cleanSources} = await import(new URL(`./attach-arrange.js?v=${MAIL_MODULE_VERSION}`, import.meta.url).href);
14
+ const {cleanLinks, cleanPicked, cleanSources, linkBlock, placeBlock, placeText} = await import(new URL(`./attach-arrange.js?v=${MAIL_MODULE_VERSION}`, import.meta.url).href);
15
15
  const {
16
16
  collectGroups,
17
17
  currentFragment,
@@ -680,11 +680,21 @@ export function createComposeWindow(mailHost) {
680
680
  try {
681
681
  const used = attachments.peek().reduce((n, a) => n + a.bytes, 0);
682
682
  const handed = await source.pick({remainingBytes: Math.max(0, maxAttachmentBytes - used)});
683
- const picked = cleanPicked(handed);
683
+ // A source hands back files to attach, or {attachments, links}: links go into the message itself.
684
+ const files = Array.isArray(handed) ? handed : handed?.attachments;
685
+ const picked = cleanPicked(files);
684
686
  if (picked.length) attachments.value = [...attachments.peek(), ...picked.map(file => ({key: `a${nextKey++}`, ...file}))];
687
+ const offered = Array.isArray(handed) || !Array.isArray(handed?.links) ? [] : handed.links;
688
+ const links = cleanLinks(offered);
689
+ if (links.length) {
690
+ const block = linkBlock(links, {expiresAt: handed.expiresAt});
691
+ if (editor) editor.setValue(placeBlock(editor.getValue(), block.html));
692
+ else bodyInput.value = placeText(bodyInput.value, block.text);
693
+ E.toast(`${links.length === 1 ? 'A link was' : `${links.length} links were`} put in the message.`, {type: 'success'});
694
+ }
685
695
  // Never dropped without a word: what could not be attached is said.
686
- const lost = (Array.isArray(handed) ? handed.length : 0) - picked.length;
687
- if (lost > 0) E.toast(`${lost} file${lost === 1 ? '' : 's'} could not be attached.`, {type: 'warning'});
696
+ const lost = (Array.isArray(files) ? files.length : 0) - picked.length + (offered.length - links.length);
697
+ if (lost > 0) E.toast(`${lost} file${lost === 1 ? '' : 's'} could not be ${offered.length ? 'added' : 'attached'}.`, {type: 'warning'});
688
698
  } catch (err) {
689
699
  E.toast(err?.message || 'Those files could not be attached.', {type: 'error'});
690
700
  } finally {
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/contacts.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/contacts.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Recipient suggestions from the host address book.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/diagnostics-section.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/diagnostics-section.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * The settings section that answers "which build is this, and what went wrong".
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/drag-drop.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/drag-drop.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /** Drag identities include the mailbox and source folder: UIDs alone are not unique. */
4
4
  const PROTECTED_USES = new Set(['\\Inbox', '\\Sent', '\\Drafts', '\\Trash', '\\Junk', '\\Archive', '\\All', '\\Flagged']);
@@ -44,3 +44,35 @@ export function messageMoveBatches(drag, destination) {
44
44
  return batches;
45
45
  });
46
46
  }
47
+
48
+ /**
49
+ * The ticked rows as batches per folder they live in: search results span folders, and a UID is only a message
50
+ * within its own folder. A ticked UID no longer on the page goes with the open folder, as it always did.
51
+ *
52
+ * @param {Set<number>} selected
53
+ * @param {{uid: number, folder?: string}[]} messages
54
+ * @param {string} currentFolder
55
+ * @param {number} [size] - UIDs per request
56
+ * @returns {{folder: string, uids: number[]}[]}
57
+ */
58
+ export function selectionBatches(selected, messages, currentFolder, size = 500) {
59
+ const groups = new Map();
60
+ const add = (folder, uid) => {
61
+ if (!folder || !Number.isInteger(uid) || uid < 1) return;
62
+ if (!groups.has(folder)) groups.set(folder, new Set());
63
+ groups.get(folder).add(uid);
64
+ };
65
+ const seen = new Set();
66
+ for (const row of messages ?? []) {
67
+ if (!selected.has(row.uid)) continue;
68
+ seen.add(row.uid);
69
+ add(row.folder ?? currentFolder, row.uid);
70
+ }
71
+ for (const uid of selected) if (!seen.has(uid)) add(currentFolder, uid);
72
+ const out = [];
73
+ for (const [folder, uids] of groups) {
74
+ const list = [...uids];
75
+ for (let at = 0; at < list.length; at += size) out.push({folder, uids: list.slice(at, at + size)});
76
+ }
77
+ return out;
78
+ }
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/folder-tree.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/folder-tree.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Mail folder presentation, shared by the Mail Reader and Email Pro.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/font-controls.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/font-controls.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.36.0, packages/core/src/admin/mail/fonts.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/fonts.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * The fonts and sizes the mail editor offers - pure, so both the compose
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/host-context.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/host-context.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /** Services supplied by the application that hosts the shared mail interface. */
4
4
  export function createMailApi({getToken, fetch: request = globalThis.fetch, onUnauthorized = () => {}}) {
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/identity.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/identity.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Who a mailbox sends as, and what it signs off with.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/image-senders-section.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/image-senders-section.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * The settings section for senders whose images always load.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/keyboard.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/keyboard.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Keyboard navigation for the reader.
@@ -1,4 +1,4 @@
1
- <!-- Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/mail.html. -->
1
+ <!-- Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/mail.html. -->
2
2
  <div class="mail-layout">
3
3
 
4
4
  <!-- Folders -->
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/message-actions.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/message-actions.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * What other Tools add to a message's menu - Booking's "Book Sam...".
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/oauth-panel.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/oauth-panel.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * "Sign in with Microsoft / Google" for a mailbox - the part of the mailbox
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/panes.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/panes.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Pane sizing for the mail reader, shared by the Mail Reader and Email Pro.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.36.0, packages/core/src/admin/mail/reader-kit.js.
1
+ // Source: @domma-mail/core 0.38.0, packages/core/src/admin/mail/reader-kit.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * The reader view's decisions that need no DOM - escaping, the mailbox form's