@open-workspace/email 0.4.1 → 0.5.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.
- package/README.md +9 -4
- package/alchemy/index.ts +130 -2
- package/drizzle/mailbox/0002_good_komodo.sql +2 -0
- package/drizzle/mailbox/0003_after_0_4_2.sql +180 -0
- package/drizzle/mailbox/meta/0002_snapshot.json +1017 -0
- package/drizzle/mailbox/meta/0003_snapshot.json +1507 -0
- package/drizzle/mailbox/meta/_journal.json +14 -0
- package/drizzle/mailbox/migrations.js +5 -1
- package/migrations/0001_overrated_ricochet.sql +2 -0
- package/migrations/0002_after_0_4_2.sql +35 -0
- package/migrations/meta/0001_snapshot.json +564 -0
- package/migrations/meta/0002_snapshot.json +807 -0
- package/migrations/meta/_journal.json +14 -0
- package/package.json +23 -7
- package/shared/attachment-preview.ts +18 -8
- package/shared/folder-order.ts +31 -6
- package/shared/mail-headers.ts +3 -3
- package/shared/mail-html.ts +25 -0
- package/shared/mail-import.ts +0 -7
- package/shared/mail-received.ts +4 -4
- package/shared/mail-rule-actions.ts +47 -0
- package/shared/mail.ts +70 -4
- package/shared/office-preview.ts +0 -4
- package/shared/pdfjs-assets.ts +1 -3
- package/shared/rich-content.ts +35 -0
- package/shared/signature.ts +15 -0
- package/src/admin/address-auto-reply.tsx +49 -0
- package/src/admin/blocked-senders.tsx +86 -66
- package/src/admin/forward-destinations.tsx +140 -0
- package/src/admin/mail-archive.tsx +134 -0
- package/src/admin/team-signature.tsx +90 -0
- package/src/client.tsx +130 -16
- package/src/mail/attachment-preview-dialog.tsx +13 -5
- package/src/mail/auto-reply-banner.tsx +61 -0
- package/src/mail/blocked-senders.tsx +124 -91
- package/src/mail/compose-window-chrome.tsx +20 -8
- package/src/mail/compose-window.tsx +387 -365
- package/src/mail/composer-asset-bookmarks.ts +47 -12
- package/src/mail/composer-attachment-list.tsx +42 -17
- package/src/mail/composer-editor-document.ts +54 -10
- package/src/mail/composer-editor.tsx +44 -44
- package/src/mail/composer-link-text.ts +42 -0
- package/src/mail/composer-recipient-fields.tsx +25 -16
- package/src/mail/composer-recipients.ts +62 -16
- package/src/mail/composer-session.ts +107 -23
- package/src/mail/composer-toolbar.tsx +15 -1
- package/src/mail/composer-upload-client.ts +29 -1
- package/src/mail/composer-upload-progress.ts +2 -2
- package/src/mail/conversation-actions-model.ts +56 -0
- package/src/mail/conversation-list.tsx +263 -128
- package/src/mail/conversation-loading-skeleton.tsx +165 -90
- package/src/mail/conversation-message.tsx +257 -102
- package/src/mail/conversation-order.ts +12 -0
- package/src/mail/conversation-reply.tsx +313 -189
- package/src/mail/conversation-selection-toolbar.tsx +188 -143
- package/src/mail/conversation-view.tsx +320 -85
- package/src/mail/delivery-indicator.tsx +33 -12
- package/src/mail/draft-attachments.ts +194 -0
- package/src/mail/email-html-body.tsx +97 -53
- package/src/mail/folder-cleanup-bar.tsx +193 -0
- package/src/mail/folder-glyph.tsx +5 -0
- package/src/mail/folder-manager.tsx +71 -38
- package/src/mail/mail-app-bar.tsx +15 -3
- package/src/mail/mail-dock.tsx +19 -3
- package/src/mail/mail-focus.ts +48 -0
- package/src/mail/mail-folders.ts +14 -2
- package/src/mail/mail-layout.css +20 -0
- package/src/mail/mail-mailbox-sheet.tsx +22 -69
- package/src/mail/mail-nav-rail.tsx +7 -4
- package/src/mail/mail-nav.tsx +66 -46
- package/src/mail/mail-prefetch.ts +30 -9
- package/src/mail/mail-primitives.tsx +6 -4
- package/src/mail/mail-queries.ts +122 -20
- package/src/mail/mail-query-cache.ts +1085 -173
- package/src/mail/mail-search-params.ts +35 -0
- package/src/mail/mail-shell.tsx +32 -9
- package/src/mail/mailbox-ai-settings.tsx +56 -42
- package/src/mail/mailbox-realtime.tsx +4 -12
- package/src/mail/mailbox-rules.tsx +898 -0
- package/src/mail/message-actions.tsx +38 -26
- package/src/mail/message-attachments.tsx +20 -12
- package/src/mail/message-body.ts +53 -0
- package/src/mail/message-format.ts +8 -2
- package/src/mail/message-header.tsx +3 -1
- package/src/mail/message-translation.tsx +34 -67
- package/src/mail/original-message-sheet.tsx +63 -50
- package/src/mail/original-message.ts +6 -6
- package/src/mail/pane-splitter.tsx +3 -3
- package/src/mail/pdf-preview.tsx +70 -62
- package/src/mail/plain-message-text.tsx +28 -0
- package/src/mail/print-message.ts +31 -36
- package/src/mail/reader-pane.tsx +134 -102
- package/src/mail/recipient-combobox.tsx +52 -29
- package/src/mail/recipient-field-row.tsx +3 -0
- package/src/mail/rich-content.ts +128 -0
- package/src/mail/sanitize-email-html.ts +57 -33
- package/src/mail/sender-actions.tsx +49 -39
- package/src/mail/sender-authentication.tsx +1 -1
- package/src/mail/sender-dialogs.tsx +67 -43
- package/src/mail/sender-security.tsx +9 -10
- package/src/mail/signature.ts +43 -0
- package/src/mail/translation-html.ts +3 -3
- package/src/mail/types.ts +12 -0
- package/src/mail/use-composer-attachment-preflight.ts +23 -60
- package/src/mail/use-composer-core.ts +286 -0
- package/src/mail/use-composer-navigation.ts +120 -0
- package/src/mail/use-composer-submission.ts +154 -19
- package/src/mail/use-conversation-actions.ts +292 -0
- package/src/mail/use-conversation-position.ts +51 -0
- package/src/mail/use-conversation-selection.ts +192 -89
- package/src/mail/use-draft-autosave.ts +394 -0
- package/src/mail/use-drafts.ts +194 -0
- package/src/mail/use-mail-controller.ts +754 -213
- package/src/mail/use-mail-data.ts +210 -100
- package/src/mail/use-mail-safety.ts +19 -38
- package/src/mail/use-mail-send.ts +18 -6
- package/src/mail/use-pdf-translation.ts +1 -1
- package/src/mail/use-reply-cc.ts +61 -0
- package/src/mail/use-visible-message-read.ts +128 -64
- package/src/pwa/push-key.ts +18 -0
- package/src/pwa/push-subscription.ts +88 -26
- package/src/settings/auto-reply-editor.tsx +454 -0
- package/src/settings/auto-reply-page.tsx +59 -0
- package/src/settings/mail-apps-page.tsx +52 -43
- package/src/settings/notifications-page.tsx +82 -67
- package/src/settings/rich-content-editor.tsx +182 -0
- package/src/settings/settings-queries.ts +57 -0
- package/src/settings/signature-editor.tsx +142 -0
- package/src/settings/signature-page.tsx +70 -0
- package/worker/admin/blocked-sender-routes.ts +10 -16
- package/worker/backups/eml.ts +185 -0
- package/worker/backups/file-parts.ts +140 -0
- package/worker/backups/mail-backup.ts +644 -0
- package/worker/backups/settings-backup.ts +866 -0
- package/worker/backups/stream-eml.ts +73 -0
- package/worker/db/schema.ts +98 -2
- package/worker/jmap/attachment-blobs.ts +113 -0
- package/worker/jmap/blobs.ts +162 -0
- package/worker/jmap/draft-content.ts +42 -0
- package/worker/jmap/drafts.ts +70 -0
- package/worker/jmap/email-body.ts +152 -0
- package/worker/jmap/email-methods.ts +1223 -0
- package/worker/jmap/eventsource.ts +9 -8
- package/worker/jmap/import-methods.ts +205 -0
- package/worker/jmap/mailbox-methods.ts +187 -0
- package/worker/jmap/method-core.ts +379 -0
- package/worker/jmap/methods.ts +108 -1815
- package/worker/jmap/push-subscription-methods.ts +373 -0
- package/worker/jmap/push-types.ts +46 -2
- package/worker/jmap/push.ts +24 -31
- package/worker/jmap/routes.ts +144 -153
- package/worker/jmap/submission-methods.ts +395 -0
- package/worker/mail/access.ts +35 -12
- package/worker/mail/ai-classification.ts +2 -2
- package/worker/mail/archive-object.ts +96 -0
- package/worker/mail/archive-routes.ts +35 -0
- package/worker/mail/archive.ts +682 -0
- package/worker/mail/auth-headers.ts +48 -40
- package/worker/mail/auto-reply-routes.ts +255 -0
- package/worker/mail/auto-reply.ts +243 -0
- package/worker/mail/bimi.ts +53 -36
- package/worker/mail/bootstrap.ts +11 -3
- package/worker/mail/capabilities.ts +69 -0
- package/worker/mail/classification-signals.ts +1 -1
- package/worker/mail/confusables-data.ts +9 -0
- package/worker/mail/conversation-cursor.ts +6 -15
- package/worker/mail/delivery-events.ts +9 -7
- package/worker/mail/delivery-facts.ts +1 -1
- package/worker/mail/demo-routes.ts +3 -3
- package/worker/mail/doh.ts +3 -3
- package/worker/mail/download-links.ts +153 -0
- package/worker/mail/downloads.ts +2 -6
- package/worker/mail/draft-routes.ts +473 -0
- package/worker/mail/draft-sender.ts +54 -0
- package/worker/mail/edge-cache.ts +41 -55
- package/worker/mail/email-routing.ts +123 -0
- package/worker/mail/forward-destinations.ts +114 -0
- package/worker/mail/forward-downloads.ts +115 -0
- package/worker/mail/forward-html.ts +85 -0
- package/worker/mail/header-metadata.ts +2 -5
- package/worker/mail/impersonation.ts +102 -101
- package/worker/mail/import-routes.ts +29 -82
- package/worker/mail/import.ts +130 -0
- package/worker/mail/inbound-delivery.ts +6 -5
- package/worker/mail/inbound.ts +58 -28
- package/worker/mail/ip-intel.ts +8 -17
- package/worker/mail/isolate-cache.ts +1 -1
- package/worker/mail/mailbox-deletion.ts +33 -12
- package/worker/mail/mailbox-directory.ts +39 -65
- package/worker/mail/mailing-list.ts +29 -58
- package/worker/mail/message-security.ts +3 -3
- package/worker/mail/message-view.ts +12 -10
- package/worker/mail/office-conversion.ts +3 -5
- package/worker/mail/office-preview-container.ts +3 -8
- package/worker/mail/outbound-content.ts +139 -65
- package/worker/mail/outbound-delivery.ts +20 -17
- package/worker/mail/outbound-service.ts +34 -9
- package/worker/mail/outbound.ts +146 -75
- package/worker/mail/outgoing-context.ts +60 -30
- package/worker/mail/participants.ts +10 -15
- package/worker/mail/plain-body.ts +39 -0
- package/worker/mail/push-endpoint.ts +17 -0
- package/worker/mail/push-notifications.ts +87 -43
- package/worker/mail/quote-parser.ts +107 -25
- package/worker/mail/r2-presigned-urls.ts +7 -0
- package/worker/mail/receive.ts +146 -39
- package/worker/mail/recipients.ts +1 -1
- package/worker/mail/remote-proxy.ts +3 -3
- package/worker/mail/repeat.ts +1 -1
- package/worker/mail/reply-plan.ts +124 -26
- package/worker/mail/rfc.ts +15 -7
- package/worker/mail/rich-content.ts +207 -0
- package/worker/mail/routes.ts +696 -304
- package/worker/mail/routing.ts +274 -0
- package/worker/mail/rules.ts +230 -0
- package/worker/mail/safety-routes.ts +88 -80
- package/worker/mail/schemas.ts +222 -31
- package/worker/mail/search.ts +25 -2
- package/worker/mail/security-settings.ts +4 -10
- package/worker/mail/send-message.ts +238 -0
- package/worker/mail/sender-intel.ts +12 -20
- package/worker/mail/signature-routes.ts +201 -0
- package/worker/mail/signatures.ts +195 -0
- package/worker/mail/spamhaus.ts +28 -16
- package/worker/mail/storage-keys.ts +35 -0
- package/worker/mail/unsubscribe.ts +19 -41
- package/worker/mail/uploads.ts +193 -80
- package/worker/mail/webhook-source.ts +3 -2
- package/worker/mail/workspace-safety.ts +194 -60
- package/worker/mailbox/demo.ts +13 -15
- package/worker/mailbox/email-index.ts +92 -13
- package/worker/mailbox/folder-model.ts +0 -20
- package/worker/mailbox/import-placement.ts +21 -36
- package/worker/mailbox/inbound-decision.ts +114 -0
- package/worker/mailbox/inbox-counts.ts +45 -25
- package/worker/mailbox/index.ts +843 -2888
- package/worker/mailbox/jmap-change-log.ts +195 -0
- package/worker/mailbox/jmap-email-rows.ts +186 -0
- package/worker/mailbox/jmap-mailboxes.ts +116 -0
- package/worker/mailbox/jmap-placement.ts +139 -0
- package/worker/mailbox/jmap-query-filter.ts +231 -0
- package/worker/mailbox/jmap-store.ts +167 -299
- package/worker/mailbox/mailbox-auto-reply.ts +301 -0
- package/worker/mailbox/mailbox-backup.ts +538 -0
- package/worker/mailbox/mailbox-drafts.ts +417 -0
- package/worker/mailbox/mailbox-folders.ts +242 -0
- package/worker/mailbox/mailbox-import.ts +450 -0
- package/worker/mailbox/mailbox-inbound.ts +934 -0
- package/worker/mailbox/mailbox-jmap.ts +294 -0
- package/worker/mailbox/mailbox-outbound.ts +413 -0
- package/worker/mailbox/mailbox-rules.ts +336 -0
- package/worker/mailbox/mailbox-senders.ts +294 -0
- package/worker/mailbox/mailbox-storage.ts +438 -0
- package/worker/mailbox/mailbox-views.ts +891 -0
- package/worker/mailbox/model.ts +1 -0
- package/worker/mailbox/office-preview-jobs.ts +59 -47
- package/worker/mailbox/placement.ts +933 -0
- package/worker/mailbox/restore-thread.ts +52 -0
- package/worker/mailbox/retention.ts +36 -0
- package/worker/mailbox/schema.ts +211 -1
- package/worker/mailbox/senders.ts +216 -178
- package/worker/mailbox/spam-undo-filing.ts +138 -0
- package/worker/mailbox/spam-undo.ts +240 -0
- package/worker/mailbox/support.ts +416 -0
- package/worker/mcp/mail-action-tools.ts +156 -0
- package/worker/mcp/mail-compose-tools.ts +8 -2
- package/worker/mcp/mail-safety-tools.ts +4 -4
- package/worker/module.ts +23 -2
- package/src/mail/use-compose-submission.ts +0 -208
- package/src/mail/use-reply-submission.ts +0 -114
- package/worker/mail/capped-body.ts +0 -36
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Button,
|
|
3
3
|
Checkbox,
|
|
4
|
+
DelayedFallback,
|
|
4
5
|
Input,
|
|
5
6
|
Skeleton,
|
|
7
|
+
queryErrorBlocksContent,
|
|
6
8
|
responseJson,
|
|
7
9
|
adminPanelClass,
|
|
8
10
|
AdminPanelBody,
|
|
9
11
|
AdminPanelHeader,
|
|
12
|
+
AdminQueryError,
|
|
10
13
|
} from "@open-workspace/core/ui";
|
|
11
14
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
12
15
|
import { Building2, LoaderCircle, ShieldBan } from "lucide-react";
|
|
13
|
-
import {
|
|
14
|
-
import type { FormEvent } from "react";
|
|
16
|
+
import { useController, useForm, useWatch } from "react-hook-form";
|
|
15
17
|
import { toast } from "sonner";
|
|
16
18
|
|
|
17
19
|
import { normalizeBlockPattern } from "../../shared/mail-feedback";
|
|
18
20
|
import { mailApi } from "../lib/mail-api";
|
|
21
|
+
import { adminBlockedSendersQuery } from "../settings/settings-queries";
|
|
19
22
|
|
|
20
|
-
const BLOCKED_SENDERS_KEY =
|
|
23
|
+
const BLOCKED_SENDERS_KEY = adminBlockedSendersQuery.queryKey;
|
|
21
24
|
|
|
22
25
|
function formatDate(value: string | Date) {
|
|
23
26
|
return new Intl.DateTimeFormat("en", { dateStyle: "medium" }).format(
|
|
@@ -35,11 +38,7 @@ function useWorkspaceBlocks() {
|
|
|
35
38
|
const invalidate = () =>
|
|
36
39
|
client.invalidateQueries({ queryKey: BLOCKED_SENDERS_KEY });
|
|
37
40
|
|
|
38
|
-
const list = useQuery(
|
|
39
|
-
queryKey: BLOCKED_SENDERS_KEY,
|
|
40
|
-
queryFn: async () =>
|
|
41
|
-
responseJson(await mailApi.api.admin["blocked-senders"].$get()),
|
|
42
|
-
});
|
|
41
|
+
const list = useQuery(adminBlockedSendersQuery);
|
|
43
42
|
|
|
44
43
|
const block = useMutation({
|
|
45
44
|
mutationFn: async (input: { pattern: string; moveExisting: boolean }) =>
|
|
@@ -85,17 +84,27 @@ function useWorkspaceBlocks() {
|
|
|
85
84
|
/** Administration → Blocked senders: addresses and domains blocked for every mailbox. */
|
|
86
85
|
export function BlockedSenders() {
|
|
87
86
|
const { list, block, unblock } = useWorkspaceBlocks();
|
|
88
|
-
const [value, setValue] = useState("");
|
|
89
|
-
const [moveExisting, setMoveExisting] = useState(true);
|
|
90
|
-
const pattern = normalizeBlockPattern(value);
|
|
91
|
-
const items = list.data?.blockedSenders ?? [];
|
|
92
87
|
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
const { control, handleSubmit, register, resetField } = useForm({
|
|
89
|
+
defaultValues: { value: "", moveExisting: true },
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const pattern = normalizeBlockPattern(useWatch({ control, name: "value" }));
|
|
93
|
+
|
|
94
|
+
const moveExistingField = useController({
|
|
95
|
+
control,
|
|
96
|
+
name: "moveExisting",
|
|
97
|
+
}).field;
|
|
98
|
+
|
|
99
|
+
const items = list.data?.blockedSenders ?? [];
|
|
95
100
|
|
|
101
|
+
const submit = handleSubmit(({ moveExisting }) => {
|
|
96
102
|
if (!pattern) return;
|
|
97
|
-
block.mutate(
|
|
98
|
-
|
|
103
|
+
block.mutate(
|
|
104
|
+
{ pattern, moveExisting },
|
|
105
|
+
{ onSuccess: () => resetField("value") }
|
|
106
|
+
);
|
|
107
|
+
});
|
|
99
108
|
|
|
100
109
|
return (
|
|
101
110
|
<div className="max-w-4xl">
|
|
@@ -111,8 +120,7 @@ export function BlockedSenders() {
|
|
|
111
120
|
<Input
|
|
112
121
|
aria-label="Address or domain to block for everyone"
|
|
113
122
|
placeholder="name@example.com or example.com"
|
|
114
|
-
|
|
115
|
-
onChange={(event) => setValue(event.target.value)}
|
|
123
|
+
{...register("value")}
|
|
116
124
|
/>
|
|
117
125
|
<Button
|
|
118
126
|
type="submit"
|
|
@@ -129,59 +137,71 @@ export function BlockedSenders() {
|
|
|
129
137
|
</div>
|
|
130
138
|
<label className="text-muted-foreground flex items-center gap-2 text-xs">
|
|
131
139
|
<Checkbox
|
|
132
|
-
checked={
|
|
133
|
-
onCheckedChange={(checked) =>
|
|
140
|
+
checked={moveExistingField.value}
|
|
141
|
+
onCheckedChange={(checked) =>
|
|
142
|
+
moveExistingField.onChange(checked === true)
|
|
143
|
+
}
|
|
134
144
|
/>
|
|
135
145
|
Also move mail already delivered from it to Spam
|
|
136
146
|
</label>
|
|
137
147
|
</form>
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
<
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
<
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
</span>
|
|
162
|
-
<span className="text-muted-foreground block truncate text-xs">
|
|
163
|
-
{item.scope === "domain" ? "Whole domain" : "Address"}
|
|
164
|
-
{" · "}blocked {formatDate(item.createdAt)}
|
|
165
|
-
{item.createdByName ? ` by ${item.createdByName}` : ""}
|
|
166
|
-
</span>
|
|
167
|
-
</span>
|
|
168
|
-
<Button
|
|
169
|
-
size="sm"
|
|
170
|
-
variant="ghost"
|
|
171
|
-
aria-label={`Unblock ${item.pattern}`}
|
|
172
|
-
disabled={unblock.isPending}
|
|
173
|
-
onClick={() => unblock.mutate(item.pattern)}
|
|
148
|
+
<DelayedFallback
|
|
149
|
+
pending={list.isPending}
|
|
150
|
+
fallback={
|
|
151
|
+
<div className="space-y-2">
|
|
152
|
+
<Skeleton className="h-12" />
|
|
153
|
+
<Skeleton className="h-12" />
|
|
154
|
+
</div>
|
|
155
|
+
}
|
|
156
|
+
>
|
|
157
|
+
{queryErrorBlocksContent(list) ? (
|
|
158
|
+
<AdminQueryError
|
|
159
|
+
query={list}
|
|
160
|
+
message="The blocked senders couldn't be loaded."
|
|
161
|
+
/>
|
|
162
|
+
) : items.length ? (
|
|
163
|
+
<ul
|
|
164
|
+
aria-label="Senders blocked for everyone"
|
|
165
|
+
className="divide-border/70 border-border divide-y rounded-lg border"
|
|
166
|
+
>
|
|
167
|
+
{items.map((item) => (
|
|
168
|
+
<li
|
|
169
|
+
key={item.pattern}
|
|
170
|
+
className="flex items-center gap-3 px-3.5 py-2.5"
|
|
174
171
|
>
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
172
|
+
{item.scope === "domain" ? (
|
|
173
|
+
<Building2 className="text-muted-foreground size-4 shrink-0" />
|
|
174
|
+
) : (
|
|
175
|
+
<ShieldBan className="text-muted-foreground size-4 shrink-0" />
|
|
176
|
+
)}
|
|
177
|
+
<span className="min-w-0 flex-1">
|
|
178
|
+
<span className="block truncate text-sm font-medium">
|
|
179
|
+
{item.pattern}
|
|
180
|
+
</span>
|
|
181
|
+
<span className="text-muted-foreground block truncate text-xs">
|
|
182
|
+
{item.scope === "domain" ? "Whole domain" : "Address"}
|
|
183
|
+
{" · "}blocked {formatDate(item.createdAt)}
|
|
184
|
+
{item.createdByName ? ` by ${item.createdByName}` : ""}
|
|
185
|
+
</span>
|
|
186
|
+
</span>
|
|
187
|
+
<Button
|
|
188
|
+
size="sm"
|
|
189
|
+
variant="ghost"
|
|
190
|
+
aria-label={`Unblock ${item.pattern}`}
|
|
191
|
+
disabled={unblock.isPending}
|
|
192
|
+
onClick={() => unblock.mutate(item.pattern)}
|
|
193
|
+
>
|
|
194
|
+
Unblock
|
|
195
|
+
</Button>
|
|
196
|
+
</li>
|
|
197
|
+
))}
|
|
198
|
+
</ul>
|
|
199
|
+
) : (
|
|
200
|
+
<p className="text-muted-foreground py-6 text-center text-sm">
|
|
201
|
+
No senders are blocked for everyone.
|
|
202
|
+
</p>
|
|
203
|
+
)}
|
|
204
|
+
</DelayedFallback>
|
|
185
205
|
</AdminPanelBody>
|
|
186
206
|
</div>
|
|
187
207
|
</div>
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Badge,
|
|
3
|
+
Skeleton,
|
|
4
|
+
responseJson,
|
|
5
|
+
useAddressSection,
|
|
6
|
+
} from "@open-workspace/core/ui";
|
|
7
|
+
import type { TeamAddress, UserAddress } from "@open-workspace/core/ui";
|
|
8
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
9
|
+
|
|
10
|
+
import { mailApi } from "../lib/mail-api";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A forward's destinations in the address editor (People or Teams), each
|
|
14
|
+
* Confirmed or Waiting for confirmation: Cloudflare forwards to one only
|
|
15
|
+
* after it followed the link in Cloudflare's email. Saving the address adds
|
|
16
|
+
* new destinations; one that Email Routing still lacks (adding it failed)
|
|
17
|
+
* makes this section ask "Save address" to add it again, and shows why it
|
|
18
|
+
* failed (worker/mail/forward-destinations.ts).
|
|
19
|
+
*/
|
|
20
|
+
export function ForwardDestinations({
|
|
21
|
+
address,
|
|
22
|
+
}: {
|
|
23
|
+
address: TeamAddress | UserAddress;
|
|
24
|
+
}) {
|
|
25
|
+
if (address.delivery !== "forward" || !address.forwardTo.length) return null;
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<DestinationList
|
|
29
|
+
mailboxId={address.mailboxId}
|
|
30
|
+
forwardTo={address.forwardTo}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function DestinationList({
|
|
36
|
+
mailboxId,
|
|
37
|
+
forwardTo,
|
|
38
|
+
}: {
|
|
39
|
+
mailboxId: string;
|
|
40
|
+
/** As the form has them, saved or not. */
|
|
41
|
+
forwardTo: string[];
|
|
42
|
+
}) {
|
|
43
|
+
const queryClient = useQueryClient();
|
|
44
|
+
const queryKey = ["forward-destinations", mailboxId];
|
|
45
|
+
const param = { mailboxId };
|
|
46
|
+
|
|
47
|
+
const saved = useQuery({
|
|
48
|
+
queryKey,
|
|
49
|
+
queryFn: async () =>
|
|
50
|
+
responseJson(
|
|
51
|
+
await mailApi.api.mail["forward-destinations"][":mailboxId"].$get({
|
|
52
|
+
param,
|
|
53
|
+
})
|
|
54
|
+
),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const statuses = new Map(
|
|
58
|
+
(saved.data?.destinations ?? []).map((destination) => [
|
|
59
|
+
destination.email.toLowerCase(),
|
|
60
|
+
destination.status,
|
|
61
|
+
])
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// A new destination, or a saved one Email Routing lacks: saving adds it.
|
|
65
|
+
const missing =
|
|
66
|
+
saved.data?.connected === true &&
|
|
67
|
+
forwardTo.some((email) => {
|
|
68
|
+
const status = statuses.get(email);
|
|
69
|
+
|
|
70
|
+
return status === undefined || status === "missing";
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
useAddressSection({
|
|
74
|
+
dirty: missing,
|
|
75
|
+
// Runs after the address is saved, so the new destinations are stored.
|
|
76
|
+
save: async () => {
|
|
77
|
+
const response = await mailApi.api.mail["forward-destinations"][
|
|
78
|
+
":mailboxId"
|
|
79
|
+
].$post({ param });
|
|
80
|
+
|
|
81
|
+
// Either way, show what Email Routing has now.
|
|
82
|
+
await queryClient.invalidateQueries({ queryKey });
|
|
83
|
+
await responseJson(response);
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div className="space-y-2">
|
|
89
|
+
<p className="text-foreground/85 text-[0.8125rem] font-semibold">
|
|
90
|
+
Forward destinations
|
|
91
|
+
</p>
|
|
92
|
+
<ul className="divide-border/60 ring-border divide-y overflow-hidden rounded-xl ring-1">
|
|
93
|
+
{forwardTo.map((email) => {
|
|
94
|
+
const status = statuses.get(email);
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<li key={email} className="flex items-center gap-3 px-3.5 py-2.5">
|
|
98
|
+
<span className="min-w-0 flex-1 truncate text-[0.8125rem]">
|
|
99
|
+
{email}
|
|
100
|
+
</span>
|
|
101
|
+
{saved.isPending ? (
|
|
102
|
+
<Skeleton className="h-5 w-24" />
|
|
103
|
+
) : status === undefined ? (
|
|
104
|
+
<span className="text-muted-foreground text-xs">
|
|
105
|
+
Gets a confirmation email when you save
|
|
106
|
+
</span>
|
|
107
|
+
) : status === "missing" ? (
|
|
108
|
+
<Badge variant="destructive">Not added to Cloudflare</Badge>
|
|
109
|
+
) : status === "confirmed" ? (
|
|
110
|
+
<Badge variant="success">Confirmed</Badge>
|
|
111
|
+
) : status === "waiting" ? (
|
|
112
|
+
<Badge variant="warning">Waiting for confirmation</Badge>
|
|
113
|
+
) : null}
|
|
114
|
+
</li>
|
|
115
|
+
);
|
|
116
|
+
})}
|
|
117
|
+
</ul>
|
|
118
|
+
{saved.isError ? (
|
|
119
|
+
<p className="text-destructive text-xs">
|
|
120
|
+
Couldn't check these with Cloudflare: {saved.error.message}
|
|
121
|
+
</p>
|
|
122
|
+
) : saved.data && !saved.data.connected ? (
|
|
123
|
+
<p className="text-muted-foreground text-xs">
|
|
124
|
+
Email Routing isn't connected here (local development), so
|
|
125
|
+
confirmations can't be checked and nothing is forwarded.
|
|
126
|
+
</p>
|
|
127
|
+
) : forwardTo.some((email) => statuses.get(email) === "missing") ? (
|
|
128
|
+
<p className="text-destructive text-xs">
|
|
129
|
+
Cloudflare didn't add a destination, so it got no confirmation email.
|
|
130
|
+
Save the address to try again.
|
|
131
|
+
</p>
|
|
132
|
+
) : (
|
|
133
|
+
<p className="text-muted-foreground text-xs">
|
|
134
|
+
Mail goes only to confirmed destinations. Each new one gets an email
|
|
135
|
+
from Cloudflare with a link to confirm it.
|
|
136
|
+
</p>
|
|
137
|
+
)}
|
|
138
|
+
</div>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
DelayedFallback,
|
|
4
|
+
Skeleton,
|
|
5
|
+
queryErrorBlocksContent,
|
|
6
|
+
responseJson,
|
|
7
|
+
adminPanelClass,
|
|
8
|
+
AdminPanelBody,
|
|
9
|
+
AdminPanelHeader,
|
|
10
|
+
AdminQueryError,
|
|
11
|
+
} from "@open-workspace/core/ui";
|
|
12
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
13
|
+
import { Archive, LoaderCircle, Play } from "lucide-react";
|
|
14
|
+
import { toast } from "sonner";
|
|
15
|
+
|
|
16
|
+
import { mailApi } from "../lib/mail-api";
|
|
17
|
+
import { mailArchiveQuery } from "../settings/settings-queries";
|
|
18
|
+
|
|
19
|
+
const ARCHIVE_KEY = mailArchiveQuery.queryKey;
|
|
20
|
+
|
|
21
|
+
function formatTime(value: number) {
|
|
22
|
+
return new Intl.DateTimeFormat("en", {
|
|
23
|
+
dateStyle: "medium",
|
|
24
|
+
timeStyle: "short",
|
|
25
|
+
}).format(new Date(value));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Administration → Mail archive: counts, messages not archived yet, and Archive now. */
|
|
29
|
+
export function MailArchive() {
|
|
30
|
+
const client = useQueryClient();
|
|
31
|
+
|
|
32
|
+
const status = useQuery(mailArchiveQuery);
|
|
33
|
+
|
|
34
|
+
const run = useMutation({
|
|
35
|
+
mutationFn: async () =>
|
|
36
|
+
responseJson(await mailApi.api.mail.archive.run.$post()),
|
|
37
|
+
onSuccess: async () => {
|
|
38
|
+
toast.success("Archiving the open messages");
|
|
39
|
+
await client.invalidateQueries({ queryKey: ARCHIVE_KEY });
|
|
40
|
+
},
|
|
41
|
+
onError: (error) => toast.error(error.message),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const { data } = status;
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div className="max-w-4xl">
|
|
48
|
+
<div className={adminPanelClass}>
|
|
49
|
+
<AdminPanelHeader
|
|
50
|
+
Icon={Archive}
|
|
51
|
+
title="Mail archive"
|
|
52
|
+
description="A write-once copy of every received and sent message, in a bucket of its own."
|
|
53
|
+
/>
|
|
54
|
+
<AdminPanelBody className="space-y-4">
|
|
55
|
+
<DelayedFallback
|
|
56
|
+
pending={status.isPending}
|
|
57
|
+
fallback={<Skeleton className="h-20" />}
|
|
58
|
+
>
|
|
59
|
+
{queryErrorBlocksContent(status) ? (
|
|
60
|
+
<AdminQueryError
|
|
61
|
+
query={status}
|
|
62
|
+
message="The mail archive status couldn't be loaded."
|
|
63
|
+
/>
|
|
64
|
+
) : data?.enabled ? (
|
|
65
|
+
<>
|
|
66
|
+
<dl className="grid grid-cols-[auto_1fr] gap-x-6 gap-y-1.5 text-sm">
|
|
67
|
+
{data.years ? (
|
|
68
|
+
<>
|
|
69
|
+
<dt className="text-muted-foreground">Locked for</dt>
|
|
70
|
+
<dd>
|
|
71
|
+
{data.years === 1 ? "1 year" : `${data.years} years`}
|
|
72
|
+
</dd>
|
|
73
|
+
</>
|
|
74
|
+
) : null}
|
|
75
|
+
<dt className="text-muted-foreground">Archived</dt>
|
|
76
|
+
<dd>{data.archived}</dd>
|
|
77
|
+
<dt className="text-muted-foreground">Waiting</dt>
|
|
78
|
+
<dd>{data.pending}</dd>
|
|
79
|
+
<dt className="text-muted-foreground">Failed</dt>
|
|
80
|
+
<dd>{data.failed}</dd>
|
|
81
|
+
<dt className="text-muted-foreground">Not archived</dt>
|
|
82
|
+
<dd>{data.abandoned}</dd>
|
|
83
|
+
</dl>
|
|
84
|
+
{data.open.length ? (
|
|
85
|
+
<ul
|
|
86
|
+
aria-label="Messages not archived"
|
|
87
|
+
className="divide-border/70 border-border divide-y rounded-lg border"
|
|
88
|
+
>
|
|
89
|
+
{data.open.map((entry) => (
|
|
90
|
+
<li key={entry.id} className="px-3.5 py-2.5 text-sm">
|
|
91
|
+
<span className="block truncate font-medium">
|
|
92
|
+
{entry.mailbox ?? "Deleted address"} ·{" "}
|
|
93
|
+
{entry.direction === "incoming" ? "received" : "sent"}{" "}
|
|
94
|
+
{formatTime(entry.createdAt)}
|
|
95
|
+
{entry.status === "abandoned"
|
|
96
|
+
? " · not archived, no longer retried"
|
|
97
|
+
: ""}
|
|
98
|
+
</span>
|
|
99
|
+
<span className="text-muted-foreground block text-xs break-all">
|
|
100
|
+
{entry.lastError ?? "Waiting for its first copy"}
|
|
101
|
+
{entry.attempts ? ` · ${entry.attempts} tries` : ""}
|
|
102
|
+
</span>
|
|
103
|
+
</li>
|
|
104
|
+
))}
|
|
105
|
+
</ul>
|
|
106
|
+
) : null}
|
|
107
|
+
<Button
|
|
108
|
+
variant="outline"
|
|
109
|
+
disabled={run.isPending}
|
|
110
|
+
onClick={() => run.mutate()}
|
|
111
|
+
>
|
|
112
|
+
{run.isPending ? (
|
|
113
|
+
<LoaderCircle className="animate-spin" />
|
|
114
|
+
) : (
|
|
115
|
+
<Play />
|
|
116
|
+
)}
|
|
117
|
+
Archive now
|
|
118
|
+
</Button>
|
|
119
|
+
</>
|
|
120
|
+
) : (
|
|
121
|
+
<p className="text-muted-foreground text-sm">
|
|
122
|
+
The mail archive is off. Deploy with{" "}
|
|
123
|
+
<code className="text-foreground">
|
|
124
|
+
{"Email({ archive: { years: 10 } })"}
|
|
125
|
+
</code>{" "}
|
|
126
|
+
to keep a write-once copy of every message.
|
|
127
|
+
</p>
|
|
128
|
+
)}
|
|
129
|
+
</DelayedFallback>
|
|
130
|
+
</AdminPanelBody>
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { DelayedFallback, responseJson } from "@open-workspace/core/ui";
|
|
2
|
+
import type { TeamAddress } from "@open-workspace/core/ui";
|
|
3
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
4
|
+
import { LoaderCircle } from "lucide-react";
|
|
5
|
+
|
|
6
|
+
import { mailApi } from "../lib/mail-api";
|
|
7
|
+
import { mailboxesQuery } from "../mail/mail-queries";
|
|
8
|
+
import { SignatureEditor } from "../settings/signature-editor";
|
|
9
|
+
import type { SignatureBody } from "../settings/signature-editor";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A shared inbox's signature, in its address editor under Administration →
|
|
13
|
+
* Teams. It follows the delivery chosen in the form: switched to a mailing
|
|
14
|
+
* list, it hides and is no longer saved with "Save address".
|
|
15
|
+
*/
|
|
16
|
+
export function TeamSignature({ address }: { address: TeamAddress }) {
|
|
17
|
+
// Mailing lists copy mail to members; only shared inboxes send replies.
|
|
18
|
+
return address.delivery === "inbox" ? (
|
|
19
|
+
<TeamSignatureSection address={address} />
|
|
20
|
+
) : null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function TeamSignatureSection({ address }: { address: TeamAddress }) {
|
|
24
|
+
const client = useQueryClient();
|
|
25
|
+
const mailboxes = useQuery(mailboxesQuery());
|
|
26
|
+
const param = { mailboxId: address.mailboxId };
|
|
27
|
+
|
|
28
|
+
// Read once per opening: the editor keeps its own state after loading it.
|
|
29
|
+
const saved = useQuery({
|
|
30
|
+
queryKey: ["team-signature", address.mailboxId],
|
|
31
|
+
queryFn: async () =>
|
|
32
|
+
responseJson(
|
|
33
|
+
await mailApi.api.mail["team-signatures"][":mailboxId"].$get({ param })
|
|
34
|
+
),
|
|
35
|
+
staleTime: Number.POSITIVE_INFINITY,
|
|
36
|
+
gcTime: 0,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Images upload through a mailbox the administrator can send from.
|
|
40
|
+
const sendable = mailboxes.data?.mailboxes.filter(
|
|
41
|
+
(mailbox) => mailbox.canSend
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const uploadMailbox =
|
|
45
|
+
sendable?.find((mailbox) => mailbox.id === address.mailboxId) ??
|
|
46
|
+
sendable?.[0];
|
|
47
|
+
|
|
48
|
+
async function save(body: SignatureBody) {
|
|
49
|
+
await responseJson(
|
|
50
|
+
await mailApi.api.mail["team-signatures"][":mailboxId"].$put({
|
|
51
|
+
param,
|
|
52
|
+
json: body,
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
await client.invalidateQueries({ queryKey: mailboxesQuery().queryKey });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<div className="space-y-2">
|
|
60
|
+
<h3 className="text-sm leading-none font-medium">Signature</h3>
|
|
61
|
+
<p className="text-muted-foreground text-xs">
|
|
62
|
+
Added to messages sent from {address.address}. {"{name}"} becomes the
|
|
63
|
+
sender's name. Without one, messages from here get no signature.
|
|
64
|
+
</p>
|
|
65
|
+
<DelayedFallback
|
|
66
|
+
pending={saved.isPending || mailboxes.isPending}
|
|
67
|
+
fallback={
|
|
68
|
+
<div className="text-muted-foreground flex items-center gap-2 py-3 text-sm">
|
|
69
|
+
<LoaderCircle className="size-4 animate-spin" /> Loading signature…
|
|
70
|
+
</div>
|
|
71
|
+
}
|
|
72
|
+
>
|
|
73
|
+
{saved.data ? (
|
|
74
|
+
<SignatureEditor
|
|
75
|
+
saved={saved.data.signature}
|
|
76
|
+
uploadMailboxId={uploadMailbox?.id}
|
|
77
|
+
label={`Signature for ${address.address}`}
|
|
78
|
+
placeholder={`{name}, ${address.displayName}…`}
|
|
79
|
+
section
|
|
80
|
+
onSave={save}
|
|
81
|
+
/>
|
|
82
|
+
) : (
|
|
83
|
+
<p className="text-destructive text-sm">
|
|
84
|
+
The signature couldn't be loaded.
|
|
85
|
+
</p>
|
|
86
|
+
)}
|
|
87
|
+
</DelayedFallback>
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
}
|