domma-cms 1.28.3 → 1.29.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 (99) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/admin/js/lib/contacts-arrange.js +1 -1
  3. package/docs/DommaFeatures.md +5 -3
  4. package/package.json +4 -1
  5. package/plugins/_lib/admin/mail/body-menu.js +2 -0
  6. package/plugins/_lib/admin/mail/cms-host.js +22 -0
  7. package/plugins/_lib/admin/mail/compose-window.js +1027 -1021
  8. package/plugins/_lib/admin/mail/contacts.js +10 -8
  9. package/plugins/_lib/admin/mail/diagnostics-section.js +2 -0
  10. package/plugins/_lib/admin/mail/drag-drop.js +46 -0
  11. package/plugins/_lib/admin/mail/folder-tree.js +2 -0
  12. package/plugins/_lib/admin/mail/font-controls.js +6 -4
  13. package/plugins/_lib/admin/mail/fonts.js +1 -1
  14. package/plugins/_lib/admin/mail/host-context.js +87 -0
  15. package/plugins/_lib/admin/mail/identity.js +2 -0
  16. package/plugins/_lib/admin/mail/image-senders-section.js +2 -0
  17. package/plugins/_lib/admin/mail/keyboard.js +2 -0
  18. package/plugins/_lib/admin/mail/mail.css +1 -1
  19. package/plugins/_lib/admin/mail/mail.html +4 -0
  20. package/plugins/_lib/admin/mail/message-actions.js +2 -0
  21. package/plugins/_lib/admin/mail/oauth-panel.js +2 -0
  22. package/plugins/_lib/admin/mail/panes.js +2 -0
  23. package/plugins/_lib/admin/mail/reader-kit.js +2 -0
  24. package/plugins/_lib/admin/mail/reader-runtime.js +6534 -0
  25. package/plugins/_lib/admin/mail/reader-view.js +9 -6380
  26. package/plugins/_lib/admin/mail/resizable.js +2 -0
  27. package/plugins/_lib/admin/mail/restore-spam.js +13 -0
  28. package/plugins/_lib/admin/mail/rules.js +14 -0
  29. package/plugins/_lib/admin/mail/scheduling.js +4 -1
  30. package/plugins/_lib/admin/mail/section-kit.js +4 -1
  31. package/plugins/_lib/admin/mail/security-note.js +2 -0
  32. package/plugins/_lib/admin/mail/settings-section.js +11 -10
  33. package/plugins/_lib/admin/mail/templates.js +5 -2
  34. package/plugins/_lib/admin/mail/threads.js +2 -0
  35. package/plugins/_lib/admin/mail/vacation.js +16 -2
  36. package/plugins/_lib/admin/mail/when-closed.js +24 -2
  37. package/plugins/_lib/admin/ui/dates.js +2 -0
  38. package/plugins/_lib/admin/ui/resizable.js +7 -5
  39. package/plugins/_lib/contacts/mailContact.js +69 -0
  40. package/plugins/_lib/contacts/model.js +199 -0
  41. package/plugins/_lib/domma-mail-contacts.lock.json +10 -0
  42. package/plugins/_lib/domma-mail.lock.json +85 -0
  43. package/plugins/_lib/games/plays.js +15 -3
  44. package/plugins/_lib/mail/accountFileStore.js +66 -0
  45. package/plugins/_lib/mail/accountRepository.js +617 -0
  46. package/plugins/_lib/mail/accountRoutes.js +130 -0
  47. package/plugins/_lib/mail/accounts.js +66 -940
  48. package/plugins/_lib/mail/automationLock.js +10 -0
  49. package/plugins/_lib/mail/bodyTokenProvider.js +36 -0
  50. package/plugins/_lib/mail/bodyTokens.js +5 -99
  51. package/plugins/_lib/mail/compose.js +5 -3
  52. package/plugins/_lib/mail/defaults.js +2 -0
  53. package/plugins/_lib/mail/envelope.js +3 -1
  54. package/plugins/_lib/mail/folderActions.js +83 -0
  55. package/plugins/_lib/mail/folderRuntime.js +109 -0
  56. package/plugins/_lib/mail/folders.js +4 -9
  57. package/plugins/_lib/mail/imapPool.js +11 -389
  58. package/plugins/_lib/mail/imapPoolRuntime.js +396 -0
  59. package/plugins/_lib/mail/mbox.js +2 -0
  60. package/plugins/_lib/mail/message-action.js +2 -0
  61. package/plugins/_lib/mail/messageSecurity.js +4 -111
  62. package/plugins/_lib/mail/messageSecurityProvider.js +116 -0
  63. package/plugins/_lib/mail/networkAddresses.js +77 -0
  64. package/plugins/_lib/mail/networkPolicy.js +62 -0
  65. package/plugins/_lib/mail/oauth.js +3 -451
  66. package/plugins/_lib/mail/oauthAccounts.js +178 -0
  67. package/plugins/_lib/mail/oauthRouteRuntime.js +282 -0
  68. package/plugins/_lib/mail/oauthRoutes.js +7 -289
  69. package/plugins/_lib/mail/oauthRuntime.js +456 -0
  70. package/plugins/_lib/mail/pollSchedule.js +2 -0
  71. package/plugins/_lib/mail/poller.js +4 -136
  72. package/plugins/_lib/mail/pollerRuntime.js +150 -0
  73. package/plugins/_lib/mail/priority.js +2 -0
  74. package/plugins/_lib/mail/publicMailbox.js +27 -0
  75. package/plugins/_lib/mail/readRoutes.js +14 -827
  76. package/plugins/_lib/mail/readRuntime.js +701 -0
  77. package/plugins/_lib/mail/render.js +2 -0
  78. package/plugins/_lib/mail/ruleRunner.js +27 -10
  79. package/plugins/_lib/mail/scheduler.js +11 -279
  80. package/plugins/_lib/mail/schedulerRuntime.js +259 -0
  81. package/plugins/_lib/mail/secretProvider.js +112 -0
  82. package/plugins/_lib/mail/secretbox.js +12 -225
  83. package/plugins/_lib/mail/send.js +21 -537
  84. package/plugins/_lib/mail/sieve.js +211 -0
  85. package/plugins/_lib/mail/sieveHost.js +24 -0
  86. package/plugins/_lib/mail/smtpService.js +553 -0
  87. package/plugins/_lib/mail/snoozeRuntime.js +60 -0
  88. package/plugins/_lib/mail/store.js +122 -64
  89. package/plugins/_lib/mail/subscriptions.js +11 -0
  90. package/plugins/_lib/mail/sync.js +64 -290
  91. package/plugins/_lib/mail/syncPlan.js +2 -0
  92. package/plugins/_lib/mail/syncRuntime.js +255 -0
  93. package/plugins/_lib/mail/syncSelection.js +2 -0
  94. package/plugins/_lib/mail/unreadBadge.js +2 -0
  95. package/plugins/_lib/mail/unsubscribe.js +2 -0
  96. package/plugins/_lib/mail/vacationRunner.js +3 -116
  97. package/plugins/_lib/mail/vacationRuntime.js +70 -0
  98. package/plugins/_lib/mail/write.js +44 -13
  99. package/server/routes/api/contacts.js +2 -196
@@ -0,0 +1,211 @@
1
+ // Source: @domma-mail/core 0.18.0, packages/core/src/mail/sieve.js.
2
+ // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
+ /** ManageSieve (RFC 5804). One bounded, TLS-verified session per operation. */
4
+ import net from 'node:net';
5
+ import tls from 'node:tls';
6
+ import {once} from 'node:events';
7
+
8
+ export const MAX_SCRIPT_BYTES = 256 * 1024;
9
+ const MAX_RESPONSE_BYTES = 2 * MAX_SCRIPT_BYTES;
10
+ const TIMEOUT = 10000;
11
+
12
+ export class SieveError extends Error {
13
+ constructor(message, statusCode = 502) {
14
+ super(message);
15
+ this.statusCode = statusCode;
16
+ }
17
+ }
18
+
19
+ export function scriptName(value, allowEmpty = false) {
20
+ if (typeof value !== 'string' || (!allowEmpty && !value) || Buffer.byteLength(value) > 128
21
+ || /[\x00-\x1f\x7f]/.test(value)) throw new SieveError('Use a script name of 1 to 128 bytes without control characters.', 400);
22
+ return value;
23
+ }
24
+
25
+ export function scriptBody(value) {
26
+ if (typeof value !== 'string' || Buffer.byteLength(value) > MAX_SCRIPT_BYTES || value.includes('\0')) {
27
+ throw new SieveError('A Sieve script must be text of at most 256 KB without null characters.', 400);
28
+ }
29
+ return value;
30
+ }
31
+
32
+ const quote = value => `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
33
+
34
+ /** Parse a complete response record, including octet-counted UTF-8 literals. */
35
+ export function parseRecord(buffer) {
36
+ const tokens = [];
37
+ let at = 0;
38
+ while (at < buffer.length) {
39
+ const ch = buffer[at];
40
+ if (ch === 32) { at++; continue; }
41
+ if (ch === 13) {
42
+ if (at + 1 >= buffer.length) return null;
43
+ if (buffer[at + 1] !== 10) throw new SieveError('Malformed ManageSieve response.');
44
+ return {tokens, bytes: at + 2};
45
+ }
46
+ if (ch === 34) {
47
+ let value = '', end = false;
48
+ const pieces = [];
49
+ for (at++; at < buffer.length; at++) {
50
+ if (buffer[at] === 34) { at++; end = true; break; }
51
+ if (buffer[at] === 92 && ++at >= buffer.length) return null;
52
+ pieces.push(buffer[at]);
53
+ }
54
+ if (!end) return null;
55
+ value = Buffer.from(pieces).toString('utf8');
56
+ tokens.push({value, string: true});
57
+ } else if (ch === 123) {
58
+ const end = buffer.indexOf('\r\n', at);
59
+ if (end === -1) return null;
60
+ const match = /^\{(\d+)\+?\}$/.exec(buffer.subarray(at, end).toString());
61
+ if (!match) throw new SieveError('Malformed ManageSieve literal.');
62
+ const size = Number(match[1]);
63
+ if (size > MAX_RESPONSE_BYTES) throw new SieveError('The ManageSieve response is too large.');
64
+ at = end + 2;
65
+ if (buffer.length < at + size) return null;
66
+ tokens.push({value: buffer.subarray(at, at + size).toString('utf8'), string: true});
67
+ at += size;
68
+ } else {
69
+ let end = at;
70
+ while (end < buffer.length && buffer[end] !== 32 && buffer[end] !== 13) end++;
71
+ if (end === buffer.length) return null;
72
+ tokens.push({value: buffer.subarray(at, end).toString('utf8'), string: false});
73
+ at = end;
74
+ }
75
+ }
76
+ return null;
77
+ }
78
+
79
+ class Session {
80
+ constructor(socket) {
81
+ this.buffer = Buffer.alloc(0);
82
+ this.records = [];
83
+ this.attach(socket);
84
+ }
85
+
86
+ attach(socket) {
87
+ this.socket = socket;
88
+ this.onData = chunk => {
89
+ this.buffer = Buffer.concat([this.buffer, chunk]);
90
+ this.received = (this.received ?? 0) + chunk.length;
91
+ if (this.received > MAX_RESPONSE_BYTES) return this.fail(new SieveError('The ManageSieve response is too large.'));
92
+ try {
93
+ let record;
94
+ while ((record = parseRecord(this.buffer))) {
95
+ this.records.push(record.tokens);
96
+ this.buffer = this.buffer.subarray(record.bytes);
97
+ }
98
+ this.wake?.();
99
+ } catch (err) { this.fail(err); }
100
+ };
101
+ this.onError = () => this.fail(new SieveError('The ManageSieve connection failed. Check the server, port and TLS certificate.'));
102
+ this.onClose = () => this.fail(new SieveError('The ManageSieve server closed the connection.'));
103
+ socket.on('data', this.onData);
104
+ socket.on('error', this.onError);
105
+ socket.on('close', this.onClose);
106
+ }
107
+
108
+ detach() {
109
+ this.socket.removeListener('data', this.onData);
110
+ this.socket.removeListener('error', this.onError);
111
+ this.socket.removeListener('close', this.onClose);
112
+ }
113
+
114
+ fail(err) {
115
+ this.error = err;
116
+ this.wake?.();
117
+ this.socket.destroy();
118
+ }
119
+
120
+ async response() {
121
+ const rows = [];
122
+ const timer = setTimeout(() => this.fail(new SieveError('The ManageSieve server did not respond in time.')), TIMEOUT);
123
+ try {
124
+ for (;;) {
125
+ while (this.records.length) {
126
+ const row = this.records.shift();
127
+ if (!row[0]?.string && ['OK', 'NO', 'BYE'].includes(row[0]?.value.toUpperCase())) {
128
+ if (row[0].value.toUpperCase() !== 'OK') {
129
+ const message = row.filter(t => t.string).map(t => t.value).join(' ');
130
+ throw new SieveError(message || 'The ManageSieve server refused this operation.', 422);
131
+ }
132
+ return rows;
133
+ }
134
+ rows.push(row);
135
+ }
136
+ if (this.error) throw this.error;
137
+ await new Promise(resolve => { this.wake = resolve; });
138
+ this.wake = null;
139
+ }
140
+ } finally { clearTimeout(timer); }
141
+ }
142
+
143
+ command(command, body) {
144
+ this.received = 0;
145
+ if (body !== undefined) {
146
+ this.socket.write(`${command} {${Buffer.byteLength(body)}+}\r\n${body}\r\n`);
147
+ } else this.socket.write(`${command}\r\n`);
148
+ return this.response();
149
+ }
150
+
151
+ async list() {
152
+ const rows = await this.command('LISTSCRIPTS');
153
+ return rows.map(row => ({name: row[0]?.value, active: row[1]?.value.toUpperCase() === 'ACTIVE'}));
154
+ }
155
+
156
+ async get(name) {
157
+ const rows = await this.command(`GETSCRIPT ${quote(scriptName(name))}`);
158
+ return rows[0]?.[0]?.value ?? '';
159
+ }
160
+
161
+ async check(body) {
162
+ if (!this.capabilities.VERSION) throw new SieveError('This server does not advertise CHECKSCRIPT support.', 409);
163
+ await this.command('CHECKSCRIPT', scriptBody(body));
164
+ }
165
+
166
+ async put(name, body) { await this.command(`PUTSCRIPT ${quote(scriptName(name))}`, scriptBody(body)); }
167
+ async activate(name) { await this.command(`SETACTIVE ${quote(scriptName(name, true))}`); }
168
+ async delete(name) { await this.command(`DELETESCRIPT ${quote(scriptName(name))}`); }
169
+ close() { this.socket.destroy(); }
170
+ }
171
+
172
+ const capabilities = rows => Object.fromEntries(rows.map(row => [row[0]?.value.toUpperCase(), row[1]?.value ?? '']));
173
+
174
+ async function connected(socket, event) {
175
+ const timer = setTimeout(() => socket.destroy(new Error('Connection timed out')), TIMEOUT);
176
+ try { await once(socket, event); } finally { clearTimeout(timer); }
177
+ }
178
+
179
+ /** Target.address has already passed host policy and DNS checks; never resolve it again. */
180
+ export async function connectSieve({target, port = 4190, security = 'starttls', auth}, adapters = {}) {
181
+ if (!['starttls', 'tls'].includes(security)) throw new SieveError('Sieve requires STARTTLS or implicit TLS.', 400);
182
+ if (!auth?.pass || !auth.user || /\0/.test(auth.user + auth.pass)) {
183
+ throw new SieveError('Sieve currently requires a mailbox signed in with a password.', 409);
184
+ }
185
+ const tlsOptions = {servername: target.servername, rejectUnauthorized: true,
186
+ checkServerIdentity: (_, cert) => tls.checkServerIdentity(target.servername || target.address, cert)};
187
+ const socket = security === 'tls'
188
+ ? (adapters.tlsConnect ?? tls.connect)({host: target.address, port, ...tlsOptions})
189
+ : (adapters.netConnect ?? net.connect)({host: target.address, port});
190
+ const session = new Session(socket);
191
+ try {
192
+ await connected(socket, security === 'tls' ? 'secureConnect' : 'connect');
193
+ let caps = capabilities(await session.response());
194
+ if (security === 'starttls') {
195
+ if (!Object.hasOwn(caps, 'STARTTLS')) throw new SieveError('This server does not offer STARTTLS for Sieve.', 409);
196
+ await session.command('STARTTLS');
197
+ if (session.buffer.length || session.records.length) throw new SieveError('Unexpected data before the TLS handshake.');
198
+ session.detach();
199
+ const secure = (adapters.tlsConnect ?? tls.connect)({socket, ...tlsOptions});
200
+ session.attach(secure);
201
+ await connected(secure, 'secureConnect');
202
+ caps = capabilities(await session.command('CAPABILITY'));
203
+ }
204
+ if (!caps.SASL?.split(/\s+/).includes('PLAIN')) throw new SieveError('This Sieve server does not offer password authentication over TLS.', 409);
205
+ const token = Buffer.from(`\0${auth.user}\0${auth.pass}`).toString('base64');
206
+ try { await session.command(`AUTHENTICATE "PLAIN" "${token}"`); }
207
+ catch { throw new SieveError('Sieve sign-in failed. Check that this server accepts the mailbox username and password.', 409); }
208
+ session.capabilities = capabilities(await session.command('CAPABILITY'));
209
+ return session;
210
+ } catch (err) { session.close(); throw err; }
211
+ }
@@ -0,0 +1,24 @@
1
+ /** Apply the site's mail policy, then pin the checked address for the TCP connection. */
2
+ import dns from 'node:dns/promises';
3
+ import net from 'node:net';
4
+ import {checkMailHost, normaliseHost} from './hostGuard.js';
5
+ import {SieveError} from './sieve.js';
6
+
7
+ // Newer hosted cores provide stricter mail policy. An absent module is the
8
+ // only reason to fall back; a refused target must never use the legacy path.
9
+ const policyUrl = new URL('../../../server/services/mailHost.js', import.meta.url);
10
+ const hostedPolicy = await import(policyUrl.href).catch(err => {
11
+ if (err.code !== 'ERR_MODULE_NOT_FOUND' || err.url !== policyUrl.href) throw err;
12
+ return null;
13
+ });
14
+
15
+ export async function resolveSieveHost(host, port, options = {}) {
16
+ if (hostedPolicy) return hostedPolicy.resolveMailHost(host, port, {kind: 'sieve'});
17
+ const name = normaliseHost(host);
18
+ const answers = net.isIP(name) ? [{address: name, family: net.isIP(name)}]
19
+ : await dns.lookup(name, {all: true});
20
+ const guard = await checkMailHost(name, {...options, lookup: async () => answers});
21
+ if (!guard.ok) throw new SieveError(guard.error, 400);
22
+ if (!answers.length) throw new SieveError('The Sieve server could not be resolved.', 400);
23
+ return {...answers[0], servername: net.isIP(name) ? undefined : name};
24
+ }