@rapidmx/web-client 0.20.0 → 0.21.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 (118) hide show
  1. package/README.md +381 -381
  2. package/apps/admin/branding/index.tsx +39 -39
  3. package/apps/admin/data-requests/index.tsx +482 -482
  4. package/apps/admin/domains/[uid].tsx +166 -166
  5. package/apps/admin/escrow-scopes/[uid].tsx +350 -350
  6. package/apps/admin/index.tsx +129 -129
  7. package/apps/admin/mailboxes/[uid].tsx +271 -271
  8. package/apps/admin/mailboxes/new/index.tsx +30 -30
  9. package/apps/admin/plugins/index.tsx +15 -15
  10. package/apps/admin/retention-policy/index.tsx +39 -39
  11. package/apps/admin/signing-certificates/index.tsx +343 -343
  12. package/apps/escrow/audit-log/index.tsx +196 -196
  13. package/apps/escrow/matters/[uid].tsx +621 -621
  14. package/apps/shared/auth/adminAccess.ts +99 -99
  15. package/apps/shared/components/admin/layout/AdminShell.tsx +384 -384
  16. package/apps/shared/components/admin/mailboxes/EraseLeftoverDataDialog.tsx +238 -238
  17. package/apps/shared/components/admin/mailboxes/EscrowScopeCard.tsx +152 -152
  18. package/apps/shared/components/admin/mailboxes/LeftoverMailboxesSection.tsx +194 -194
  19. package/apps/shared/components/admin/settings/BrandingForm.tsx +423 -423
  20. package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +119 -119
  21. package/apps/shared/components/admin/settings/MailboxPolicyForm.tsx +198 -198
  22. package/apps/shared/components/admin/settings/PluginsManager.tsx +2093 -2093
  23. package/apps/shared/components/admin/settings/RetentionPolicyForm.tsx +182 -182
  24. package/apps/shared/components/admin/setup/EscrowSetupStep.tsx +288 -288
  25. package/apps/shared/components/admin/setup/SetupWizard.tsx +446 -446
  26. package/apps/shared/components/admin/usePagedList.tsx +129 -129
  27. package/apps/shared/components/calendar/EventModal.tsx +206 -206
  28. package/apps/shared/components/calendar/MonthView.tsx +185 -185
  29. package/apps/shared/components/calendar/RecurrenceEditor.tsx +227 -227
  30. package/apps/shared/components/calendar/SplitDayView.tsx +144 -144
  31. package/apps/shared/components/calendar/TimeGridView.tsx +246 -246
  32. package/apps/shared/components/calendar/allDay.ts +124 -124
  33. package/apps/shared/components/contacts/ContactForm.tsx +383 -383
  34. package/apps/shared/components/contacts/ContactsToolbar.tsx +103 -103
  35. package/apps/shared/components/escrow/layout/EscrowShell.tsx +155 -155
  36. package/apps/shared/components/layout/AppShell.tsx +463 -461
  37. package/apps/shared/components/layout/KeyEnrollmentGate.tsx +398 -398
  38. package/apps/shared/components/layout/MailboxProvisioning.tsx +168 -168
  39. package/apps/shared/components/layout/ResponsiveToolbar.tsx +315 -315
  40. package/apps/shared/components/layout/ThemeSwitch.tsx +84 -84
  41. package/apps/shared/components/layout/UserMenu.tsx +439 -439
  42. package/apps/shared/components/mail/ConversationList.tsx +332 -332
  43. package/apps/shared/components/mail/ConversationThreadPane.tsx +613 -613
  44. package/apps/shared/components/mail/MailSelectionBar.tsx +240 -240
  45. package/apps/shared/components/mail/MenuButton.tsx +404 -404
  46. package/apps/shared/components/mail/MessageDetailPane.tsx +1757 -1757
  47. package/apps/shared/components/mail/compose/ComposeContext.tsx +312 -312
  48. package/apps/shared/components/mail/compose/ComposeToolbar.tsx +422 -422
  49. package/apps/shared/components/mail/compose/ComposeWindow.tsx +1705 -1681
  50. package/apps/shared/components/mail/compose/RichTextEditor.tsx +147 -147
  51. package/apps/shared/components/mail/compose/composeFlushRegistry.ts +60 -60
  52. package/apps/shared/components/mail/compose/quotedBody.ts +161 -161
  53. package/apps/shared/components/mail/reading/MessageMoreMenu.tsx +258 -258
  54. package/apps/shared/components/mail/reading/MessageSourceDialog.tsx +79 -79
  55. package/apps/shared/components/mail/reading/messageExport.ts +59 -59
  56. package/apps/shared/components/mail/reading/printMessage.ts +99 -99
  57. package/apps/shared/components/mail/reading/useMessageActions.ts +443 -443
  58. package/apps/shared/components/mail/verificationSeals.ts +125 -125
  59. package/apps/shared/components/rules/RuleBuilder.tsx +311 -311
  60. package/apps/shared/components/settings/SigningCertificateCard.tsx +344 -344
  61. package/apps/shared/keyboard/GlobalShortcuts.tsx +51 -51
  62. package/apps/shared/keyboard/ShortcutProvider.tsx +62 -62
  63. package/apps/shared/keyboard/ShortcutsDialog.tsx +84 -84
  64. package/apps/shared/keyboard/dispatch.ts +124 -124
  65. package/apps/shared/keyboard/format.ts +89 -89
  66. package/apps/shared/keyboard/keymap.ts +114 -114
  67. package/apps/shared/keyboard/registry.ts +65 -65
  68. package/apps/shared/keyboard/targets.ts +79 -79
  69. package/apps/shared/mail/folderOfType.ts +49 -49
  70. package/apps/shared/mail/folderTree.ts +143 -143
  71. package/apps/shared/mail/listAllPages.ts +39 -39
  72. package/apps/shared/mail/newMailNotifications.ts +171 -171
  73. package/apps/shared/mail/outbox/sendJob.ts +445 -445
  74. package/apps/shared/mail/outbox/sendOutcomes.ts +155 -155
  75. package/apps/shared/mail/reportNotices.ts +66 -66
  76. package/apps/shared/mail/senderBlocking.ts +141 -141
  77. package/apps/shared/mail/useMailConnection.ts +205 -205
  78. package/apps/shared/mail/useMailLiveUpdates.ts +277 -277
  79. package/apps/shared/mail/useMailboxUpdateAccess.ts +60 -60
  80. package/apps/shared/mail/useMarkMessageRead.ts +47 -47
  81. package/apps/shared/mail/useNewMailNotifications.ts +178 -178
  82. package/apps/shared/notifications/store.ts +560 -560
  83. package/apps/shared/search/LocalIndexLifecycle.tsx +114 -114
  84. package/apps/shared/search/localIndexBuilder.ts +481 -481
  85. package/apps/shared/signing/enrollmentStorage.ts +33 -33
  86. package/apps/shared/signing/enrollmentTracker.ts +385 -385
  87. package/apps/shared/signing/enrollmentView.ts +251 -251
  88. package/apps/shared/signing/useNow.ts +19 -19
  89. package/apps/shared/signing/useSigningEnrollmentWatcher.ts +90 -90
  90. package/apps/shared/styles/app.css +396 -396
  91. package/apps/www/calendar/index.tsx +581 -581
  92. package/apps/www/contacts/[uid].tsx +112 -112
  93. package/apps/www/index.tsx +3012 -3012
  94. package/apps/www/messages/[uid].tsx +139 -139
  95. package/apps/www/settings/auto-reply/index.tsx +136 -136
  96. package/apps/www/settings/blocked-senders/index.tsx +303 -303
  97. package/apps/www/settings/encryption/index.tsx +1290 -1290
  98. package/apps/www/settings/filters/[uid].tsx +179 -179
  99. package/apps/www/settings/filters/index.tsx +105 -105
  100. package/apps/www/settings/filters/new/index.tsx +165 -165
  101. package/apps/www/settings/labels/index.tsx +207 -207
  102. package/apps/www/settings/privacy/index.tsx +495 -495
  103. package/apps/www/settings/profile/index.tsx +251 -251
  104. package/apps/www/settings/read-receipts/index.tsx +150 -150
  105. package/apps/www/settings/sharing/index.tsx +259 -259
  106. package/apps/www/settings/signatures/[uid].tsx +175 -175
  107. package/apps/www/settings/signatures/index.tsx +91 -91
  108. package/apps/www/settings/signatures/new/index.tsx +138 -138
  109. package/apps/www/tasks/index.tsx +654 -654
  110. package/dist/apps/shared/components/admin/layout/AdminShell.js +2 -2
  111. package/dist/apps/shared/components/admin/settings/BrandingForm.js +3 -3
  112. package/dist/apps/shared/components/escrow/layout/EscrowShell.js +2 -2
  113. package/dist/apps/shared/components/layout/AppShell.js +4 -2
  114. package/dist/apps/shared/components/mail/compose/ComposeWindow.d.ts +7 -1
  115. package/dist/apps/shared/components/mail/compose/ComposeWindow.js +20 -1
  116. package/dist/apps/shared/components/mail/reading/printMessage.js +11 -11
  117. package/dist/apps/shared/styles/app.css +396 -396
  118. package/package.json +2 -2
@@ -1,303 +1,303 @@
1
- ///////////////////////////////////////////////////////////////////////////////
2
- // Copyright (C) 2026 Jean-Philippe Steinmetz
3
- // SPDX-License-Identifier: MPL-2.0
4
- ///////////////////////////////////////////////////////////////////////////////
5
- import { pageTitle } from "../../../shared/navigation/pageTitle.js";
6
- import React, { FormEvent, useId, useRef, useState } from "react";
7
- import { blockedSendersOf, isSharedWithMe, safeSendersOf } from "@rapidmx/react-shared/mail/mailApi.js";
8
- import {
9
- MAX_SENDER_LIST_ENTRIES,
10
- SenderListKind,
11
- SenderListsChange,
12
- addBlockedSender,
13
- addSafeSender,
14
- checkSenderEntry,
15
- removeBlockedSender,
16
- removeSafeSender,
17
- } from "@rapidmx/react-shared/mail/senderListsApi.js";
18
- import SettingsShell, { SettingsShellProps, useSettingsShell } from "../../../shared/components/settings/layout/SettingsShell.js";
19
- import Button from "@rapidmx/react-shared/components/buttons/Button.js";
20
- import { useMailboxUpdateAccess } from "../../../shared/mail/useMailboxUpdateAccess.js";
21
- import { notifyApiError } from "../../../shared/notifications/apiErrors.js";
22
-
23
- export type SettingsBlockedSendersPageProps = Omit<SettingsShellProps, "active">;
24
-
25
- function SettingsBlockedSendersPage(props: SettingsBlockedSendersPageProps) {
26
- return (
27
- <SettingsShell {...props} active="blocked-senders">
28
- <BlockedSendersContent />
29
- </SettingsShell>
30
- );
31
- }
32
-
33
- /** What each list is called and does, in the words the page uses for it. */
34
- const COPY: Record<SenderListKind, { title: string; add: string; addLabel: string; verb: string; other: string; explain: string; empty: string }> = {
35
- blocked: {
36
- title: "Blocked senders",
37
- add: "Block",
38
- addLabel: "Add a blocked sender",
39
- verb: "Blocked",
40
- other: "safe senders",
41
- explain: "Mail from these addresses and domains goes to Junk Email, without the spam filter or your filters looking at it.",
42
- empty: "No blocked senders.",
43
- },
44
- safe: {
45
- title: "Safe senders",
46
- add: "Trust",
47
- addLabel: "Add a safe sender",
48
- verb: "Trusted",
49
- other: "blocked senders",
50
- explain:
51
- "Mail from these addresses and domains is not sent to Junk Email because of the spam filter's verdict, as long as it passes authentication: " +
52
- "a valid signature from the sender's own domain. Mail that fails it, carries a virus or is quarantined by policy is still kept out.",
53
- empty: "No safe senders.",
54
- },
55
- };
56
-
57
- const CAP = MAX_SENDER_LIST_ENTRIES.toLocaleString("en-US");
58
-
59
- interface ListSectionProps {
60
- kind: SenderListKind;
61
- entries: string[];
62
- /** The other list, to say when an entry moves here from it. */
63
- otherEntries: string[];
64
- /** The reader's own addresses: they are not blocked. */
65
- ownAddresses: string[];
66
- editable: boolean;
67
- onAdd: (entry: string) => Promise<SenderListsChange | undefined>;
68
- onRemove: (entry: string) => Promise<SenderListsChange | undefined>;
69
- }
70
-
71
- /** One list: its count, the form that adds an address or domain to it, and its entries with a Remove button each. */
72
- function ListSection({ kind, entries, otherEntries, ownAddresses, editable, onAdd, onRemove }: ListSectionProps) {
73
- const copy = COPY[kind];
74
- const id = useId();
75
- const headingRef = useRef<HTMLHeadingElement>(null);
76
- const [value, setValue] = useState("");
77
- const [error, setError] = useState<string | null>(null);
78
- const [status, setStatus] = useState<string | null>(null);
79
- const [busy, setBusy] = useState(false);
80
- const full = entries.length >= MAX_SENDER_LIST_ENTRIES;
81
- const sorted = [...entries].sort();
82
-
83
- async function handleAdd(e: FormEvent) {
84
- e.preventDefault();
85
- setStatus(null);
86
- const checked = checkSenderEntry(value);
87
- if (!checked.ok) {
88
- setError(checked.message);
89
- return;
90
- }
91
- if (kind === "blocked" && ownAddresses.includes(checked.entry)) {
92
- setError("That is one of your own addresses, so it cannot be blocked.");
93
- return;
94
- }
95
- setError(null);
96
- setBusy(true);
97
- try {
98
- const moved = otherEntries.includes(checked.entry);
99
- const result = await onAdd(checked.entry);
100
- if (result) {
101
- setValue("");
102
- setStatus(
103
- !result.changed
104
- ? `${checked.entry} is already on this list.`
105
- : `${copy.verb} ${checked.entry}.${moved ? ` It was on your ${copy.other} and was moved here.` : ""}`,
106
- );
107
- }
108
- } finally {
109
- setBusy(false);
110
- }
111
- }
112
-
113
- async function handleRemove(entry: string) {
114
- setStatus(null);
115
- setBusy(true);
116
- try {
117
- if (await onRemove(entry)) {
118
- setStatus(`Removed ${entry}.`);
119
- // The button that was pressed is gone with its entry: focus goes to the list's heading rather than back to the page's start.
120
- headingRef.current?.focus();
121
- }
122
- } finally {
123
- setBusy(false);
124
- }
125
- }
126
-
127
- return (
128
- <section aria-labelledby={`${id}-title`} className="min-w-0 rounded-md border border-border bg-surface p-4">
129
- <h2 id={`${id}-title`} ref={headingRef} tabIndex={-1} className="text-base font-bold tracking-tight outline-none">
130
- {copy.title}
131
- </h2>
132
- <p className="text-xs text-text-muted mt-0.5 mb-2">
133
- {entries.length.toLocaleString("en-US")} of {CAP}
134
- </p>
135
- <p className="text-sm text-text-muted mb-3">{copy.explain}</p>
136
-
137
- {editable && (
138
- <form onSubmit={handleAdd} noValidate className="mb-3">
139
- <label htmlFor={`${id}-entry`} className="block text-sm font-semibold mb-1.5 text-text">
140
- {copy.addLabel}
141
- </label>
142
- <div className="flex flex-col sm:flex-row gap-2">
143
- <input
144
- id={`${id}-entry`}
145
- type="text"
146
- inputMode="email"
147
- autoComplete="off"
148
- autoCapitalize="none"
149
- spellCheck={false}
150
- value={value}
151
- disabled={full || busy}
152
- placeholder="name@example.com or example.com"
153
- aria-invalid={error ? true : undefined}
154
- aria-describedby={`${id}-hint${error ? ` ${id}-error` : ""}`}
155
- onChange={(e) => {
156
- setValue(e.target.value);
157
- setError(null);
158
- }}
159
- className="flex-1 min-w-0 text-sm px-3 py-1.5 rounded-md border border-border bg-surface disabled:opacity-55"
160
- />
161
- <Button type="submit" className="!w-auto shrink-0" disabled={full || busy} loading={busy}>
162
- {copy.add}
163
- </Button>
164
- </div>
165
- <p id={`${id}-hint`} className="text-xs text-text-muted mt-1">
166
- A domain such as example.com covers every address at it, but not its subdomains. An address already on your {copy.other} moves here.
167
- </p>
168
- {error && (
169
- <p id={`${id}-error`} role="alert" className="text-sm text-danger mt-1">
170
- {error}
171
- </p>
172
- )}
173
- {full && (
174
- <p className="text-sm text-danger mt-1">
175
- This list is full: it holds {CAP} senders. Remove one to add another.
176
- </p>
177
- )}
178
- </form>
179
- )}
180
-
181
- <p role="status" className="text-sm text-success font-medium mb-2 empty:hidden">
182
- {status}
183
- </p>
184
-
185
- {sorted.length === 0 ? (
186
- <p className="text-sm text-text-muted">{copy.empty}</p>
187
- ) : (
188
- <ul aria-label={copy.title} className="divide-y divide-border border-y border-border">
189
- {sorted.map((entry) => (
190
- <li key={entry} className="flex items-center justify-between gap-3 py-2">
191
- <span className="min-w-0 break-all text-sm">
192
- {entry}
193
- {entry.startsWith("@") && <span className="block text-xs text-text-muted">Everyone at {entry.slice(1)}</span>}
194
- </span>
195
- {editable && (
196
- <button
197
- type="button"
198
- disabled={busy}
199
- aria-label={`Remove ${entry} from ${copy.title.toLowerCase()}`}
200
- onClick={() => void handleRemove(entry)}
201
- className="shrink-0 text-sm font-medium text-primary-dark hover:underline disabled:opacity-55"
202
- >
203
- Remove
204
- </button>
205
- )}
206
- </li>
207
- ))}
208
- </ul>
209
- )}
210
- </section>
211
- );
212
- }
213
-
214
- function BlockedSendersContent() {
215
- const { mailboxUid } = useSettingsShell();
216
- // A mailbox chosen in the shell's switcher is a different set of lists: the content starts over for it.
217
- return <ListsContent key={mailboxUid} />;
218
- }
219
-
220
- function ListsContent() {
221
- const { mailboxUid, mailboxes } = useSettingsShell();
222
- // `SettingsShell` only ever renders its children once `mailboxes` has loaded and `mailboxUid` has resolved to one of them - same established
223
- // non-null pattern as `apps/www/settings/read-receipts/index.tsx`.
224
- const mailbox = mailboxes.find((mb) => mb.uid === mailboxUid)!;
225
- const writable = useMailboxUpdateAccess(mailbox);
226
- // The lists are the owner's (and a manager's) to change; the server does not say which of the two a delegate is, so one who may update is offered the
227
- // forms and told what a refusal means.
228
- const delegated = isSharedWithMe(mailbox);
229
- // A server before the lists sends neither.
230
- const supported = mailbox.blockedSenders !== undefined || mailbox.safeSenders !== undefined;
231
- const [blocked, setBlocked] = useState(blockedSendersOf(mailbox));
232
- const [safe, setSafe] = useState(safeSendersOf(mailbox));
233
- const ownAddresses = mailboxes.flatMap((mb) => [mb.primarySmtpAddress, ...(mb.aliasAddresses ?? [])]).filter((a) => !!a).map((a) => a.toLowerCase());
234
-
235
- async function change(action: () => Promise<SenderListsChange>, context: string): Promise<SenderListsChange | undefined> {
236
- try {
237
- const result = await action();
238
- // The answer carries both lists as they now are: adding to one takes the entry off the other.
239
- setBlocked(result.blockedSenders);
240
- setSafe(result.safeSenders);
241
- return result;
242
- } catch (err) {
243
- notifyApiError(err, context);
244
- return undefined;
245
- }
246
- }
247
-
248
- return (
249
- <div className="flex-1 min-w-0 overflow-y-auto p-4 sm:p-6">
250
- <div className="max-w-4xl">
251
- <h1 className="text-lg font-bold tracking-tight mb-1">Blocked and safe senders</h1>
252
- <p className="text-sm text-text-muted mb-4">
253
- These lists belong to <span className="font-medium text-text">{mailbox.displayName}</span> ({mailbox.primarySmtpAddress}). Each entry is an email address or a domain. An
254
- entry is on one list at a time: adding it to one takes it off the other.
255
- </p>
256
-
257
- {!supported ? (
258
- <p role="status" className="text-sm text-text-muted">
259
- This server does not support blocked and safe senders yet.
260
- </p>
261
- ) : (
262
- <>
263
- {!writable && (
264
- <p role="status" className="text-sm rounded-md border border-border bg-surface-alt px-3 py-2 mb-4">
265
- You have view-only access to this mailbox, so you can see these lists but not change them.
266
- </p>
267
- )}
268
- {writable && delegated && (
269
- <p className="text-sm text-text-muted mb-4">
270
- Only this mailbox&rsquo;s owner, or someone with full access to it, can change these lists. If you cannot, the server says so when you try.
271
- </p>
272
- )}
273
- <div className="grid gap-4 md:grid-cols-2">
274
- <ListSection
275
- kind="blocked"
276
- entries={blocked}
277
- otherEntries={safe}
278
- ownAddresses={ownAddresses}
279
- editable={writable}
280
- onAdd={(entry) => change(() => addBlockedSender(mailbox.uid, entry), "Couldn't block this sender")}
281
- onRemove={(entry) => change(() => removeBlockedSender(mailbox.uid, entry), "Couldn't unblock this sender")}
282
- />
283
- <ListSection
284
- kind="safe"
285
- entries={safe}
286
- otherEntries={blocked}
287
- ownAddresses={ownAddresses}
288
- editable={writable}
289
- onAdd={(entry) => change(() => addSafeSender(mailbox.uid, entry), "Couldn't add this safe sender")}
290
- onRemove={(entry) => change(() => removeSafeSender(mailbox.uid, entry), "Couldn't remove this safe sender")}
291
- />
292
- </div>
293
- </>
294
- )}
295
- </div>
296
- </div>
297
- );
298
- }
299
-
300
- export default SettingsBlockedSendersPage;
301
-
302
- /** The tab's title: `Brand: Settings` (see `pageTitle()`). */
303
- export const title = pageTitle("Settings");
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import { pageTitle } from "../../../shared/navigation/pageTitle.js";
6
+ import React, { FormEvent, useId, useRef, useState } from "react";
7
+ import { blockedSendersOf, isSharedWithMe, safeSendersOf } from "@rapidmx/react-shared/mail/mailApi.js";
8
+ import {
9
+ MAX_SENDER_LIST_ENTRIES,
10
+ SenderListKind,
11
+ SenderListsChange,
12
+ addBlockedSender,
13
+ addSafeSender,
14
+ checkSenderEntry,
15
+ removeBlockedSender,
16
+ removeSafeSender,
17
+ } from "@rapidmx/react-shared/mail/senderListsApi.js";
18
+ import SettingsShell, { SettingsShellProps, useSettingsShell } from "../../../shared/components/settings/layout/SettingsShell.js";
19
+ import Button from "@rapidmx/react-shared/components/buttons/Button.js";
20
+ import { useMailboxUpdateAccess } from "../../../shared/mail/useMailboxUpdateAccess.js";
21
+ import { notifyApiError } from "../../../shared/notifications/apiErrors.js";
22
+
23
+ export type SettingsBlockedSendersPageProps = Omit<SettingsShellProps, "active">;
24
+
25
+ function SettingsBlockedSendersPage(props: SettingsBlockedSendersPageProps) {
26
+ return (
27
+ <SettingsShell {...props} active="blocked-senders">
28
+ <BlockedSendersContent />
29
+ </SettingsShell>
30
+ );
31
+ }
32
+
33
+ /** What each list is called and does, in the words the page uses for it. */
34
+ const COPY: Record<SenderListKind, { title: string; add: string; addLabel: string; verb: string; other: string; explain: string; empty: string }> = {
35
+ blocked: {
36
+ title: "Blocked senders",
37
+ add: "Block",
38
+ addLabel: "Add a blocked sender",
39
+ verb: "Blocked",
40
+ other: "safe senders",
41
+ explain: "Mail from these addresses and domains goes to Junk Email, without the spam filter or your filters looking at it.",
42
+ empty: "No blocked senders.",
43
+ },
44
+ safe: {
45
+ title: "Safe senders",
46
+ add: "Trust",
47
+ addLabel: "Add a safe sender",
48
+ verb: "Trusted",
49
+ other: "blocked senders",
50
+ explain:
51
+ "Mail from these addresses and domains is not sent to Junk Email because of the spam filter's verdict, as long as it passes authentication: " +
52
+ "a valid signature from the sender's own domain. Mail that fails it, carries a virus or is quarantined by policy is still kept out.",
53
+ empty: "No safe senders.",
54
+ },
55
+ };
56
+
57
+ const CAP = MAX_SENDER_LIST_ENTRIES.toLocaleString("en-US");
58
+
59
+ interface ListSectionProps {
60
+ kind: SenderListKind;
61
+ entries: string[];
62
+ /** The other list, to say when an entry moves here from it. */
63
+ otherEntries: string[];
64
+ /** The reader's own addresses: they are not blocked. */
65
+ ownAddresses: string[];
66
+ editable: boolean;
67
+ onAdd: (entry: string) => Promise<SenderListsChange | undefined>;
68
+ onRemove: (entry: string) => Promise<SenderListsChange | undefined>;
69
+ }
70
+
71
+ /** One list: its count, the form that adds an address or domain to it, and its entries with a Remove button each. */
72
+ function ListSection({ kind, entries, otherEntries, ownAddresses, editable, onAdd, onRemove }: ListSectionProps) {
73
+ const copy = COPY[kind];
74
+ const id = useId();
75
+ const headingRef = useRef<HTMLHeadingElement>(null);
76
+ const [value, setValue] = useState("");
77
+ const [error, setError] = useState<string | null>(null);
78
+ const [status, setStatus] = useState<string | null>(null);
79
+ const [busy, setBusy] = useState(false);
80
+ const full = entries.length >= MAX_SENDER_LIST_ENTRIES;
81
+ const sorted = [...entries].sort();
82
+
83
+ async function handleAdd(e: FormEvent) {
84
+ e.preventDefault();
85
+ setStatus(null);
86
+ const checked = checkSenderEntry(value);
87
+ if (!checked.ok) {
88
+ setError(checked.message);
89
+ return;
90
+ }
91
+ if (kind === "blocked" && ownAddresses.includes(checked.entry)) {
92
+ setError("That is one of your own addresses, so it cannot be blocked.");
93
+ return;
94
+ }
95
+ setError(null);
96
+ setBusy(true);
97
+ try {
98
+ const moved = otherEntries.includes(checked.entry);
99
+ const result = await onAdd(checked.entry);
100
+ if (result) {
101
+ setValue("");
102
+ setStatus(
103
+ !result.changed
104
+ ? `${checked.entry} is already on this list.`
105
+ : `${copy.verb} ${checked.entry}.${moved ? ` It was on your ${copy.other} and was moved here.` : ""}`,
106
+ );
107
+ }
108
+ } finally {
109
+ setBusy(false);
110
+ }
111
+ }
112
+
113
+ async function handleRemove(entry: string) {
114
+ setStatus(null);
115
+ setBusy(true);
116
+ try {
117
+ if (await onRemove(entry)) {
118
+ setStatus(`Removed ${entry}.`);
119
+ // The button that was pressed is gone with its entry: focus goes to the list's heading rather than back to the page's start.
120
+ headingRef.current?.focus();
121
+ }
122
+ } finally {
123
+ setBusy(false);
124
+ }
125
+ }
126
+
127
+ return (
128
+ <section aria-labelledby={`${id}-title`} className="min-w-0 rounded-md border border-border bg-surface p-4">
129
+ <h2 id={`${id}-title`} ref={headingRef} tabIndex={-1} className="text-base font-bold tracking-tight outline-none">
130
+ {copy.title}
131
+ </h2>
132
+ <p className="text-xs text-text-muted mt-0.5 mb-2">
133
+ {entries.length.toLocaleString("en-US")} of {CAP}
134
+ </p>
135
+ <p className="text-sm text-text-muted mb-3">{copy.explain}</p>
136
+
137
+ {editable && (
138
+ <form onSubmit={handleAdd} noValidate className="mb-3">
139
+ <label htmlFor={`${id}-entry`} className="block text-sm font-semibold mb-1.5 text-text">
140
+ {copy.addLabel}
141
+ </label>
142
+ <div className="flex flex-col sm:flex-row gap-2">
143
+ <input
144
+ id={`${id}-entry`}
145
+ type="text"
146
+ inputMode="email"
147
+ autoComplete="off"
148
+ autoCapitalize="none"
149
+ spellCheck={false}
150
+ value={value}
151
+ disabled={full || busy}
152
+ placeholder="name@example.com or example.com"
153
+ aria-invalid={error ? true : undefined}
154
+ aria-describedby={`${id}-hint${error ? ` ${id}-error` : ""}`}
155
+ onChange={(e) => {
156
+ setValue(e.target.value);
157
+ setError(null);
158
+ }}
159
+ className="flex-1 min-w-0 text-sm px-3 py-1.5 rounded-md border border-border bg-surface disabled:opacity-55"
160
+ />
161
+ <Button type="submit" className="!w-auto shrink-0" disabled={full || busy} loading={busy}>
162
+ {copy.add}
163
+ </Button>
164
+ </div>
165
+ <p id={`${id}-hint`} className="text-xs text-text-muted mt-1">
166
+ A domain such as example.com covers every address at it, but not its subdomains. An address already on your {copy.other} moves here.
167
+ </p>
168
+ {error && (
169
+ <p id={`${id}-error`} role="alert" className="text-sm text-danger mt-1">
170
+ {error}
171
+ </p>
172
+ )}
173
+ {full && (
174
+ <p className="text-sm text-danger mt-1">
175
+ This list is full: it holds {CAP} senders. Remove one to add another.
176
+ </p>
177
+ )}
178
+ </form>
179
+ )}
180
+
181
+ <p role="status" className="text-sm text-success font-medium mb-2 empty:hidden">
182
+ {status}
183
+ </p>
184
+
185
+ {sorted.length === 0 ? (
186
+ <p className="text-sm text-text-muted">{copy.empty}</p>
187
+ ) : (
188
+ <ul aria-label={copy.title} className="divide-y divide-border border-y border-border">
189
+ {sorted.map((entry) => (
190
+ <li key={entry} className="flex items-center justify-between gap-3 py-2">
191
+ <span className="min-w-0 break-all text-sm">
192
+ {entry}
193
+ {entry.startsWith("@") && <span className="block text-xs text-text-muted">Everyone at {entry.slice(1)}</span>}
194
+ </span>
195
+ {editable && (
196
+ <button
197
+ type="button"
198
+ disabled={busy}
199
+ aria-label={`Remove ${entry} from ${copy.title.toLowerCase()}`}
200
+ onClick={() => void handleRemove(entry)}
201
+ className="shrink-0 text-sm font-medium text-primary-dark hover:underline disabled:opacity-55"
202
+ >
203
+ Remove
204
+ </button>
205
+ )}
206
+ </li>
207
+ ))}
208
+ </ul>
209
+ )}
210
+ </section>
211
+ );
212
+ }
213
+
214
+ function BlockedSendersContent() {
215
+ const { mailboxUid } = useSettingsShell();
216
+ // A mailbox chosen in the shell's switcher is a different set of lists: the content starts over for it.
217
+ return <ListsContent key={mailboxUid} />;
218
+ }
219
+
220
+ function ListsContent() {
221
+ const { mailboxUid, mailboxes } = useSettingsShell();
222
+ // `SettingsShell` only ever renders its children once `mailboxes` has loaded and `mailboxUid` has resolved to one of them - same established
223
+ // non-null pattern as `apps/www/settings/read-receipts/index.tsx`.
224
+ const mailbox = mailboxes.find((mb) => mb.uid === mailboxUid)!;
225
+ const writable = useMailboxUpdateAccess(mailbox);
226
+ // The lists are the owner's (and a manager's) to change; the server does not say which of the two a delegate is, so one who may update is offered the
227
+ // forms and told what a refusal means.
228
+ const delegated = isSharedWithMe(mailbox);
229
+ // A server before the lists sends neither.
230
+ const supported = mailbox.blockedSenders !== undefined || mailbox.safeSenders !== undefined;
231
+ const [blocked, setBlocked] = useState(blockedSendersOf(mailbox));
232
+ const [safe, setSafe] = useState(safeSendersOf(mailbox));
233
+ const ownAddresses = mailboxes.flatMap((mb) => [mb.primarySmtpAddress, ...(mb.aliasAddresses ?? [])]).filter((a) => !!a).map((a) => a.toLowerCase());
234
+
235
+ async function change(action: () => Promise<SenderListsChange>, context: string): Promise<SenderListsChange | undefined> {
236
+ try {
237
+ const result = await action();
238
+ // The answer carries both lists as they now are: adding to one takes the entry off the other.
239
+ setBlocked(result.blockedSenders);
240
+ setSafe(result.safeSenders);
241
+ return result;
242
+ } catch (err) {
243
+ notifyApiError(err, context);
244
+ return undefined;
245
+ }
246
+ }
247
+
248
+ return (
249
+ <div className="flex-1 min-w-0 overflow-y-auto p-4 sm:p-6">
250
+ <div className="max-w-4xl">
251
+ <h1 className="text-lg font-bold tracking-tight mb-1">Blocked and safe senders</h1>
252
+ <p className="text-sm text-text-muted mb-4">
253
+ These lists belong to <span className="font-medium text-text">{mailbox.displayName}</span> ({mailbox.primarySmtpAddress}). Each entry is an email address or a domain. An
254
+ entry is on one list at a time: adding it to one takes it off the other.
255
+ </p>
256
+
257
+ {!supported ? (
258
+ <p role="status" className="text-sm text-text-muted">
259
+ This server does not support blocked and safe senders yet.
260
+ </p>
261
+ ) : (
262
+ <>
263
+ {!writable && (
264
+ <p role="status" className="text-sm rounded-md border border-border bg-surface-alt px-3 py-2 mb-4">
265
+ You have view-only access to this mailbox, so you can see these lists but not change them.
266
+ </p>
267
+ )}
268
+ {writable && delegated && (
269
+ <p className="text-sm text-text-muted mb-4">
270
+ Only this mailbox&rsquo;s owner, or someone with full access to it, can change these lists. If you cannot, the server says so when you try.
271
+ </p>
272
+ )}
273
+ <div className="grid gap-4 md:grid-cols-2">
274
+ <ListSection
275
+ kind="blocked"
276
+ entries={blocked}
277
+ otherEntries={safe}
278
+ ownAddresses={ownAddresses}
279
+ editable={writable}
280
+ onAdd={(entry) => change(() => addBlockedSender(mailbox.uid, entry), "Couldn't block this sender")}
281
+ onRemove={(entry) => change(() => removeBlockedSender(mailbox.uid, entry), "Couldn't unblock this sender")}
282
+ />
283
+ <ListSection
284
+ kind="safe"
285
+ entries={safe}
286
+ otherEntries={blocked}
287
+ ownAddresses={ownAddresses}
288
+ editable={writable}
289
+ onAdd={(entry) => change(() => addSafeSender(mailbox.uid, entry), "Couldn't add this safe sender")}
290
+ onRemove={(entry) => change(() => removeSafeSender(mailbox.uid, entry), "Couldn't remove this safe sender")}
291
+ />
292
+ </div>
293
+ </>
294
+ )}
295
+ </div>
296
+ </div>
297
+ );
298
+ }
299
+
300
+ export default SettingsBlockedSendersPage;
301
+
302
+ /** The tab's title: `Brand: Settings` (see `pageTitle()`). */
303
+ export const title = pageTitle("Settings");