domma-cms 1.29.1 → 1.30.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 (83) hide show
  1. package/CHANGELOG.md +4 -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 +1 -1
  6. package/plugins/_lib/admin/mail/contacts.js +1 -1
  7. package/plugins/_lib/admin/mail/diagnostics-section.js +1 -1
  8. package/plugins/_lib/admin/mail/drag-drop.js +1 -1
  9. package/plugins/_lib/admin/mail/folder-tree.js +22 -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 +68 -1
  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 +1 -1
  22. package/plugins/_lib/admin/mail/reader-runtime.js +91 -5
  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 +6 -2
  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 +1 -1
  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 +1 -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/domma-mail.lock.json +80 -79
  38. package/plugins/_lib/mail/accountFileStore.js +1 -1
  39. package/plugins/_lib/mail/accountRepository.js +36 -2
  40. package/plugins/_lib/mail/accountRoutes.js +1 -1
  41. package/plugins/_lib/mail/accounts.js +1 -1
  42. package/plugins/_lib/mail/bodyTokenProvider.js +1 -1
  43. package/plugins/_lib/mail/bodyTokens.js +1 -1
  44. package/plugins/_lib/mail/compose.js +1 -1
  45. package/plugins/_lib/mail/defaults.js +1 -1
  46. package/plugins/_lib/mail/envelope.js +1 -1
  47. package/plugins/_lib/mail/folderActions.js +1 -1
  48. package/plugins/_lib/mail/folderRuntime.js +1 -1
  49. package/plugins/_lib/mail/folders.js +1 -1
  50. package/plugins/_lib/mail/imapPoolRuntime.js +1 -1
  51. package/plugins/_lib/mail/mbox.js +1 -1
  52. package/plugins/_lib/mail/message-action.js +1 -1
  53. package/plugins/_lib/mail/messageSecurity.js +1 -1
  54. package/plugins/_lib/mail/messageSecurityProvider.js +1 -1
  55. package/plugins/_lib/mail/networkAddresses.js +1 -1
  56. package/plugins/_lib/mail/networkPolicy.js +1 -1
  57. package/plugins/_lib/mail/oauthAccounts.js +1 -1
  58. package/plugins/_lib/mail/oauthRouteRuntime.js +1 -1
  59. package/plugins/_lib/mail/oauthRuntime.js +1 -1
  60. package/plugins/_lib/mail/pollSchedule.js +1 -1
  61. package/plugins/_lib/mail/poller.js +1 -1
  62. package/plugins/_lib/mail/pollerRuntime.js +1 -1
  63. package/plugins/_lib/mail/priority.js +1 -1
  64. package/plugins/_lib/mail/publicMailbox.js +1 -1
  65. package/plugins/_lib/mail/readRuntime.js +57 -3
  66. package/plugins/_lib/mail/render.js +1 -1
  67. package/plugins/_lib/mail/ruleRunner.js +1 -1
  68. package/plugins/_lib/mail/schedulerRuntime.js +1 -1
  69. package/plugins/_lib/mail/secretProvider.js +1 -1
  70. package/plugins/_lib/mail/secretbox.js +1 -1
  71. package/plugins/_lib/mail/senderAuth.js +113 -0
  72. package/plugins/_lib/mail/sieve.js +7 -2
  73. package/plugins/_lib/mail/smtpService.js +1 -1
  74. package/plugins/_lib/mail/snoozeRuntime.js +1 -1
  75. package/plugins/_lib/mail/store.js +1 -1
  76. package/plugins/_lib/mail/subscriptions.js +1 -1
  77. package/plugins/_lib/mail/syncPlan.js +1 -1
  78. package/plugins/_lib/mail/syncRuntime.js +1 -1
  79. package/plugins/_lib/mail/syncSelection.js +1 -1
  80. package/plugins/_lib/mail/unreadBadge.js +1 -1
  81. package/plugins/_lib/mail/unsubscribe.js +1 -1
  82. package/plugins/_lib/mail/vacationRuntime.js +1 -1
  83. package/plugins/_lib/mail/write.js +4 -2
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.18.0, packages/core/src/mail/secretbox.js.
1
+ // Source: @domma-mail/core 0.19.0, packages/core/src/mail/secretbox.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /** CMS compatibility entry point. Standalone hosts create their own secret box. */
4
4
  import path from 'node:path';
@@ -0,0 +1,113 @@
1
+ // Source: @domma-mail/core 0.19.0, packages/core/src/mail/senderAuth.js.
2
+ // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
+ /**
4
+ * Did this message really come from the address in its From line?
5
+ *
6
+ * Used before loading a contact's remote images automatically: anyone can
7
+ * write a contact's address into From, so being in the contacts list is not
8
+ * enough on its own. The answer comes from the RECEIVING mail server's own
9
+ * check, recorded in an Authentication-Results header (RFC 8601).
10
+ *
11
+ * Only a header the receiving server wrote counts. A sender can put any
12
+ * Authentication-Results it likes into its own message, so:
13
+ *
14
+ * - the server that took delivery is the `by` host of the topmost Received
15
+ * header (each hop adds its Received line at the top);
16
+ * - a result counts only when its authserv-id is that host, or another host
17
+ * in the same domain (a local delivery step on the same system), AND it
18
+ * sits ABOVE the first Received line that host wrote. Anything a sender
19
+ * forged arrives below that line, whatever names it uses.
20
+ *
21
+ * A pass is any of: dmarc=pass; dkim=pass whose signing domain (header.d)
22
+ * aligns with the From domain; spf=pass whose smtp.mailfrom domain aligns.
23
+ * "Aligns" is relaxed alignment: the same organisational domain (example.co.uk).
24
+ *
25
+ * No such header, or nothing aligned that passed, is NOT verified - the safe
26
+ * answer, so images stay blocked as before.
27
+ *
28
+ * Pure: header lines in, an answer out.
29
+ *
30
+ * @module _lib/mail/senderAuth
31
+ */
32
+
33
+ /** Second-level labels that are public suffixes under a country code (co.uk, com.au...). */
34
+ const SECOND_LEVEL = /^(co|com|org|net|ac|gov|ltd|plc|me|sch|nhs|edu|nom|or|ne|go)\.[a-z]{2}$/;
35
+
36
+ /** The registrable part of a host name, roughly: example.co.uk, example.com. */
37
+ export function baseDomain(host) {
38
+ const labels = String(host ?? '').toLowerCase().replace(/\.$/, '').split('.').filter(Boolean);
39
+ if (labels.length < 2) return labels.join('.');
40
+ const lastTwo = labels.slice(-2).join('.');
41
+ return SECOND_LEVEL.test(lastTwo) && labels.length >= 3 ? labels.slice(-3).join('.') : lastTwo;
42
+ }
43
+
44
+ /** Relaxed alignment (DMARC): the same organisational domain. Never a bare public suffix. */
45
+ export function aligned(a, b) {
46
+ const x = baseDomain(a), y = baseDomain(b);
47
+ return Boolean(x) && x.includes('.') && !SECOND_LEVEL.test(x) && x === y;
48
+ }
49
+
50
+ const unfold = line => String(line ?? '').replace(/\r?\n[ \t]+/g, ' ');
51
+ const valueOf = line => unfold(line).replace(/^[^:]*:\s*/, '');
52
+ /** Comments in parentheses removed (RFC 5322 CFWS, one level deep is all servers write). */
53
+ const uncomment = text => text.replace(/\([^()]*\)/g, ' ');
54
+
55
+ /** The `by` host of a Received header, or null. */
56
+ export function receivedBy(value) {
57
+ const match = /\bby\s+([A-Za-z0-9.-]+\.[A-Za-z]{2,})/i.exec(uncomment(String(value ?? '')));
58
+ return match ? match[1].toLowerCase() : null;
59
+ }
60
+
61
+ /**
62
+ * One Authentication-Results value -> {authservId, results: [{method, result, props}]}.
63
+ *
64
+ * @param {string} value
65
+ * @returns {{authservId: string, results: object[]}}
66
+ */
67
+ export function parseAuthResults(value) {
68
+ const parts = uncomment(String(value ?? '')).split(';').map(s => s.trim()).filter(Boolean);
69
+ const authservId = (parts.shift() ?? '').split(/\s+/)[0].toLowerCase();
70
+ const results = [];
71
+ for (const part of parts) {
72
+ const match = /^([a-z0-9-]+)\s*=\s*([a-z0-9-]+)(.*)$/i.exec(part);
73
+ if (!match) continue;
74
+ const props = {};
75
+ for (const prop of match[3].matchAll(/([a-z0-9-]+\.[a-z0-9-]+)\s*=\s*("[^"]*"|[^\s;]+)/gi)) {
76
+ props[prop[1].toLowerCase()] = prop[2].replace(/^"|"$/g, '');
77
+ }
78
+ results.push({method: match[1].toLowerCase(), result: match[2].toLowerCase(), props});
79
+ }
80
+ return {authservId, results};
81
+ }
82
+
83
+ /** The domain of an address or @domain / user@domain identity. */
84
+ const domainOf = value => String(value ?? '').toLowerCase().split('@').pop().replace(/[>\s]/g, '');
85
+
86
+ /**
87
+ * @param {{key: string, line: string}[]} headerLines - in message order (mailparser's `headerLines`)
88
+ * @param {string} fromAddress
89
+ * @returns {{ok: boolean, via?: string, reason?: string}}
90
+ */
91
+ export function senderAuthenticated(headerLines, fromAddress) {
92
+ const fromDomain = domainOf(fromAddress);
93
+ if (!fromDomain.includes('.')) return {ok: false, reason: 'The sender has no domain to check.'};
94
+ const lines = (headerLines ?? []).map(h => ({key: String(h?.key ?? '').toLowerCase(), value: valueOf(h?.line)}));
95
+ const received = lines.map((h, i) => ({...h, i})).filter(h => h.key === 'received');
96
+ const receiver = received.length ? receivedBy(received[0].value) : null;
97
+ if (!receiver) return {ok: false, reason: 'The message does not say which server received it.'};
98
+ for (const [i, h] of lines.entries()) {
99
+ if (h.key !== 'authentication-results') continue;
100
+ const {authservId, results} = parseAuthResults(h.value);
101
+ if (!authservId || (authservId !== receiver && baseDomain(authservId) !== baseDomain(receiver))) continue;
102
+ // Must sit above the first Received line its own server wrote.
103
+ const own = received.find(r => receivedBy(r.value) === authservId);
104
+ if (!own || own.i < i) continue;
105
+ for (const r of results) {
106
+ if (r.result !== 'pass') continue;
107
+ if (r.method === 'dmarc') return {ok: true, via: 'dmarc'};
108
+ if (r.method === 'dkim' && aligned(domainOf(r.props['header.d'] ?? r.props['header.i']), fromDomain)) return {ok: true, via: 'dkim'};
109
+ if (r.method === 'spf' && aligned(domainOf(r.props['smtp.mailfrom']), fromDomain)) return {ok: true, via: 'spf'};
110
+ }
111
+ }
112
+ return {ok: false, reason: 'Your mail server did not confirm this message came from the sender\'s domain.'};
113
+ }
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.18.0, packages/core/src/mail/sieve.js.
1
+ // Source: @domma-mail/core 0.19.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';
@@ -199,7 +199,12 @@ export async function connectSieve({target, port = 4190, security = 'starttls',
199
199
  const secure = (adapters.tlsConnect ?? tls.connect)({socket, ...tlsOptions});
200
200
  session.attach(secure);
201
201
  await connected(secure, 'secureConnect');
202
- caps = capabilities(await session.command('CAPABILITY'));
202
+ // RFC 5804 2.2: once TLS is up the server re-issues its capabilities
203
+ // unasked, ending in OK. Sending CAPABILITY here as well put every
204
+ // later reply one behind (sign-in read CAPABILITY's OK, LISTSCRIPTS
205
+ // read the capability lines), so the scripts never showed.
206
+ session.received = 0;
207
+ caps = capabilities(await session.response());
203
208
  }
204
209
  if (!caps.SASL?.split(/\s+/).includes('PLAIN')) throw new SieveError('This Sieve server does not offer password authentication over TLS.', 409);
205
210
  const token = Buffer.from(`\0${auth.user}\0${auth.pass}`).toString('base64');
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.18.0, packages/core/src/mail/smtpService.js.
1
+ // Source: @domma-mail/core 0.19.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.18.0, packages/core/src/mail/snoozeRuntime.js.
1
+ // Source: @domma-mail/core 0.19.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.18.0, packages/core/src/mail/store.js.
1
+ // Source: @domma-mail/core 0.19.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.18.0, packages/core/src/mail/subscriptions.js.
1
+ // Source: @domma-mail/core 0.19.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.18.0, packages/core/src/mail/syncPlan.js.
1
+ // Source: @domma-mail/core 0.19.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.18.0, packages/core/src/mail/syncRuntime.js.
1
+ // Source: @domma-mail/core 0.19.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.18.0, packages/core/src/mail/syncSelection.js.
1
+ // Source: @domma-mail/core 0.19.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.18.0, packages/core/src/mail/unreadBadge.js.
1
+ // Source: @domma-mail/core 0.19.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.18.0, packages/core/src/mail/unsubscribe.js.
1
+ // Source: @domma-mail/core 0.19.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,4 @@
1
- // Source: @domma-mail/core 0.18.0, packages/core/src/mail/vacationRuntime.js.
1
+ // Source: @domma-mail/core 0.19.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';
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.18.0, packages/core/src/mail/write.js.
1
+ // Source: @domma-mail/core 0.19.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.
@@ -15,6 +15,7 @@
15
15
  * @module _lib/mail/write
16
16
  */
17
17
  import {ENVELOPE_QUERY, toRecord} from './envelope.js';
18
+ import {isSpamFolder} from '../admin/mail/folder-tree.js';
18
19
 
19
20
  /** Refuse IMAP fallbacks that could expunge mail outside the selected UID set. */
20
21
  export function safeWritePool(pool) {
@@ -355,7 +356,8 @@ export const NOT_JUNK_KEYWORD = '$NotJunk';
355
356
  * @returns {{destination: string|null, add: string[], remove: string[]}}
356
357
  */
357
358
  export function planSpamMove({spam, folder, junkFolder, inboxFolder = 'INBOX'}) {
358
- const inJunk = Boolean(junkFolder) && folder === junkFolder;
359
+ // The \Junk folder, or a plain folder a server filter files spam into.
360
+ const inJunk = isSpamFolder(folder, junkFolder);
359
361
 
360
362
  if (spam) {
361
363
  return {