@rapidmx/web-client 0.16.0 → 0.17.2

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 (184) hide show
  1. package/README.md +36 -28
  2. package/apps/admin/distribution-lists/new/index.tsx +3 -1
  3. package/apps/admin/domains/[uid].tsx +3 -1
  4. package/apps/admin/domains/new/index.tsx +3 -1
  5. package/apps/admin/escrow-scopes/[uid].tsx +3 -1
  6. package/apps/admin/escrow-scopes/new/index.tsx +3 -1
  7. package/apps/admin/index.tsx +3 -1
  8. package/apps/admin/mailboxes/[uid].tsx +3 -1
  9. package/apps/admin/mailboxes/new/index.tsx +3 -1
  10. package/apps/admin/transport-rules/new/index.tsx +3 -1
  11. package/apps/escrow/matters/new/index.tsx +3 -1
  12. package/apps/shared/components/admin/layout/AdminShell.tsx +4 -1
  13. package/apps/shared/components/admin/setup/SetupWizard.tsx +3 -1
  14. package/apps/shared/components/calendar/layout/CalendarShell.tsx +2 -2
  15. package/apps/shared/components/contacts/layout/ContactsShell.tsx +2 -2
  16. package/apps/shared/components/layout/AppShell.tsx +24 -43
  17. package/apps/shared/components/mail/ConversationThreadPane.tsx +1 -0
  18. package/apps/shared/components/mail/EmptyFolderBar.tsx +41 -0
  19. package/apps/shared/components/mail/MailSelectionBar.tsx +19 -15
  20. package/apps/shared/components/mail/MenuButton.tsx +31 -11
  21. package/apps/shared/components/mail/MessageDetailPane.tsx +202 -4
  22. package/apps/shared/components/mail/PermanentDeleteDialog.tsx +47 -0
  23. package/apps/shared/components/mail/layout/MailShell.tsx +36 -34
  24. package/apps/shared/components/mail/reading/MessageMoreMenu.tsx +258 -0
  25. package/apps/shared/components/mail/reading/MessageSourceDialog.tsx +79 -0
  26. package/apps/shared/components/mail/reading/messageExport.ts +59 -0
  27. package/apps/shared/components/mail/reading/printMessage.ts +99 -0
  28. package/apps/shared/components/mail/reading/useMessageActions.ts +443 -0
  29. package/apps/shared/components/settings/layout/SettingsShell.tsx +3 -2
  30. package/apps/shared/components/tasks/layout/TasksShell.tsx +2 -2
  31. package/apps/shared/keyboard/GlobalShortcuts.tsx +1 -1
  32. package/apps/shared/mail/folderOfType.ts +49 -0
  33. package/apps/shared/mail/permanentDelete.ts +160 -0
  34. package/apps/shared/mail/reportNotices.ts +66 -0
  35. package/apps/shared/mail/senderBlocking.ts +141 -0
  36. package/apps/shared/mail/useMailboxUpdateAccess.ts +60 -0
  37. package/apps/shared/mail/usePermanentDelete.tsx +160 -0
  38. package/apps/shared/navigation/frameContext.tsx +1 -1
  39. package/apps/shared/navigation/index.ts +70 -0
  40. package/apps/shared/navigation/pageTitle.ts +19 -0
  41. package/apps/www/_shell.tsx +82 -0
  42. package/apps/www/calendar/index.tsx +5 -2
  43. package/apps/www/contacts/[uid].tsx +6 -3
  44. package/apps/www/contacts/index.tsx +8 -3
  45. package/apps/www/index.tsx +146 -31
  46. package/apps/www/messages/[uid].tsx +8 -4
  47. package/apps/www/settings/appearance/index.tsx +5 -2
  48. package/apps/www/settings/auto-reply/index.tsx +5 -2
  49. package/apps/www/settings/blocked-senders/index.tsx +303 -0
  50. package/apps/www/settings/encryption/index.tsx +5 -2
  51. package/apps/www/settings/filters/[uid].tsx +5 -2
  52. package/apps/www/settings/filters/index.tsx +5 -2
  53. package/apps/www/settings/filters/new/index.tsx +30 -5
  54. package/apps/www/settings/labels/index.tsx +5 -2
  55. package/apps/www/settings/privacy/index.tsx +5 -2
  56. package/apps/www/settings/profile/index.tsx +5 -2
  57. package/apps/www/settings/read-receipts/index.tsx +5 -2
  58. package/apps/www/settings/sharing/index.tsx +5 -2
  59. package/apps/www/settings/signatures/[uid].tsx +5 -2
  60. package/apps/www/settings/signatures/index.tsx +5 -2
  61. package/apps/www/settings/signatures/new/index.tsx +6 -3
  62. package/apps/www/tasks/index.tsx +7 -2
  63. package/dist/apps/admin/distribution-lists/new/index.js +3 -1
  64. package/dist/apps/admin/domains/[uid].js +3 -1
  65. package/dist/apps/admin/domains/new/index.js +3 -1
  66. package/dist/apps/admin/escrow-scopes/[uid].js +3 -1
  67. package/dist/apps/admin/escrow-scopes/new/index.js +3 -1
  68. package/dist/apps/admin/index.js +3 -1
  69. package/dist/apps/admin/mailboxes/[uid].js +3 -1
  70. package/dist/apps/admin/mailboxes/new/index.js +3 -1
  71. package/dist/apps/admin/transport-rules/new/index.js +3 -1
  72. package/dist/apps/escrow/matters/new/index.js +3 -1
  73. package/dist/apps/shared/components/admin/layout/AdminShell.js +4 -1
  74. package/dist/apps/shared/components/admin/setup/SetupWizard.js +3 -1
  75. package/dist/apps/shared/components/calendar/layout/CalendarShell.js +2 -2
  76. package/dist/apps/shared/components/contacts/layout/ContactsShell.js +2 -2
  77. package/dist/apps/shared/components/layout/AppShell.d.ts +8 -11
  78. package/dist/apps/shared/components/layout/AppShell.js +24 -33
  79. package/dist/apps/shared/components/mail/ConversationThreadPane.js +1 -1
  80. package/dist/apps/shared/components/mail/EmptyFolderBar.d.ts +18 -0
  81. package/dist/apps/shared/components/mail/EmptyFolderBar.js +10 -0
  82. package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +9 -4
  83. package/dist/apps/shared/components/mail/MailSelectionBar.js +10 -12
  84. package/dist/apps/shared/components/mail/MenuButton.d.ts +9 -2
  85. package/dist/apps/shared/components/mail/MenuButton.js +15 -11
  86. package/dist/apps/shared/components/mail/MessageDetailPane.d.ts +5 -0
  87. package/dist/apps/shared/components/mail/MessageDetailPane.js +147 -7
  88. package/dist/apps/shared/components/mail/PermanentDeleteDialog.d.ts +19 -0
  89. package/dist/apps/shared/components/mail/PermanentDeleteDialog.js +11 -0
  90. package/dist/apps/shared/components/mail/layout/MailShell.d.ts +13 -9
  91. package/dist/apps/shared/components/mail/layout/MailShell.js +26 -33
  92. package/dist/apps/shared/components/mail/reading/MessageMoreMenu.d.ts +56 -0
  93. package/dist/apps/shared/components/mail/reading/MessageMoreMenu.js +153 -0
  94. package/dist/apps/shared/components/mail/reading/MessageSourceDialog.d.ts +27 -0
  95. package/dist/apps/shared/components/mail/reading/MessageSourceDialog.js +27 -0
  96. package/dist/apps/shared/components/mail/reading/messageExport.d.ts +19 -0
  97. package/dist/apps/shared/components/mail/reading/messageExport.js +51 -0
  98. package/dist/apps/shared/components/mail/reading/printMessage.d.ts +30 -0
  99. package/dist/apps/shared/components/mail/reading/printMessage.js +70 -0
  100. package/dist/apps/shared/components/mail/reading/useMessageActions.d.ts +57 -0
  101. package/dist/apps/shared/components/mail/reading/useMessageActions.js +366 -0
  102. package/dist/apps/shared/components/settings/layout/SettingsShell.js +3 -2
  103. package/dist/apps/shared/components/tasks/layout/TasksShell.js +2 -2
  104. package/dist/apps/shared/keyboard/GlobalShortcuts.js +1 -1
  105. package/dist/apps/shared/mail/folderOfType.d.ts +13 -0
  106. package/dist/apps/shared/mail/folderOfType.js +40 -0
  107. package/dist/apps/shared/mail/permanentDelete.d.ts +62 -0
  108. package/dist/apps/shared/mail/permanentDelete.js +127 -0
  109. package/dist/apps/shared/mail/reportNotices.d.ts +21 -0
  110. package/dist/apps/shared/mail/reportNotices.js +47 -0
  111. package/dist/apps/shared/mail/senderBlocking.d.ts +26 -0
  112. package/dist/apps/shared/mail/senderBlocking.js +92 -0
  113. package/dist/apps/shared/mail/useMailboxUpdateAccess.d.ts +11 -0
  114. package/dist/apps/shared/mail/useMailboxUpdateAccess.js +52 -0
  115. package/dist/apps/shared/mail/usePermanentDelete.d.ts +35 -0
  116. package/dist/apps/shared/mail/usePermanentDelete.js +96 -0
  117. package/dist/apps/shared/navigation/frameContext.d.ts +1 -1
  118. package/dist/apps/shared/navigation/index.d.ts +27 -0
  119. package/dist/apps/shared/navigation/index.js +58 -0
  120. package/dist/apps/shared/navigation/pageTitle.d.ts +11 -0
  121. package/dist/apps/shared/navigation/pageTitle.js +12 -0
  122. package/dist/apps/www/_shell.d.ts +26 -0
  123. package/dist/apps/www/_shell.js +31 -0
  124. package/dist/apps/www/calendar/index.d.ts +7 -2
  125. package/dist/apps/www/calendar/index.js +4 -2
  126. package/dist/apps/www/contacts/[uid].d.ts +14 -3
  127. package/dist/apps/www/contacts/[uid].js +5 -3
  128. package/dist/apps/www/contacts/index.d.ts +7 -2
  129. package/dist/apps/www/contacts/index.js +6 -4
  130. package/dist/apps/www/index.d.ts +7 -2
  131. package/dist/apps/www/index.js +117 -19
  132. package/dist/apps/www/messages/[uid].d.ts +14 -3
  133. package/dist/apps/www/messages/[uid].js +7 -5
  134. package/dist/apps/www/settings/appearance/index.d.ts +8 -2
  135. package/dist/apps/www/settings/appearance/index.js +4 -2
  136. package/dist/apps/www/settings/auto-reply/index.d.ts +7 -2
  137. package/dist/apps/www/settings/auto-reply/index.js +4 -2
  138. package/dist/apps/www/settings/blocked-senders/index.d.ts +9 -0
  139. package/dist/apps/www/settings/blocked-senders/index.js +134 -0
  140. package/dist/apps/www/settings/encryption/index.d.ts +7 -2
  141. package/dist/apps/www/settings/encryption/index.js +4 -2
  142. package/dist/apps/www/settings/filters/[uid].d.ts +7 -2
  143. package/dist/apps/www/settings/filters/[uid].js +4 -2
  144. package/dist/apps/www/settings/filters/index.d.ts +7 -2
  145. package/dist/apps/www/settings/filters/index.js +4 -2
  146. package/dist/apps/www/settings/filters/new/index.d.ts +7 -2
  147. package/dist/apps/www/settings/filters/new/index.js +28 -5
  148. package/dist/apps/www/settings/labels/index.d.ts +7 -2
  149. package/dist/apps/www/settings/labels/index.js +4 -2
  150. package/dist/apps/www/settings/privacy/index.d.ts +7 -2
  151. package/dist/apps/www/settings/privacy/index.js +4 -2
  152. package/dist/apps/www/settings/profile/index.d.ts +7 -2
  153. package/dist/apps/www/settings/profile/index.js +4 -2
  154. package/dist/apps/www/settings/read-receipts/index.d.ts +7 -2
  155. package/dist/apps/www/settings/read-receipts/index.js +4 -2
  156. package/dist/apps/www/settings/sharing/index.d.ts +7 -2
  157. package/dist/apps/www/settings/sharing/index.js +4 -2
  158. package/dist/apps/www/settings/signatures/[uid].d.ts +7 -2
  159. package/dist/apps/www/settings/signatures/[uid].js +4 -2
  160. package/dist/apps/www/settings/signatures/index.d.ts +7 -2
  161. package/dist/apps/www/settings/signatures/index.js +4 -2
  162. package/dist/apps/www/settings/signatures/new/index.d.ts +7 -2
  163. package/dist/apps/www/settings/signatures/new/index.js +5 -3
  164. package/dist/apps/www/tasks/index.d.ts +7 -2
  165. package/dist/apps/www/tasks/index.js +5 -3
  166. package/package.json +4 -2
  167. package/apps/shared/navigation/AppRouter.tsx +0 -300
  168. package/apps/shared/navigation/idle.ts +0 -45
  169. package/apps/shared/navigation/routerContext.tsx +0 -83
  170. package/apps/shared/navigation/routes.ts +0 -72
  171. package/apps/www/_routedPage.tsx +0 -24
  172. package/apps/www/_routes.ts +0 -37
  173. package/dist/apps/shared/navigation/AppRouter.d.ts +0 -52
  174. package/dist/apps/shared/navigation/AppRouter.js +0 -242
  175. package/dist/apps/shared/navigation/idle.d.ts +0 -14
  176. package/dist/apps/shared/navigation/idle.js +0 -43
  177. package/dist/apps/shared/navigation/routerContext.d.ts +0 -37
  178. package/dist/apps/shared/navigation/routerContext.js +0 -56
  179. package/dist/apps/shared/navigation/routes.d.ts +0 -32
  180. package/dist/apps/shared/navigation/routes.js +0 -37
  181. package/dist/apps/www/_routedPage.d.ts +0 -12
  182. package/dist/apps/www/_routedPage.js +0 -19
  183. package/dist/apps/www/_routes.d.ts +0 -11
  184. package/dist/apps/www/_routes.js +0 -31
@@ -0,0 +1,160 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import { Message, emptyFolder, listMessages, purgeMessage } from "@rapidmx/react-shared/mail/mailApi.js";
6
+ import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
7
+ import { displaySubject } from "../components/mail/reading/EncryptedPreview.js";
8
+ import { notifySessionExpired } from "../notifications/apiErrors.js";
9
+ import { notify } from "../notifications/store.js";
10
+ import { LIST_PAGE_SIZE, MAX_LIST_PAGES, listAllPages } from "./listAllPages.js";
11
+
12
+ /**
13
+ * Permanent delete: what "Delete" does to a message that is already in Deleted Items (and what "Empty folder" does to Deleted Items and
14
+ * Junk Email). Unlike a move into Deleted Items it cannot be undone, so it is never reached without a confirmation (see
15
+ * `usePermanentDelete()`, which asks it, runs what is in here and tells the folder badges and the reader).
16
+ *
17
+ * Server side it is `DELETE /mail/messages/:uid?purge=true` (a hard delete - the row and its search document are gone, not a
18
+ * recoverable soft delete) per message, and `DELETE /mail/messages?folderUid=` (`truncate`) for a whole folder. Both refuse a message under
19
+ * an active legal hold with a `409`; the per-message form refuses one message at a time, so a selection is deleted as far as it can be and
20
+ * each refusal is reported (`PurgeFailure`), rather than the first stopping the rest.
21
+ */
22
+
23
+ /** How many purge requests are on the wire at once: a few at a time is quick, and the server publishes each folder's counts as they land. */
24
+ export const PURGE_CONCURRENCY = 4;
25
+
26
+ /** The folder types "Empty folder" is offered for: Outlook's Deleted Items and Junk Email. */
27
+ export const EMPTIABLE_FOLDER_TYPES: readonly string[] = ["deleted_items", "junk"];
28
+
29
+ /** A message the server refused to delete, and what it said. */
30
+ export interface PurgeFailure {
31
+ message: Message;
32
+ /** The server's own words (a legal hold names itself), or a stand-in when it did not answer. */
33
+ reason: string;
34
+ /** The response's status - `undefined` when there was no response. */
35
+ status?: number;
36
+ }
37
+
38
+ /** What deleting several messages came to: those that are gone, and those that are not (with why). Together they are all that was asked for. */
39
+ export interface PurgeOutcome {
40
+ deleted: Message[];
41
+ failed: PurgeFailure[];
42
+ }
43
+
44
+ /** What emptying a folder came to. */
45
+ export interface EmptyFolderOutcome extends PurgeOutcome {
46
+ /** Nothing is left in the folder as far as this knows: the whole-folder request went through, or every message listed was deleted. */
47
+ emptied: boolean;
48
+ }
49
+
50
+ function describeFailure(err: unknown): { reason: string; status?: number } {
51
+ if (err instanceof ApiRequestError) {
52
+ return { reason: err.message || `The server answered ${err.status}.`, status: err.status };
53
+ }
54
+ return { reason: "The server couldn't be reached." };
55
+ }
56
+
57
+ /** `1 message`, `3 messages`. */
58
+ export function messageCount(count: number): string {
59
+ return `${count} message${count === 1 ? "" : "s"}`;
60
+ }
61
+
62
+ /**
63
+ * Permanently deletes `messages`, each in its own request, a few at a time. Never rejects: a refusal (a legal hold, a share without the right
64
+ * to delete, a message that is already gone) is recorded against its message and the rest carry on. `deleted` and `failed` keep the order of
65
+ * `messages`.
66
+ */
67
+ export async function purgeMessages(messages: Message[]): Promise<PurgeOutcome> {
68
+ const failures: (PurgeFailure | null)[] = new Array(messages.length).fill(null);
69
+ let next = 0;
70
+ async function worker(): Promise<void> {
71
+ while (next < messages.length) {
72
+ const index = next++;
73
+ try {
74
+ await purgeMessage(messages[index].uid);
75
+ } catch (err) {
76
+ failures[index] = { message: messages[index], ...describeFailure(err) };
77
+ }
78
+ }
79
+ }
80
+ await Promise.all(Array.from({ length: Math.min(PURGE_CONCURRENCY, messages.length) }, worker));
81
+ return {
82
+ deleted: messages.filter((_, index) => failures[index] === null),
83
+ failed: failures.filter((failure): failure is PurgeFailure => failure !== null),
84
+ };
85
+ }
86
+
87
+ /**
88
+ * Permanently deletes everything in `folderUid`: one request for the whole folder, which is all or nothing. The server refuses it as a whole
89
+ * when a message in it is under a legal hold (`409`) or when the caller may delete messages but not empty a folder (`403`, a delegate) - and
90
+ * then this lists the folder and deletes message by message instead, so what may go does and each refusal is reported. Any other failure
91
+ * (the server is down) rejects, and the caller says so.
92
+ */
93
+ export async function purgeFolder(
94
+ folderUid: string,
95
+ paging: { pageSize: number; maxPages: number } = { pageSize: LIST_PAGE_SIZE, maxPages: MAX_LIST_PAGES },
96
+ ): Promise<EmptyFolderOutcome> {
97
+ try {
98
+ await emptyFolder(folderUid);
99
+ return { emptied: true, deleted: [], failed: [] };
100
+ } catch (err) {
101
+ if (!(err instanceof ApiRequestError) || (err.status !== 403 && err.status !== 409)) {
102
+ throw err;
103
+ }
104
+ }
105
+ const listed = await listAllPages((page) => listMessages(folderUid, { limit: paging.pageSize, page }), paging.pageSize, paging.maxPages);
106
+ const outcome = await purgeMessages(listed.items);
107
+ return { ...outcome, emptied: outcome.failed.length === 0 && !listed.truncated };
108
+ }
109
+
110
+ /** The line for one refusal, in the notification's details. */
111
+ function failureLine(failure: PurgeFailure): string {
112
+ return `${displaySubject(failure.message.subject) || "(no subject)"}: ${failure.reason}`;
113
+ }
114
+
115
+ /**
116
+ * Tells the reader what a delete of several messages came to: "3 messages permanently deleted" (no Undo - there is none), or "2 deleted, 1
117
+ * could not be deleted" with the server's reasons.
118
+ */
119
+ export function notifyPurged(outcome: PurgeOutcome): void {
120
+ const { deleted, failed } = outcome;
121
+ if (failed.length === 0) {
122
+ notify({ kind: "success", title: `${messageCount(deleted.length)} permanently deleted` });
123
+ return;
124
+ }
125
+ if (failed.some((failure) => failure.status === 401)) {
126
+ notifySessionExpired();
127
+ return;
128
+ }
129
+ const reasons = [...new Set(failed.map((failure) => failure.reason))];
130
+ notify({
131
+ kind: deleted.length > 0 ? "warning" : "error",
132
+ title:
133
+ deleted.length > 0
134
+ ? `${deleted.length} deleted, ${failed.length} could not be deleted`
135
+ : `Couldn't permanently delete ${failed.length === 1 ? "that message" : "those messages"}`,
136
+ message: reasons.slice(0, 3).join(" ") + (reasons.length > 3 ? ` (and ${reasons.length - 3} more reasons)` : ""),
137
+ details: failed.map(failureLine),
138
+ sticky: true,
139
+ });
140
+ }
141
+
142
+ /**
143
+ * Tells the reader what emptying `folderName` came to. `count` is how many messages it held, when that was known: the whole-folder request
144
+ * does not say. A folder that had to be deleted message by message reports as `notifyPurged()` does, plus a word when it was too big to be
145
+ * done in one go.
146
+ */
147
+ export function notifyFolderEmptied(folderName: string, outcome: EmptyFolderOutcome, count?: number): void {
148
+ if (outcome.deleted.length === 0 && outcome.failed.length === 0 && outcome.emptied) {
149
+ notify({
150
+ kind: "success",
151
+ title: count === undefined ? `${folderName} emptied` : `${messageCount(count)} permanently deleted`,
152
+ message: count === undefined ? "Everything in it was permanently deleted." : `${folderName} is now empty.`,
153
+ });
154
+ return;
155
+ }
156
+ notifyPurged(outcome);
157
+ if (!outcome.emptied && outcome.failed.length === 0) {
158
+ notify({ kind: "info", title: `${folderName} is not empty yet`, message: "It holds more than could be deleted in one go. Empty it again to carry on." });
159
+ }
160
+ }
@@ -0,0 +1,66 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import type { MessageReportKind, MessageReportResult } from "@rapidmx/react-shared/mail/mailApi.js";
6
+
7
+ /** Where a notification's "Manage blocked senders" goes: the Blocked and safe senders page of the mailbox. */
8
+ export function senderListsHref(mailboxUid: string): string {
9
+ return `/settings/blocked-senders?mailboxUid=${encodeURIComponent(mailboxUid)}`;
10
+ }
11
+
12
+ /** What a pop-up says about reporting `kind`: the title, and the folder the message goes to. */
13
+ const KINDS: Record<MessageReportKind, { title: string; noun: string; folder: string }> = {
14
+ junk: { title: "Reported as junk", noun: "junk", folder: "Junk Email" },
15
+ phishing: { title: "Reported as phishing", noun: "phishing", folder: "Junk Email" },
16
+ not_junk: { title: "Marked as not junk", noun: "not junk", folder: "the Inbox" },
17
+ };
18
+
19
+ /** The noun of `kind` for a failure's title ("Couldn't report this message as phishing"). */
20
+ export function reportNoun(kind: MessageReportKind): string {
21
+ return KINDS[kind].noun;
22
+ }
23
+
24
+ /** The title of a pop-up for a report of `kind`. */
25
+ export function reportTitle(kind: MessageReportKind): string {
26
+ return KINDS[kind].title;
27
+ }
28
+
29
+ /** The name of the folder a report of `kind` files the message in. */
30
+ export function reportFolderName(kind: MessageReportKind): string {
31
+ return KINDS[kind].folder;
32
+ }
33
+
34
+ /** What a pop-up for a report says. `hint` is the small muted line: only for the two things a reader may want to know about (the filter could not be
35
+ * taught, or the message is encrypted so it was not), never for the ones that are simply how the server is set up. */
36
+ export interface ReportNotice {
37
+ title: string;
38
+ message: string;
39
+ hint?: string;
40
+ }
41
+
42
+ /**
43
+ * The words for what the server did with a report (`reportMessage()`'s answer): where the message went, whether the spam filter learned from it, and - for
44
+ * a report of phishing - that the server recorded it. `subject` names the message. `alwaysTrust` says the reader asked for the sender to be trusted.
45
+ */
46
+ export function reportNotice(result: MessageReportResult, subject: string, alwaysTrust: boolean): ReportNotice {
47
+ const kind = KINDS[result.kind];
48
+ const where = result.moved ? `was moved to ${kind.folder}` : `is already in ${kind.folder}`;
49
+ const learned = result.learned ? " and used to train the spam filter" : "";
50
+ const parts = [`“${subject}” ${where}${learned}.`];
51
+ if (result.kind === "phishing") {
52
+ parts.push("The report was recorded in the audit log.");
53
+ }
54
+ if (result.safeSender) {
55
+ parts.push(`Mail from ${result.safeSender} that passes authentication is no longer sent to Junk Email.`);
56
+ } else if (alwaysTrust) {
57
+ parts.push("The message names no address that could be trusted.");
58
+ }
59
+ const hint =
60
+ result.learnSkipped === "failed"
61
+ ? "The spam filter could not be trained from this report."
62
+ : result.learnSkipped === "encrypted"
63
+ ? "Not used to train the spam filter: the message is encrypted."
64
+ : undefined;
65
+ return { title: kind.title, message: parts.join(" "), hint };
66
+ }
@@ -0,0 +1,141 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import {
6
+ MailFilterRule,
7
+ createMailFilterRule,
8
+ deleteMailFilterRule,
9
+ listMailFilterRules,
10
+ updateMailFilterRule,
11
+ } from "@rapidmx/react-shared/mail/mailFilterRulesApi.js";
12
+
13
+ /**
14
+ * "Block sender" and "Never block sender", expressed as the mailbox's own mail filter rules - the server has no blocked-senders list.
15
+ * A rule's "From contains" is a case-insensitive substring match on the From header (restapi's `matchesConditions()`), which is the
16
+ * closest thing there is to "from equals": it also matches a longer address that ends in this one (`joann@x.com` for `ann@x.com`).
17
+ *
18
+ * - **Block** is `From contains <address>` -> move to the mailbox's Junk Email, stop processing more rules, ahead of every other rule
19
+ * (a sequence below all of them), so nothing else files the sender's mail first.
20
+ * - **Never block** is `From contains <address>` -> move to the Inbox, stop processing, likewise first. It keeps the sender's mail out of
21
+ * the reader's own blocking and filing rules. It cannot keep it out of Junk when the spam filter sends it there: mail the spam filter
22
+ * has judged junk skips every rule (restapi's `ScanQueueJob.deliverMessage()`).
23
+ *
24
+ * Rules are found by what they do, not by their name, so one the reader renamed or made by hand is still the rule for that sender.
25
+ */
26
+
27
+ /** Every rule listing asks for up to this many, which is the most the mail server reads when it filters a delivery. */
28
+ const RULE_LIMIT = 500;
29
+
30
+ export const BLOCK_RULE_PREFIX = "Block ";
31
+ export const NEVER_BLOCK_RULE_PREFIX = "Never block ";
32
+
33
+ /** `addresses` trimmed, lowercased and without repeats, keeping only what has an `@`. */
34
+ export function normalizeAddresses(addresses: (string | undefined)[]): string[] {
35
+ return [...new Set(addresses.map((address) => address?.trim().toLowerCase() ?? "").filter((address) => address.includes("@")))];
36
+ }
37
+
38
+ /** Whether `rule` is "From contains ..." (every address of `addresses` among them, and nothing else) and moves to `folderUid` and stops. */
39
+ function isSenderRule(rule: MailFilterRule, addresses: string[], folderUid: string): boolean {
40
+ const conditions = rule.conditions as Record<string, unknown>;
41
+ const only = Object.keys(conditions).every((key) => key === "fromContains" || conditions[key] === undefined);
42
+ const from = (rule.conditions.fromContains ?? []).map((entry) => entry.toLowerCase());
43
+ return (
44
+ only &&
45
+ addresses.every((address) => from.includes(address)) &&
46
+ rule.stopProcessingRules &&
47
+ rule.actions.length === 1 &&
48
+ rule.actions[0].type === "move_to_folder" &&
49
+ rule.actions[0].folderUid === folderUid
50
+ );
51
+ }
52
+
53
+ /** What blocking a sender did: `created` the rule, found it `existing` (and on), or turned an existing one back on. */
54
+ export interface BlockResult {
55
+ outcome: "created" | "existing" | "enabled";
56
+ rule: MailFilterRule;
57
+ }
58
+
59
+ /** What "Never block" did: the block rules it took away, and the rule that keeps the sender in the Inbox (`created` now or found). */
60
+ export interface NeverBlockResult {
61
+ removed: MailFilterRule[];
62
+ outcome: "created" | "existing" | "enabled";
63
+ rule: MailFilterRule;
64
+ }
65
+
66
+ /** A sequence that puts a new rule ahead of every rule the mailbox has. */
67
+ function firstSequence(rules: MailFilterRule[]): number {
68
+ return Math.min(0, ...rules.map((rule) => rule.sequence)) - 1;
69
+ }
70
+
71
+ /** Finds the rule that does `folderUid` for `addresses`, makes one (named `${prefix}${addresses[0]}`) if there is none, and turns a found one on. */
72
+ async function ensureRule(
73
+ rules: MailFilterRule[],
74
+ mailboxUid: string,
75
+ addresses: string[],
76
+ folderUid: string,
77
+ prefix: string,
78
+ ): Promise<{ outcome: "created" | "existing" | "enabled"; rule: MailFilterRule }> {
79
+ const found = rules.find((rule) => isSenderRule(rule, addresses, folderUid));
80
+ if (found) {
81
+ if (found.enabled) {
82
+ return { outcome: "existing", rule: found };
83
+ }
84
+ // The whole rule, as the filters page saves one: the update replaces the record.
85
+ const { uid, version, name, sequence, stopProcessingRules, conditions, actions } = found;
86
+ return { outcome: "enabled", rule: await updateMailFilterRule({ uid, version, name, enabled: true, sequence, stopProcessingRules, conditions, actions }) };
87
+ }
88
+ const rule = await createMailFilterRule({
89
+ mailboxUid,
90
+ name: `${prefix}${addresses[0]}`,
91
+ sequence: firstSequence(rules),
92
+ stopProcessingRules: true,
93
+ conditions: { fromContains: addresses },
94
+ actions: [{ type: "move_to_folder", folderUid }],
95
+ });
96
+ return { outcome: "created", rule };
97
+ }
98
+
99
+ /** Takes away every rule that is `folderUid` for `addresses`. */
100
+ async function removeRules(rules: MailFilterRule[], addresses: string[], folderUid: string): Promise<MailFilterRule[]> {
101
+ const doomed = rules.filter((rule) => isSenderRule(rule, addresses, folderUid));
102
+ for (const rule of doomed) {
103
+ await deleteMailFilterRule(rule.uid, rule.version);
104
+ }
105
+ return doomed;
106
+ }
107
+
108
+ /**
109
+ * Blocks a sender: mail from `addresses` (its envelope sender and From header address, when they differ - a mailing list or a bulk sender
110
+ * usually has both) goes to `junkFolderUid` from now on. Idempotent: the rule is made once, and a rule that was turned off is turned on.
111
+ * A "Never block" rule for the same sender is taken away, since the two would fight.
112
+ */
113
+ export async function blockSender(mailboxUid: string, addresses: string[], junkFolderUid: string, inboxFolderUid: string): Promise<BlockResult> {
114
+ const rules = await listMailFilterRules(mailboxUid, { limit: RULE_LIMIT });
115
+ await removeRules(rules, addresses, inboxFolderUid);
116
+ return ensureRule(rules, mailboxUid, addresses, junkFolderUid, BLOCK_RULE_PREFIX);
117
+ }
118
+
119
+ /** Never blocks a sender: takes away the block rule for `addresses` and makes (once) the rule that keeps their mail in the Inbox. */
120
+ export async function neverBlockSender(
121
+ mailboxUid: string,
122
+ addresses: string[],
123
+ junkFolderUid: string,
124
+ inboxFolderUid: string,
125
+ ): Promise<NeverBlockResult> {
126
+ const rules = await listMailFilterRules(mailboxUid, { limit: RULE_LIMIT });
127
+ const removed = await removeRules(rules, addresses, junkFolderUid);
128
+ const kept = await ensureRule(
129
+ rules.filter((rule) => !removed.includes(rule)),
130
+ mailboxUid,
131
+ addresses,
132
+ inboxFolderUid,
133
+ NEVER_BLOCK_RULE_PREFIX,
134
+ );
135
+ return { removed, ...kept };
136
+ }
137
+
138
+ /** Takes back a rule this module made (the notification's Undo). */
139
+ export function removeSenderRule(rule: MailFilterRule): Promise<void> {
140
+ return deleteMailFilterRule(rule.uid, rule.version);
141
+ }
@@ -0,0 +1,60 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import { useEffect, useState } from "react";
6
+ import type { Mailbox } from "@rapidmx/react-shared/mail/mailApi.js";
7
+ import { getMyMailboxAccess } from "@rapidmx/react-shared/mail/mailboxAccessApi.js";
8
+
9
+ /** What the server said about the caller's update access to a mailbox, remembered per mailbox for the page load. */
10
+ const answers = new Map<string, Promise<boolean | undefined>>();
11
+
12
+ /** Forgets every remembered answer - for the tests, and anything that changes the caller's access mid-session. */
13
+ export function clearMailboxUpdateAccessCache(): void {
14
+ answers.clear();
15
+ }
16
+
17
+ /** Whether the caller may change things in `mailboxUid` (move, mark and flag its messages, add its filters): the server's own ACL check. Never rejects; `undefined` when it could not be asked (which is not cached). */
18
+ function fetchUpdateAccess(mailboxUid: string): Promise<boolean | undefined> {
19
+ let answer = answers.get(mailboxUid);
20
+ if (!answer) {
21
+ answer = getMyMailboxAccess(mailboxUid).then(
22
+ (access) => access.canUpdate,
23
+ () => {
24
+ answers.delete(mailboxUid);
25
+ return undefined;
26
+ },
27
+ );
28
+ answers.set(mailboxUid, answer);
29
+ }
30
+ return answer;
31
+ }
32
+
33
+ /**
34
+ * Whether the reader may change the messages of `mailbox`: `false` only for a mailbox shared with them (`accessRole: "delegate"`) that
35
+ * the server says they may not update - a view-only share. Everything else is `true` from the first render: the reader's own mailbox
36
+ * needs no request, and a mailbox that is unknown (the shell has not listed it), or whose access could not be read, is treated as
37
+ * writable - the server still refuses what is not allowed, and hiding a usable action over a failed lookup is worse than offering one
38
+ * that then says why it failed.
39
+ */
40
+ export function useMailboxUpdateAccess(mailbox: Mailbox | undefined): boolean {
41
+ const uid = mailbox?.uid;
42
+ const delegated = mailbox?.accessRole === "delegate";
43
+ const [writable, setWritable] = useState(true);
44
+ useEffect(() => {
45
+ setWritable(true);
46
+ if (!uid || !delegated) {
47
+ return;
48
+ }
49
+ let cancelled = false;
50
+ void fetchUpdateAccess(uid).then((canUpdate) => {
51
+ if (!cancelled && canUpdate === false) {
52
+ setWritable(false);
53
+ }
54
+ });
55
+ return () => {
56
+ cancelled = true;
57
+ };
58
+ }, [uid, delegated]);
59
+ return writable;
60
+ }
@@ -0,0 +1,160 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import React, { ReactElement, useRef, useState } from "react";
6
+ import type { Message } from "@rapidmx/react-shared/mail/mailApi.js";
7
+ import PermanentDeleteDialog from "../components/mail/PermanentDeleteDialog.js";
8
+ import { useMailShell } from "../components/mail/layout/MailShell.js";
9
+ import { notifyApiError } from "../notifications/apiErrors.js";
10
+ import { removeLocalEntity } from "../search/localIndexRpcClient.js";
11
+ import {
12
+ EmptyFolderOutcome,
13
+ PurgeOutcome,
14
+ messageCount,
15
+ notifyFolderEmptied,
16
+ notifyPurged,
17
+ purgeFolder,
18
+ purgeMessages,
19
+ } from "./permanentDelete.js";
20
+
21
+ /** The folder "Empty folder" is about. */
22
+ export interface EmptiableFolder {
23
+ uid: string;
24
+ name: string;
25
+ }
26
+
27
+ export interface PermanentDelete {
28
+ /**
29
+ * Asks, then permanently deletes `messages` (Delete in Deleted Items - the Delete menu item of a message card calls this too). Resolves
30
+ * with what came of it once the dialog is gone, and everything a delete has to tell has been told: the folder badges follow, the local
31
+ * search index drops the messages, and a notification says "N messages permanently deleted" or which could not be and why. Resolves
32
+ * `null` - and sends nothing - when the reader cancels, when `messages` is empty, or while another request is already open.
33
+ */
34
+ requestPermanentDelete: (messages: Message[]) => Promise<PurgeOutcome | null>;
35
+ /**
36
+ * Asks, then permanently deletes everything in `folder`. `count` is how many messages it holds when that is known (the dialog and the
37
+ * notification then say so). Resolves as `requestPermanentDelete()` does; a request that failed outright (the server is down) has said so and resolves an
38
+ * outcome with nothing deleted, so the caller reloads what it lists.
39
+ */
40
+ requestEmptyFolder: (folder: EmptiableFolder, count?: number) => Promise<EmptyFolderOutcome | null>;
41
+ /** A request is open (the dialog is up, or the delete is on the wire): what should hold every other action of the list meanwhile. */
42
+ busy: boolean;
43
+ /** The confirmation dialog - render it once, anywhere (it is a portal). */
44
+ dialog: ReactElement;
45
+ }
46
+
47
+ type Request = { kind: "messages"; messages: Message[] } | { kind: "folder"; folder: EmptiableFolder; count?: number };
48
+
49
+ interface Pending {
50
+ request: Request;
51
+ resolve: (outcome: never) => void;
52
+ }
53
+
54
+ /**
55
+ * The one place a permanent delete is confirmed and carried out - for the mail list (the selection bar, the Delete key, Empty folder) and
56
+ * for a message card's own Delete, so all of them ask the same question, delete the same way and report the same way. Call it inside the
57
+ * mail shell (it keeps that shell's folder badges right).
58
+ *
59
+ * The reader always confirms: nothing is remembered between requests.
60
+ */
61
+ export function usePermanentDelete(): PermanentDelete {
62
+ const { trackMessageChange, refreshFolderCounts } = useMailShell();
63
+ const [pending, setPending] = useState<Pending | null>(null);
64
+ const [running, setRunning] = useState(false);
65
+ // Set at once (state is a render later), so a key pressed twice does not open two dialogs.
66
+ const pendingRef = useRef<Pending | null>(null);
67
+
68
+ function ask<T>(request: Request): Promise<T | null> {
69
+ if (pendingRef.current) {
70
+ return Promise.resolve(null);
71
+ }
72
+ return new Promise<T | null>((resolve) => {
73
+ const next: Pending = { request, resolve };
74
+ pendingRef.current = next;
75
+ setPending(next);
76
+ });
77
+ }
78
+
79
+ function requestPermanentDelete(messages: Message[]): Promise<PurgeOutcome | null> {
80
+ return messages.length === 0 ? Promise.resolve(null) : ask<PurgeOutcome>({ kind: "messages", messages });
81
+ }
82
+
83
+ function requestEmptyFolder(folder: EmptiableFolder, count?: number): Promise<EmptyFolderOutcome | null> {
84
+ return ask<EmptyFolderOutcome>({ kind: "folder", folder, count });
85
+ }
86
+
87
+ /** Closes the dialog and hands the caller what came of it. */
88
+ function finish(outcome: PurgeOutcome | null) {
89
+ const current = pendingRef.current!;
90
+ pendingRef.current = null;
91
+ setPending(null);
92
+ setRunning(false);
93
+ current.resolve(outcome as never);
94
+ }
95
+
96
+ /** What every delete tells the rest of the page: the badges (each message is one fewer in its folder) and the local search index. */
97
+ function afterDeleted(deleted: Message[]) {
98
+ for (const message of deleted) {
99
+ trackMessageChange(message, null).settle();
100
+ void removeLocalEntity(message.mailboxUid, message.uid);
101
+ }
102
+ }
103
+
104
+ async function confirm() {
105
+ const { request } = pendingRef.current!;
106
+ setRunning(true);
107
+ if (request.kind === "messages") {
108
+ const outcome = await purgeMessages(request.messages);
109
+ afterDeleted(outcome.deleted);
110
+ notifyPurged(outcome);
111
+ finish(outcome);
112
+ return;
113
+ }
114
+ let outcome: EmptyFolderOutcome;
115
+ try {
116
+ outcome = await purgeFolder(request.folder.uid);
117
+ } catch (err) {
118
+ notifyApiError(err, `Couldn't empty ${request.folder.name}`);
119
+ // Part of it may have gone before the failure: the caller reloads rather than assume nothing did.
120
+ outcome = { emptied: false, deleted: [], failed: [] };
121
+ }
122
+ afterDeleted(outcome.deleted);
123
+ // The whole-folder request does not say which messages went, so the counts are read back rather than adjusted.
124
+ refreshFolderCounts();
125
+ if (outcome.emptied || outcome.deleted.length > 0 || outcome.failed.length > 0) {
126
+ notifyFolderEmptied(request.folder.name, outcome, request.count);
127
+ }
128
+ finish(outcome);
129
+ }
130
+
131
+ function cancel() {
132
+ finish(null);
133
+ }
134
+
135
+ const request = pending?.request;
136
+ const folderRequest = request?.kind === "folder" ? request : undefined;
137
+ const dialog = (
138
+ <PermanentDeleteDialog
139
+ open={pending !== null}
140
+ title={folderRequest ? `Empty ${folderRequest.folder.name}` : "Delete permanently"}
141
+ message={
142
+ folderRequest
143
+ ? `Permanently delete ${
144
+ folderRequest.count === undefined
145
+ ? "all items"
146
+ : folderRequest.count === 1
147
+ ? "the only item"
148
+ : `all ${folderRequest.count} items`
149
+ } in ${folderRequest.folder.name}? This can't be undone.`
150
+ : `Permanently delete ${messageCount(request?.kind === "messages" ? request.messages.length : 0)}? This can't be undone.`
151
+ }
152
+ confirmLabel={folderRequest ? "Delete all permanently" : "Delete permanently"}
153
+ busy={running}
154
+ onConfirm={() => void confirm()}
155
+ onCancel={cancel}
156
+ />
157
+ );
158
+
159
+ return { requestPermanentDelete, requestEmptyFolder, busy: pending !== null, dialog };
160
+ }
@@ -5,7 +5,7 @@
5
5
  import React, { PropsWithChildren, createContext, useContext, useLayoutEffect } from "react";
6
6
 
7
7
  /**
8
- * What the persistent app frame (`AppRouter`'s one mounted `AppShell` chrome) offers to what is rendered inside it. `null`
8
+ * What the persistent app frame (the webmail's router shell, `apps/www/_shell.tsx`, whose one mounted `AppChrome` never unmounts) offers to what is rendered inside it. `null`
9
9
  * outside a frame - a page not shown by the router (an admin page, a plugin page, a test) renders its own chrome.
10
10
  */
11
11
  export interface AppFrameContextValue {