domma-cms 1.77.0 → 1.79.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 (111) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/admin/js/lib/site-settings-arrange.js +3 -3
  3. package/admin/js/templates/docs/usage-site-settings.html +29 -1
  4. package/admin/js/templates/settings.html +19 -0
  5. package/admin/js/views/settings.js +3 -3
  6. package/docs/DommaFeatures.md +62 -54
  7. package/docs/plans/2026-11-19-brand-kit-design.md +58 -0
  8. package/docs/screenshots/email-branding-gallery.png +0 -0
  9. package/docs/screenshots/email-branding-waypoint.png +0 -0
  10. package/package.json +1 -1
  11. package/plugins/_lib/admin/mail/attach-arrange.js +176 -0
  12. package/plugins/_lib/admin/mail/body-menu.js +1 -1
  13. package/plugins/_lib/admin/mail/cms-attach.js +268 -0
  14. package/plugins/_lib/admin/mail/cms-host.js +10 -3
  15. package/plugins/_lib/admin/mail/compose-window.js +37 -1
  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 +1 -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 +1 -1
  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 +1 -1
  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 -83
  48. package/plugins/_lib/mail/accountFileStore.js +1 -1
  49. package/plugins/_lib/mail/accountRepository.js +1 -1
  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/vacationRunner.js +14 -2
  92. package/plugins/_lib/mail/vacationRuntime.js +23 -5
  93. package/plugins/_lib/mail/write.js +1 -1
  94. package/plugins/_lib/outreach/sending.js +3 -1
  95. package/plugins/_lib/public/rich-text.mjs +1 -1
  96. package/plugins/_lib/rich-text.js +1 -1
  97. package/plugins/docs/CHANGELOG.md +5 -0
  98. package/plugins/docs/plugin.js +2 -2
  99. package/plugins/free-tier.lock.json +7 -7
  100. package/plugins/shopping-cart/CHANGELOG.md +5 -0
  101. package/plugins/shopping-cart/lib/accounts.js +1 -1
  102. package/plugins/support/CHANGELOG.md +5 -0
  103. package/plugins/support/lib/mail.js +2 -2
  104. package/server/routes/api/settings.js +28 -7
  105. package/server/services/actions.js +2 -1
  106. package/server/services/callInvites.js +1 -1
  107. package/server/services/email.js +10 -4
  108. package/server/services/emailBrand.js +126 -0
  109. package/server/services/emailExamples.js +37 -0
  110. package/server/services/instantCalls.js +1 -1
  111. package/server/services/passwordReset.js +4 -4
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.34.1, packages/core/src/mail/senderAuth.js.
1
+ // Source: @domma-mail/core 0.36.0, packages/core/src/mail/senderAuth.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Did this message really come from the address in its From line?
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.34.1, packages/core/src/mail/sieve.js.
1
+ // Source: @domma-mail/core 0.36.0, packages/core/src/mail/sieve.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /** ManageSieve (RFC 5804). One bounded, TLS-verified session per operation. */
4
4
  import net from 'node:net';
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.34.1, packages/core/src/mail/smtpService.js.
1
+ // Source: @domma-mail/core 0.36.0, packages/core/src/mail/smtpService.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Sending, and keeping a copy where the rest of your clients will find it.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.34.1, packages/core/src/mail/snoozeRuntime.js.
1
+ // Source: @domma-mail/core 0.36.0, packages/core/src/mail/snoozeRuntime.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  import {safeWritePool, moveMessage} from './write.js';
4
4
 
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.34.1, packages/core/src/mail/store.js.
1
+ // Source: @domma-mail/core 0.36.0, packages/core/src/mail/store.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * The synchronised message store.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.34.1, packages/core/src/mail/subscriptions.js.
1
+ // Source: @domma-mail/core 0.36.0, packages/core/src/mail/subscriptions.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  export function resolveSubscriptions(boxes) {
4
4
  const list = boxes ?? [];
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.34.1, packages/core/src/mail/syncPlan.js.
1
+ // Source: @domma-mail/core 0.36.0, packages/core/src/mail/syncPlan.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Deciding what a folder sync needs to do.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.34.1, packages/core/src/mail/syncRuntime.js.
1
+ // Source: @domma-mail/core 0.36.0, packages/core/src/mail/syncRuntime.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  import {missingUids, planFolderSync} from './syncPlan.js';
4
4
  import {resolveSyncFolders} from './syncSelection.js';
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.34.1, packages/core/src/mail/syncSelection.js.
1
+ // Source: @domma-mail/core 0.36.0, packages/core/src/mail/syncSelection.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Which folders a mailbox keeps mirrored.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.34.1, packages/core/src/mail/unreadBadge.js.
1
+ // Source: @domma-mail/core 0.36.0, packages/core/src/mail/unreadBadge.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * The free reader's sidebar badge - unread mail in each mailbox's INBOX.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.34.1, packages/core/src/mail/unsubscribe.js.
1
+ // Source: @domma-mail/core 0.36.0, packages/core/src/mail/unsubscribe.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Getting off a mailing list.
@@ -1,4 +1,16 @@
1
- /** CMS transport adapter for the shared away responder. */
1
+ /**
2
+ * CMS transport adapter for the shared away responder. Away replies go out in the mailbox's
3
+ * Email Pro branding when Email Pro is on (its registry's `brandAway`), else plain.
4
+ */
2
5
  import {sendMessage} from './send.js';
3
6
  import {createVacationRunner} from './vacationRuntime.js';
4
- export const runVacation = createVacationRunner({sendMessage});
7
+
8
+ const EMAIL_PRO = Symbol.for('domma.email-pro');
9
+
10
+ export const runVacation = createVacationRunner({
11
+ sendMessage,
12
+ brand: async ({account, draft}) => {
13
+ const brandAway = globalThis[EMAIL_PRO]?.brandAway;
14
+ return typeof brandAway === 'function' ? brandAway({account, draft}) : draft;
15
+ }
16
+ });
@@ -1,12 +1,29 @@
1
- // Source: @domma-mail/core 0.34.1, packages/core/src/mail/vacationRuntime.js.
1
+ // Source: @domma-mail/core 0.36.0, packages/core/src/mail/vacationRuntime.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  import {randomUUID} from 'node:crypto';
4
4
  import {autoReplyHeaders, isActive, normaliseVacation, replySubject, shouldAutoReply, replyHistory} from '../admin/mail/vacation.js';
5
5
  import {textToHtml} from '../admin/mail/identity.js';
6
6
  import {ENVELOPE_QUERY, toRecord} from './envelope.js';
7
7
 
8
- /** Public CMS responder, with explicit transport and durable sender claims. */
9
- export function createVacationRunner({sendMessage, isKnownSender = async () => false}) {
8
+ /**
9
+ * Public CMS responder, with explicit transport and durable sender claims.
10
+ * `brand({account, draft})` may return the reply's draft in the mailbox's branding (CMS Email Pro);
11
+ * it can only change `html` and `body`, and a brand that fails or returns nothing sends the reply plain.
12
+ */
13
+ export function createVacationRunner({sendMessage, isKnownSender = async () => false, brand = null}) {
14
+ async function present(account, draft) {
15
+ if (typeof brand !== 'function') return draft;
16
+ try {
17
+ const out = await brand({account, draft: {...draft}});
18
+ if (!out || typeof out !== 'object') return draft;
19
+ const html = typeof out.html === 'string' ? out.html : draft.html;
20
+ const body = typeof out.body === 'string' ? out.body : draft.body;
21
+ return {...draft, html, body};
22
+ } catch {
23
+ return draft;
24
+ }
25
+ }
26
+
10
27
  return async function runVacation({pool, store, account, poolKey, connection, smtp, messages, config = {}, addresses,
11
28
  now = new Date(), budget = {remaining: 10}, folder, uidValidity, isStopping = () => false}) {
12
29
  const report = {considered: 0, replied: 0, attempted: 0, skipped: [], errors: []};
@@ -48,11 +65,12 @@ export function createVacationRunner({sendMessage, isKnownSender = async () => f
48
65
  budget.remaining--; report.attempted++;
49
66
  try {
50
67
  const incomingId = typeof message.messageId === 'string' && !/[\r\n]/.test(message.messageId) ? message.messageId.slice(0, 1000) : null;
51
- await sendMessage({smtp, account, store: null, draft: {
68
+ const draft = await present(account, {
52
69
  to: [{address: sender}], subject: replySubject(vacation, String(message.subject ?? '').slice(0, 500)),
53
70
  body: vacation.bodyText, html: vacation.bodyHtml || textToHtml(vacation.bodyText),
54
71
  messageId: `<${randomUUID()}@${String(smtp.from).split('@')[1]?.replace(/[^a-zA-Z0-9.-]/g, '') || 'localhost'}>`, inReplyTo: incomingId, references: incomingId ? [incomingId] : []
55
- }, pool, poolKey, connection, allowInsecureTLS: config.allowInsecureTLS === true, headers: autoReplyHeaders(), fileCopy: false});
72
+ });
73
+ await sendMessage({smtp, account, store: null, draft, pool, poolKey, connection, allowInsecureTLS: config.allowInsecureTLS === true, headers: autoReplyHeaders(), fileCopy: false});
56
74
  } catch (error) {
57
75
  await store.finishAutoReply(claim, {status: error.deliveryUnknown === true || error.retryable !== true ? 'unknown' : 'failed',
58
76
  error: 'The automatic reply could not be confirmed. Check with the sender before sending another copy.'});
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.34.1, packages/core/src/mail/write.js.
1
+ // Source: @domma-mail/core 0.36.0, packages/core/src/mail/write.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Changing mail, rather than reading it.
@@ -1,3 +1,5 @@
1
+ import {brandEmail} from '../../../server/services/emailBrand.js';
2
+ import {getConfig} from '../../../server/config.js';
1
3
  /**
2
4
  * Outreach email rendering and batch sending. Lifted from Surveys 1.4
3
5
  * (lib/sending.js), generalised: the per-recipient link and the button label
@@ -86,7 +88,7 @@ export function renderInvite(template, contact, link, opts = {}) {
86
88
  + (footerHtml || '')
87
89
  + `</div>`;
88
90
 
89
- return {subject, text, html};
91
+ return brandEmail({subject, text, html}, {site: opts.site || getConfig('site'), family: opts.family || 'campaign', preserveLayout: true});
90
92
  }
91
93
 
92
94
  /**
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.34.1, packages/core/src/public/rich-text.mjs.
1
+ // Source: @domma-mail/core 0.36.0, packages/core/src/public/rich-text.mjs.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Rich text in a Description field - the pure part, shared by the server, the
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.34.1, packages/core/src/rich-text.js.
1
+ // Source: @domma-mail/core 0.36.0, packages/core/src/rich-text.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Rich text Description fields - cleaning what is saved and what is shown.
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [Unreleased]
4
+
5
+ - Automated emails use the site's shared email identity, with existing message content, links, attachments and preferences preserved. Requires the coordinated CMS email-branding release.
6
+
7
+
3
8
  ## [2.15.0] - 2026-11-10
4
9
  - **Own documents only** - a new permission, **Docs: own documents only** (`docs-restricted`), for roles that should write their own documents and nothing more: their own and shared documents only, whatever the site's "Who sees documents" setting says; no list of people and no sharing with anyone new; no public links; no emailing; nothing through other tools. Only Docs administrators see them in the list of people or can share with them. Enforced by the server on every route, and the screens hide what they cannot use. Nobody holds it unless a role is given it, so nothing changes on a site that does not use it. The Job Board gives it to companies and agents.
5
10
  - For add-ons: `services.restrictedUser(user)`, and documents and settings answer `restrictedUser: true` for such a person.
@@ -901,7 +901,7 @@ export default async function docsPlugin(fastify, options) {
901
901
  + (message ? `<blockquote style="border-left:3px solid #ccc;margin:0;padding:.25em 1em">${escapeHtml(message).replace(/\n/g, '<br>')}</blockquote>` : '')
902
902
  + (base ? `<p><a href="${escapeHtml(link)}">Open it in Docs</a></p>` : `<p>Open it in Docs on the site, at <code>${escapeHtml(where)}</code>.</p>`);
903
903
  try {
904
- await mailer.sendEmail(transport, {from: smtp.fromAddress, fromName: smtp.fromName, to: u.email,
904
+ await mailer.sendEmail(transport, {branding: {family: 'docs'}, from: smtp.fromAddress, fromName: smtp.fromName, to: u.email,
905
905
  subject: `${who} shared "${doc.title}" with you`, html,
906
906
  text: `${who} shared a document with you: ${doc.title}\n${message ? `\n${message}\n` : ''}\n${link}`});
907
907
  n++;
@@ -999,7 +999,7 @@ export default async function docsPlugin(fastify, options) {
999
999
  const failed = [];
1000
1000
  for (const address of to) {
1001
1001
  try {
1002
- await mailer.sendEmail(transport, {from: smtp.fromAddress, fromName: smtp.fromName, to: address,
1002
+ await mailer.sendEmail(transport, {branding: {family: 'docs'}, from: smtp.fromAddress, fromName: smtp.fromName, to: address,
1003
1003
  subject: mode === 'link' ? `${who} sent you "${doc.title}"` : doc.title, html, text, ...(attachments ? {attachments} : {})});
1004
1004
  } catch (err) {
1005
1005
  req.log.warn({err}, '[docs] send failed');
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "note": "Written by `make sync-free-tier` in dcms-marketplace. Do not edit these plugins here - edit them there and sync.",
3
- "source": "dcms-marketplace@6cd8828c",
3
+ "source": "dcms-marketplace@5d5eabe5",
4
4
  "plugins": {
5
5
  "blog": {
6
6
  "version": "1.11.0",
@@ -83,7 +83,7 @@
83
83
  "docs": {
84
84
  "version": "2.15.0",
85
85
  "files": {
86
- "CHANGELOG.md": "2bf73d5627e5a1d4ab692f15c2fa128d55d7707062a7f9597d0c9737fc42accb",
86
+ "CHANGELOG.md": "daec1dd2fca964a9f86f1d478c15148a7870188bc041c10abd41110a9f3e6c0b",
87
87
  "CLAUDE.md": "29e27e36bdf2acb65481f2e2a77bf28ced83fd403cf9352355a752faa8b41f67",
88
88
  "admin/css/docs.css": "89304c596f2d36492198885359fa86998f9f36be522238983e32e5d01319c759",
89
89
  "admin/lib/api.js": "0ddd567995a79e2379b92049de3b09a8bdf1c0d798042c7fbe3937f14e3631bf",
@@ -111,7 +111,7 @@
111
111
  "lib/pdf-worker.js": "c256c32520a37a6579a528f16d5965951cfb65d7984a246168c1b33fd36d72eb",
112
112
  "lib/pdf.js": "83abc3aba0c322c50b528b8a037466a294303f55d7c30f3cd1445f811b78ae28",
113
113
  "lib/store.js": "128c372b9b2daa1370205e5261c76e90d3966717d371aeb33b9a5cccb16fa04f",
114
- "plugin.js": "487191d13142bd70d12e2f9a339ba83c75bb3f1b8ad87eb6cb2688c47b4932dc",
114
+ "plugin.js": "d2383f22f97cc52e0cfae7a39096965303d372571610d3cc57cd55f7b267977c",
115
115
  "plugin.json": "c97fc5e37494aa0ca4e4a0a89b204bb01cbdcd5c4fe36e0e68d185e56d9ba713",
116
116
  "plugin.public.js": "a9cd7a9211f5b0006832054a15055a3c36afa9f9b284600cdc5fce19e892c178",
117
117
  "templates/public-doc.html": "7360cbeec5cba8a2b1b1d074730972bb4b90cfe913a799a06522b2e1a0f566d8",
@@ -243,7 +243,7 @@
243
243
  "shopping-cart": {
244
244
  "version": "1.8.0",
245
245
  "files": {
246
- "CHANGELOG.md": "ff7a4dd729a654cac1fc2f5505a44cb4556a29b4051b3668536f9d4fb45bdc50",
246
+ "CHANGELOG.md": "d23355840d01d07c40caf499d3c53d7bce1a3f87b538ff10d6dc88f97eb77e68",
247
247
  "CLAUDE.md": "a80eb3fb8bacb7a98e754491de2adba3b8552bdcc9dec6ecc97714f86a4788a1",
248
248
  "admin/css/index.css": "b3e9e0c351d88a9aab2947f12c7530c70a4254017f5c87032fe66652853eb2db",
249
249
  "admin/lib/chart.js": "b01ce5cfac773c8df8efccab50b67d3dfa99fbead0037d817553db4a6688d4d6",
@@ -262,7 +262,7 @@
262
262
  "config.js": "31b336560d21a802d799ed487d5c3116de898446ba3521068b10d192f4ebbb2d",
263
263
  "docs/guide.md": "664da6180b7e2d8ed804f1a2bb3ef1bb8fdc19e61cb3abff126201d7c13cf112",
264
264
  "inject/body.html": "fe3810d85d355b402ccc368eddc0a8641b7edf1a5d9e20b9830d05268eecae67",
265
- "lib/accounts.js": "5115cec6a145da18c106dfdbf5fd0b2a1bad0c68e8fac4ef623287e85db75e5c",
265
+ "lib/accounts.js": "0940fcfd169e2c3993c8f8df3dd0786d4f57777747892ef0cee0a26c91e65169",
266
266
  "lib/commission.js": "5b10475d98cff2aaf4c76b9950f8d698d6262e36754a8963669690a8e3e9bd52",
267
267
  "lib/description.js": "3f7a771ee14bd94764e68a918cf26a84bf03b1fa3b56b0b3dfe5a18eee09496e",
268
268
  "lib/extensions.js": "73d3515b52c066e3e616c425d91a7a48a6aab153e7d14ae7278b38ee32649352",
@@ -314,7 +314,7 @@
314
314
  "support": {
315
315
  "version": "1.3.0",
316
316
  "files": {
317
- "CHANGELOG.md": "da64649fcc59d9f42f5987395f3ca2ae98bcfa749d4121537233aeb6f3b00e3a",
317
+ "CHANGELOG.md": "2d740413e329c7201bafdb84c02e699e67f29b6388644d26ee37d5de66ba7aee",
318
318
  "CLAUDE.md": "fe805bbe9048c0dce37e178bef34c34149ab2c2acc03766024f0daaf9f09058a",
319
319
  "admin/css/index.css": "2e8e5a66a30aee7da4f36f8d80564e1fdadc19558c67359ae1a01a4ee56959a9",
320
320
  "admin/lib/ai.js": "9a82ee5922bc54b20b5d108ccc9bde8791f9dac843e49d855ff6b254f3675645",
@@ -333,7 +333,7 @@
333
333
  "lib/assist.js": "5aea85ece5490328bca7e8de28f141b5350530b790e98d02e1e414840462292e",
334
334
  "lib/attachments.js": "e3479c7fe9f01e6287126279bc9d514fd14f00b64af9082ac49596bc6a543c23",
335
335
  "lib/cache.js": "70cc826b24cc5359597a5c83a990f6da43cadebf2ac34094aee42058240fb72d",
336
- "lib/mail.js": "d14aae3a59aad6af61451863cdaaf94fc4a87810b16e1dcb9c655dda6c803b3b",
336
+ "lib/mail.js": "76f879c884751dfda9a7bde0090955d6532bf247f373cfb31b04f5984d7443aa",
337
337
  "lib/receiver.js": "7ed1ae47fab820655aa4c4ddf926b089601ea03a0bb4a5346d4b3f6736b66009",
338
338
  "lib/sender.js": "2b308422ac60a8a2801570e06319d5972797a601640c67beee95ccab9ac64092",
339
339
  "lib/shape.js": "d60b48410aa5582ea80451c3d831686b0e29525a958733a8bc9dfaae8eca94d2",
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [Unreleased]
4
+
5
+ - Automated emails use the site's shared email identity, with existing message content, links, attachments and preferences preserved. Requires the coordinated CMS email-branding release.
6
+
7
+
3
8
  ## [1.8.0] - 2026-11-15
4
9
  - A product's **Description** is a rich text editor: paragraphs, bold, italics, underline, lists and links. What it
5
10
  saves is rich text, cleaned on save and again on the product page.
@@ -49,7 +49,7 @@ async function mail({to, subject, lines, link, button}) {
49
49
  if (mailer) { await mailer(msg); return true; }
50
50
  const s = site();
51
51
  if (!isSmtpConfigured(s.smtp || {})) return false;
52
- await sendEmail(await createTransport(s.smtp), {from: s.smtp.fromAddress || s.contactEmail || 'noreply@example.com', fromName: s.smtp.fromName || s.title || 'Shop', ...msg});
52
+ await sendEmail(await createTransport(s.smtp), {branding: {family: 'account'}, from: s.smtp.fromAddress || s.contactEmail || 'noreply@example.com', fromName: s.smtp.fromName || s.title || 'Shop', ...msg});
53
53
  return true;
54
54
  }
55
55
 
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [Unreleased]
4
+
5
+ - Automated emails use the site's shared email identity, with existing message content, links, attachments and preferences preserved. Requires the coordinated CMS email-branding release.
6
+
7
+
3
8
  ## [1.3.0] - 2026-11-16
4
9
 
5
10
  - On the Domma server's inbox, with AI Assist: **Summarise** above a request's conversation (kept with the request), **Suggest a reply** that fills the reply box for you to edit and send yourself, and **Summarise** on the Waiting on Domma tab, grouping those requests into themes. Only the conversation's words are sent, never site names, people's names, email addresses, phone numbers or files. Sites see no change.
@@ -43,10 +43,10 @@ export async function send(msg, {log} = {}) {
43
43
  if (!isSmtpConfigured(smtp)) return false;
44
44
  const key = JSON.stringify([smtp.host, smtp.port, smtp.user, smtp.secure]);
45
45
  if (!transport || transportFor !== key) { transport = await createTransport(smtp); transportFor = key; }
46
- await sendEmail(transport, {
46
+ await sendEmail(transport, {branding: {family: 'support'},
47
47
  // `msg.from`: the support mailbox, for mail TO a customer (a reply then reaches it).
48
48
  from: msg.from || smtp.fromAddress || 'noreply@example.com',
49
- fromName: 'Domma Support',
49
+ fromName: smtp.fromName || s.brand?.text || s.title || 'Support',
50
50
  to: msg.to, subject: msg.subject, html: msg.html, text: msg.text,
51
51
  ...(msg.replyTo && {replyTo: msg.replyTo})
52
52
  });
@@ -1,3 +1,5 @@
1
+ import {normaliseEmailBrand} from '../../services/emailBrand.js';
2
+ import {EMAIL_EXAMPLES, emailExample} from '../../services/emailExamples.js';
1
3
  /**
2
4
  * Settings API
3
5
  * GET /api/settings - get site settings
@@ -11,7 +13,7 @@ import {faviconSource, generateFavicon} from '../../services/favicon.js';
11
13
  import {saveMedia} from '../../services/content.js';
12
14
  import {randomUUID} from 'node:crypto';
13
15
  import {authenticate, requirePermission} from '../../middleware/auth.js';
14
- import {createTransport, mailFailure, TEST_EMAIL_FAILED} from '../../services/email.js';
16
+ import {createTransport, fromHeader, mailFailure, TEST_EMAIL_FAILED} from '../../services/email.js';
15
17
  import {signedOnly} from '../../services/codePolicy.js';
16
18
  import {resolveMailHost} from '../../services/mailHost.js';
17
19
  import fs from 'fs/promises';
@@ -134,7 +136,7 @@ export async function settingsRoutes(fastify) {
134
136
  const ALLOWED_KEYS = new Set([
135
137
  'title', 'tagline', 'description', 'logo', 'favicon',
136
138
  'theme', 'adminTheme', 'fontFamily', 'fontSize',
137
- 'smtp', 'footer', 'analytics', 'social', 'locale',
139
+ 'smtp', 'emailBrand', 'footer', 'analytics', 'social', 'locale',
138
140
  'layoutOptions', 'seo', 'backToTop', 'goToBottom', 'cookieConsent', 'breadcrumbs', 'autoTheme',
139
141
  'adminBrand',
140
142
  // The screen `#/` (Dashboard) opens - see services/adminHome.js.
@@ -257,6 +259,10 @@ export async function settingsRoutes(fastify) {
257
259
  merged.motion = normaliseMotionSettings(next, merged.footer);
258
260
  }
259
261
  }
262
+ if ('emailBrand' in data) {
263
+ try { merged.emailBrand = normaliseEmailBrand(merged.emailBrand); }
264
+ catch (err) { return reply.code(400).send({error: err.message}); }
265
+ }
260
266
  // Never erase smtp.pass with the empty string that the GET endpoint injects for safety
261
267
  if (merged.smtp && merged.smtp.pass === '' && existing.smtp?.pass) {
262
268
  merged.smtp = {...merged.smtp, pass: existing.smtp.pass};
@@ -282,8 +288,24 @@ export async function settingsRoutes(fastify) {
282
288
  return { success: true };
283
289
  });
284
290
 
291
+ fastify.get('/settings/email-examples', canRead, async () => ({examples: EMAIL_EXAMPLES.map(({id, label}) => ({id, label}))}));
292
+
293
+ fastify.post('/settings/email-preview', canRead, async (request, reply) => {
294
+ const site = getConfig('site');
295
+ if (request.body?.emailBrand !== undefined) {
296
+ try { site.emailBrand = normaliseEmailBrand(request.body.emailBrand); }
297
+ catch (err) { return reply.code(400).send({error: err.message}); }
298
+ }
299
+ const example = emailExample(request.body?.example || 'account', site);
300
+ if (!example) return reply.code(400).send({error: 'Choose an email example.'});
301
+ return example;
302
+ });
303
+
285
304
  fastify.post('/settings/test-email', canRead, async (request, reply) => {
286
- const smtp = getConfig('site')?.smtp;
305
+ const site = getConfig('site');
306
+ const smtp = site.smtp;
307
+ const example = request.body?.example ? emailExample(request.body.example, site) : null;
308
+ if (request.body?.example && !example) return reply.code(400).send({error: 'Choose an email example.'});
287
309
  if (!smtp?.host) {
288
310
  return reply.status(400).send({ error: 'SMTP is not configured. Save your SMTP settings first.' });
289
311
  }
@@ -300,11 +322,10 @@ export async function settingsRoutes(fastify) {
300
322
  // Do NOT build a raw nodemailer transport here; that regresses on engine sync.
301
323
  const transporter = await createTransport(smtp);
302
324
  await transporter.sendMail({
303
- from: smtp.fromName ? `"${smtp.fromName}" <${smtp.fromAddress}>` : smtp.fromAddress,
325
+ from: fromHeader(smtp.fromName, smtp.fromAddress),
304
326
  to,
305
- subject: 'Domma CMS - Test Email',
306
- text: 'This is a test email sent from Domma CMS to verify your SMTP configuration.',
307
- html: '<p>This is a test email sent from <strong>Domma CMS</strong> to verify your SMTP configuration.</p>'
327
+ ...(example || emailExample('test', site)),
328
+ subject: `[TEST] ${example?.subject || 'Email branding and SMTP check'}`
308
329
  });
309
330
  return { success: true, message: `Test email sent to ${to}` };
310
331
  } catch (err) {
@@ -1,3 +1,4 @@
1
+ import {brandEmail, escapeHtml} from './email.js';
1
2
  /**
2
3
  * Actions Service (Pro - requires MongoDB)
3
4
  *
@@ -241,7 +242,7 @@ async function executeStep(step, collection, entry, context) {
241
242
  to,
242
243
  subject,
243
244
  text: body,
244
- html: `<p>${body.replace(/\n/g, '<br>')}</p>`
245
+ ...brandEmail({subject, text: body, html: `<p>${escapeHtml(body).replace(/\n/g, '<br>')}</p>`}, {site: settings, family: 'automation'})
245
246
  });
246
247
 
247
248
  return { to };
@@ -162,7 +162,7 @@ export async function sendInviteEmail({to, name, hostName, title, link}, {log} =
162
162
  if (!isSmtpConfigured(smtp)) return false;
163
163
  const k = JSON.stringify([smtp.host, smtp.port, smtp.user, smtp.secure]);
164
164
  if (!transport || transportFor !== k) { transport = await createTransport(smtp); transportFor = k; }
165
- await sendEmail(transport, {from: smtp.fromAddress || 'noreply@example.com', fromName: smtp.fromName || s.title || 'Calls', ...msg});
165
+ await sendEmail(transport, {branding: {family: 'calendar'}, from: smtp.fromAddress || 'noreply@example.com', fromName: smtp.fromName || s.title || 'Calls', ...msg});
166
166
  return true;
167
167
  } catch (err) {
168
168
  try { (log?.error || console.error).call(log || console, `[calls] Invitation to ${to} not sent: ${err?.message || err}`); } catch { /* never */ }
@@ -1,3 +1,6 @@
1
+ import {getConfig} from '../config.js';
2
+ import {brandEmail} from './emailBrand.js';
3
+ export {brandEmail} from './emailBrand.js';
1
4
  /**
2
5
  * Core Email Utility
3
6
  * Nodemailer transport factory and generic form email sending utility.
@@ -250,6 +253,8 @@ export function fromHeader(name, address) {
250
253
  /**
251
254
  * Send a generic transactional email.
252
255
  *
256
+ * `branding` explicitly opts an automated sender into the shared site presentation.
257
+ * With no branding option, user-composed mail passes through unchanged.
253
258
  * `replyTo`, `headers` and `attachments` are passed to nodemailer only when
254
259
  * given - an inline image is an attachment with a `cid` the html refers to
255
260
  * as `<img src="cid:...">`.
@@ -259,14 +264,15 @@ export function fromHeader(name, address) {
259
264
  * @returns {Promise<void>}
260
265
  * @throws {Error} If sending the email fails.
261
266
  */
262
- export async function sendEmail(transport, {from, fromName, to, subject, html, text, replyTo, headers, attachments}) {
267
+ export async function sendEmail(transport, {from, fromName, to, subject, html, text, replyTo, headers, attachments, branding}) {
263
268
  try {
269
+ const presentation = branding ? brandEmail({subject, html, text}, {site: getConfig('site'), ...branding}) : {html, text};
264
270
  const message = {
265
271
  from: fromHeader(fromName, from),
266
272
  to,
267
273
  subject,
268
- text,
269
- html
274
+ text: presentation.text,
275
+ html: presentation.html
270
276
  };
271
277
  if (replyTo) message.replyTo = replyTo;
272
278
  if (headers && Object.keys(headers).length) message.headers = headers;
@@ -354,7 +360,7 @@ export async function sendFormEmail(transport, { from, fromName, to, subject, fo
354
360
  to,
355
361
  subject,
356
362
  text,
357
- html
363
+ ...brandEmail({subject, html, text}, {site: getConfig('site'), family: 'forms'})
358
364
  });
359
365
  recordSendResult(true, info.messageId);
360
366
 
@@ -0,0 +1,126 @@
1
+ /** Shared, opt-in presentation for automated site emails. No SMTP or runtime writes. */
2
+ const esc = value => String(value ?? '').replace(/[&<>"']/g, c => ({'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;'}[c]));
3
+ const clean = (value, max = 300) => typeof value === 'string' ? value.replace(/[\u0000-\u001f\u007f]/g, ' ').trim().slice(0, max) : '';
4
+ const hex = value => /^#[\da-f]{6}$/i.test(value || '');
5
+
6
+ export const EMAIL_FAMILIES = {
7
+ account: 'Your account', waypoint: 'Waypoint', booking: 'Bookings', calendar: 'Calendar',
8
+ shop: 'Your order', invoice: 'Invoices and quotes', support: 'Support', docs: 'Documents', signing: 'Document signing',
9
+ forms: 'Form submission', automation: 'Site notification', report: 'Your report', security: 'Account security',
10
+ campaign: 'News and updates', survey: 'Your invitation', onboard: 'Getting started', ecard: 'A card for you',
11
+ prize: 'Your reward', recovery: 'Account recovery', jobs: 'Job board', wiki: 'Wiki updates', test: 'Email preview',
12
+ gift: 'A gift for you', offer: 'An offer for you', licence: 'Your licence'
13
+ };
14
+
15
+ /** Site identity, with explicit email overrides. Never use the admin identity on customer mail. */
16
+ export function emailBrand(site = {}) {
17
+ const override = site.emailBrand || {};
18
+ const base = emailUrl(site.baseUrl) || emailUrl(site.url);
19
+ const colour = /^#[\da-f]{3}$/i.test(override.accent || '') ? '#' + override.accent.slice(1).split('').map(c => c + c).join('') : override.accent;
20
+ const accent = hex(colour) ? colour : '#2563eb';
21
+ const support = clean(override.supportEmail || site.contactEmail);
22
+ return {
23
+ name: clean(override.name || site.brand?.text || site.title || site.smtp?.fromName || 'Our team', 120),
24
+ logo: /\.svg(?:[?#]|$)/i.test(override.logo || site.brand?.logo || site.logo || '') ? '' : emailUrl(override.logo || site.brand?.logo || site.logo, base),
25
+ accent, ink: accentInk(accent), link: accentInk(accent) === '#000000' ? '#0f172a' : accent, base,
26
+ supportEmail: /^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(support) ? support : '',
27
+ footer: clean(override.footer, 600)
28
+ };
29
+ }
30
+
31
+ export function accentInk(accent) {
32
+ const rgb = accent.slice(1).match(/../g).map(x => parseInt(x, 16) / 255).map(x => x <= .04045 ? x / 12.92 : ((x + .055) / 1.055) ** 2.4);
33
+ const luminance = .2126 * rgb[0] + .7152 * rgb[1] + .0722 * rgb[2];
34
+ return (luminance + .05) / .05 > 1.05 / (luminance + .05) ? '#000000' : '#ffffff';
35
+ }
36
+
37
+ /** Structured content is escaped here; html fragments are trusted template output only. */
38
+ export function emailBlocks(blocks = [], brand = emailBrand()) {
39
+ const pieces = blocks.map(block => {
40
+ if (block.type === 'details') {
41
+ const rows = (block.rows || []).filter(([, value]) => value !== '' && value != null);
42
+ return {html: `${block.title ? `<p style="margin:20px 0 8px;"><strong>${esc(block.title)}</strong></p>` : ''}<table role="presentation" class="dm-email-panel" bgcolor="#f8fafc" width="100%" cellpadding="0" cellspacing="0" style="background:#f8fafc;margin:20px 0;border:1px solid #e2e8f0;border-radius:8px;">${rows.map(([label, value]) => `<tr><td style="padding:10px 14px;vertical-align:top;color:#64748b;border-bottom:1px solid #e2e8f0;width:35%;">${esc(label)}</td><td style="padding:10px 14px;vertical-align:top;border-bottom:1px solid #e2e8f0;font-weight:600;">${esc(value).replace(/\n/g, '<br>')}</td></tr>`).join('')}</table>`, text: (block.title ? `${block.title}:\n` : '') + rows.map(([label, value]) => `${label}: ${String(value).replace(/\n/g, '\n ')}`).join('\n')};
43
+ }
44
+ if (block.type === 'link') {
45
+ const href = emailUrl(block.url, brand.base);
46
+ return href ? {html: `<p style="font-size:12px;margin:18px 0;"><a href="${esc(href)}" class="dm-email-link" style="color:${brand.link};">${esc(block.label)}</a></p>`, text: `${block.label}: ${href}`} : {html: '', text: ''};
47
+ }
48
+ if (block.type === 'action') {
49
+ const href = emailUrl(block.url, brand.base);
50
+ return href ? {html: `<table role="presentation" cellpadding="0" cellspacing="0" style="margin:26px 0;"><tr><td bgcolor="${brand.accent}" style="border-radius:6px;background:${brand.accent};"><a href="${esc(href)}" style="display:inline-block;padding:14px 24px;font-weight:700;color:${brand.ink};text-decoration:none;">${esc(block.label || 'Open')}</a></td></tr></table><p style="font-size:12px;color:#64748b;word-break:break-all;">Or open this link:<br><a href="${esc(href)}" class="dm-email-link" style="color:${brand.link};">${esc(href)}</a></p>`, text: `${block.label || 'Open'}: ${href}`} : {html: '', text: ''};
51
+ }
52
+ if (block.type === 'quote') return {html: `<blockquote class="dm-email-panel" style="margin:20px 0;padding:16px 20px;border-left:4px solid ${brand.accent};background:#f8fafc;">${esc(block.text).replace(/\n/g, '<br>')}</blockquote>`, text: block.text || ''};
53
+ if (block.type === 'items') return {html: `<ul style="padding-left:20px;">${(block.items || []).map(item => `<li style="margin:12px 0;">${esc(item)}</li>`).join('')}</ul>`, text: (block.items || []).map(item => `- ${item}`).join('\n')};
54
+ if (block.type === 'status') return {html: `<p style="margin:16px 0;padding:12px 16px;border:1px solid #cbd5e1;border-radius:6px;font-weight:700;">${esc(block.text)}</p>`, text: block.text || ''};
55
+ return {html: `<p style="margin:0 0 18px;">${esc(block.text).replace(/\n/g, '<br>')}</p>`, text: block.text || ''};
56
+ });
57
+ return {html: pieces.map(p => p.html).join('\n'), text: pieces.map(p => p.text).filter(Boolean).join('\n\n')};
58
+ }
59
+
60
+ /** Adapt existing trusted templates without nesting full HTML documents or losing attachment metadata. */
61
+ function fragment(html, brand, preserveLayout) {
62
+ let output = String(html || '');
63
+ const styles = preserveLayout ? (output.match(/<head\b[^>]*>([\s\S]*?)<\/head\s*>/i)?.[1].match(/<style\b[^>]*>[\s\S]*?<\/style\s*>/gi) || []).join('') : '';
64
+ output = output.replace(/<head\b[^>]*>[\s\S]*?<\/head\s*>/gi, '');
65
+ output = output.replace(/<!doctype[^>]*>|<\/?(?:html|body)\b[^>]*>/gi, '');
66
+ if (!preserveLayout) {
67
+ output = output.replace(/<style\b[^>]*>[\s\S]*?<\/style\s*>/gi, '');
68
+ output = output.replace(/style="([^"]*)"/gi, (all, style) => {
69
+ if (!/background(?:-color)?:\s*#(?:2563eb|5b8cff|1f5bb8)\b/i.test(style)) return all;
70
+ const next = style.replace(/background(?:-color)?:[^;]+;?/gi, '').replace(/(?:^|;)\s*color:[^;]+;?/gi, ';');
71
+ return `style="${next};background-color:${brand.accent};color:${brand.ink};"`;
72
+ });
73
+ }
74
+ return styles + output;
75
+ }
76
+
77
+ /** Explicit opt-in: SMTP stays a transport, and manually composed mail is never decorated. */
78
+ export function brandEmail(message, {site = {}, family = 'automation', title, preview, blocks, preserveLayout = false} = {}) {
79
+ if (String(message.html || '').includes('data-domma-email="1"')) return {...message};
80
+ const brand = emailBrand(site);
81
+ const heading = clean(title || message.subject || 'A message for you', 240);
82
+ const label = EMAIL_FAMILIES[family] || EMAIL_FAMILIES.automation;
83
+ const content = blocks ? emailBlocks(blocks, brand) : message.html ? {html: fragment(message.html, brand, preserveLayout), text: message.text || ''} : emailBlocks([{text: message.text || ''}], brand);
84
+ if (family === 'account' && !preserveLayout) content.html = content.html.replace(/<h2\b[^>]*>[\s\S]*?<\/h2>/i, '');
85
+ const preheader = clean(preview || content.text || heading, 180);
86
+ const contact = brand.supportEmail ? `<a href="mailto:${esc(brand.supportEmail)}" style="color:#64748b;">${esc(brand.supportEmail)}</a>` : '';
87
+ const website = brand.base ? `<a href="${esc(brand.base)}" style="color:#64748b;">Visit ${esc(brand.name)}</a>` : '';
88
+ const logo = brand.logo ? `<img src="${esc(brand.logo)}" alt="${esc(brand.name)}" width="160" style="display:block;max-width:160px;max-height:64px;width:auto;height:auto;border:0;margin-bottom:14px;">` : '';
89
+ const html = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="color-scheme" content="light dark"><title>${esc(heading)}</title><style>@media(max-width:600px){.dm-email-pad{padding:24px 20px!important}.dm-email-shell{border-radius:0!important}}@media(prefers-color-scheme:dark){.dm-email-page{background:#111827!important}.dm-email-shell,.dm-email-content{background:#1f2937!important;color:#f1f5f9!important}.dm-email-title,.dm-email-brand div{color:#fff!important}.dm-email-panel{background:#334155!important;color:#f1f5f9!important}.dm-email-panel td{color:inherit!important}.dm-email-preserve{background:#fff!important;color:#334155!important}.dm-email-preserve .dm-email-title{color:#0f172a!important}.dm-email-link{color:#93c5fd!important}.dm-email-footer a{color:#cbd5e1!important}.dm-email-footer{background:#172033!important;color:#cbd5e1!important}}</style></head>
90
+ <body class="dm-email-page" style="margin:0;padding:0;background:#edf1f6;"><div style="display:none;max-height:0;overflow:hidden;mso-hide:all;">${esc(preheader)}</div>
91
+ <table data-domma-email="1" role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" class="dm-email-page" style="background:#edf1f6;font:15px/1.65 Arial,Helvetica,sans-serif;color:#334155;"><tr><td align="center" style="padding:36px 12px;">
92
+ <table role="presentation" width="600" cellpadding="0" cellspacing="0" border="0" class="dm-email-shell" style="width:100%;max-width:600px;background:#fff;border:1px solid #dce3ed;border-radius:12px;overflow:hidden;">
93
+ <tr><td bgcolor="${brand.accent}" style="height:6px;font-size:0;line-height:6px;background:${brand.accent};">&nbsp;</td></tr>
94
+ <tr><td class="dm-email-pad dm-email-brand" style="padding:28px 36px 20px;">${logo}<div style="font-size:18px;font-weight:700;color:#0f172a;">${esc(brand.name)}</div><div style="margin-top:4px;font-size:11px;font-weight:700;letter-spacing:1.4px;text-transform:uppercase;color:#64748b;">${esc(label)}</div></td></tr>
95
+ <tr><td class="dm-email-pad dm-email-content${blocks ? '' : ' dm-email-preserve'}" style="padding:8px 36px 32px;background:#fff;color:#334155;"><h1 class="dm-email-title" style="font:700 26px/1.25 Arial,Helvetica,sans-serif;color:#0f172a;margin:0 0 24px;">${esc(heading)}</h1><!--dm-email-body-->${content.html}<!--/dm-email-body--></td></tr>
96
+ <tr><td class="dm-email-pad dm-email-footer" style="padding:22px 36px;background:#f8fafc;border-top:1px solid #e2e8f0;font:12px/1.6 Arial,Helvetica,sans-serif;color:#64748b;"><strong>${esc(brand.name)}</strong>${brand.footer ? `<p style="margin:8px 0;">${esc(brand.footer)}</p>` : ''}<p style="margin:8px 0 0;">${[website, contact].filter(Boolean).join(' &nbsp;·&nbsp; ')}</p></td></tr>
97
+ </table></td></tr></table></body></html>`;
98
+ const text = [brand.name, label, heading, content.text, brand.footer, brand.base, brand.supportEmail].filter(Boolean).join('\n\n');
99
+ return {...message, html, text};
100
+ }
101
+
102
+ /** Store only email presentation fields. Blank overrides inherit the site's public identity. */
103
+ export function normaliseEmailBrand(value) {
104
+ if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('Email branding must be an object.');
105
+ const out = {};
106
+ for (const key of ['name', 'logo', 'accent', 'supportEmail', 'footer']) {
107
+ if (value[key] != null && typeof value[key] !== 'string') throw new Error(`Email branding ${key} must be text.`);
108
+ out[key] = clean(value[key], key === 'footer' ? 600 : key === 'logo' ? 2000 : 160);
109
+ }
110
+ if (out.accent && !hex(out.accent)) throw new Error('Email accent must be a six-digit hex colour, such as #2563eb.');
111
+ if (/\.svg(?:[?#]|$)/i.test(out.logo)) throw new Error('Choose a PNG, JPEG, GIF or WebP email logo.');
112
+ if (out.logo && !/^(https?:\/\/|\/[^/])/i.test(out.logo)) throw new Error('Email logo must be an http(s) address or a site-relative path.');
113
+ if (out.logo && /^https?:/i.test(out.logo) && !emailUrl(out.logo)) throw new Error('Email logo address is invalid.');
114
+ if (out.supportEmail && !/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(out.supportEmail)) throw new Error('Email support address is invalid.');
115
+ return out;
116
+ }
117
+
118
+ /** Public web URLs only. A relative asset needs a configured, trusted site origin. */
119
+ export function emailUrl(value, base) {
120
+ if (typeof value !== 'string' || !value.trim() || /[\u0000-\u0020\u007f]/.test(value.trim())) return '';
121
+ if (!/^https?:\/\//i.test(value) && !(base && /^(\/[^/]|#\/)/.test(value))) return '';
122
+ try {
123
+ const url = new URL(value, base || undefined);
124
+ return ['https:', 'http:'].includes(url.protocol) && !url.username && !url.password ? url.href : '';
125
+ } catch { return ''; }
126
+ }