@open-workspace/email 0.3.0 → 0.4.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 +22 -22
- package/alchemy/index.ts +273 -0
- package/drizzle/mailbox/0000_puzzling_dracula.sql +149 -0
- package/drizzle/mailbox/0001_mute_jack_flag.sql +12 -0
- package/drizzle/mailbox/meta/0000_snapshot.json +1002 -0
- package/drizzle/mailbox/meta/0001_snapshot.json +1002 -0
- package/drizzle/mailbox/meta/_journal.json +20 -0
- package/drizzle/mailbox/migrations.js +12 -0
- package/index.ts +3 -1
- package/migrations/{0000_email.sql → 0000_dry_moon_knight.sql} +26 -20
- package/migrations/meta/0000_snapshot.json +125 -109
- package/migrations/meta/_journal.json +2 -2
- package/package.json +74 -68
- package/shared/attachment-preview.ts +37 -27
- package/shared/folder-order.ts +106 -0
- package/shared/mail-authentication.ts +8 -3
- package/shared/mail-feedback.ts +18 -25
- package/shared/mail-headers.ts +114 -39
- package/shared/mail-import.ts +38 -0
- package/shared/mail-path.ts +42 -0
- package/shared/mail-received.ts +174 -31
- package/shared/mail-remote.ts +59 -2
- package/shared/mail-sender-intel.ts +22 -4
- package/shared/mail.ts +77 -28
- package/shared/module.ts +33 -0
- package/shared/office-preview.ts +14 -2
- package/shared/pdfjs-assets.ts +35 -0
- package/shared/permissions.ts +73 -0
- package/shared/webhooks.ts +41 -0
- package/src/admin/blocked-senders.tsx +189 -0
- package/src/client.tsx +97 -0
- package/src/lib/mail-api.ts +9 -0
- package/src/mail/attachment-preview-dialog.tsx +161 -0
- package/src/mail/blocked-senders.tsx +138 -0
- package/src/mail/compose-window-chrome.tsx +194 -0
- package/src/mail/compose-window.tsx +486 -0
- package/src/mail/composer-asset-bookmarks.ts +409 -0
- package/src/mail/composer-asset.tsx +229 -0
- package/src/mail/composer-attachment-list.tsx +138 -0
- package/src/mail/composer-editor-document.ts +65 -0
- package/src/mail/composer-editor.tsx +284 -0
- package/src/mail/composer-linked-attachment-text.ts +12 -0
- package/src/mail/composer-recipient-fields.tsx +165 -0
- package/src/mail/composer-recipients.ts +208 -0
- package/src/mail/composer-session.ts +562 -0
- package/src/mail/composer-toolbar.tsx +303 -0
- package/src/mail/composer-upload-client.ts +105 -0
- package/src/mail/composer-upload-progress.ts +53 -0
- package/src/mail/conversation-list.tsx +550 -0
- package/src/mail/conversation-loading-skeleton.tsx +119 -0
- package/src/mail/conversation-message.tsx +346 -0
- package/src/mail/conversation-reply.tsx +470 -0
- package/src/mail/conversation-selection-toolbar.tsx +322 -0
- package/src/mail/conversation-view.tsx +437 -0
- package/src/mail/delivery-indicator.tsx +272 -0
- package/src/mail/email-html-body.tsx +203 -0
- package/src/mail/folder-glyph.tsx +46 -0
- package/src/mail/folder-manager.tsx +532 -0
- package/src/mail/format-bytes.ts +7 -0
- package/src/mail/mail-app-bar.tsx +253 -0
- package/src/mail/mail-background.tsx +12 -0
- package/src/mail/mail-dock.tsx +137 -0
- package/src/mail/mail-folders.ts +44 -0
- package/src/mail/mail-layout.css +236 -0
- package/src/mail/mail-location.ts +73 -0
- package/src/mail/mail-mailbox-sheet.tsx +275 -0
- package/src/mail/mail-nav-rail.tsx +129 -0
- package/src/mail/mail-nav.tsx +324 -0
- package/src/mail/mail-prefetch.ts +59 -0
- package/src/mail/mail-primitives.tsx +66 -0
- package/src/mail/mail-queries.ts +209 -0
- package/src/mail/mail-query-cache.ts +486 -0
- package/src/mail/mail-seed.ts +47 -0
- package/src/mail/mail-shell.tsx +126 -0
- package/src/mail/mailbox-ai-settings.tsx +185 -0
- package/src/mail/mailbox-realtime.tsx +251 -0
- package/src/mail/mailbox-route.tsx +15 -0
- package/src/mail/message-actions.tsx +353 -0
- package/src/mail/message-attachments.tsx +200 -0
- package/src/mail/message-format.ts +75 -0
- package/src/mail/message-header.tsx +260 -0
- package/src/mail/message-translation.tsx +225 -0
- package/src/mail/original-message-sheet.tsx +619 -0
- package/src/mail/original-message.ts +191 -0
- package/src/mail/outbound-notification.ts +53 -0
- package/src/mail/pane-splitter.tsx +117 -0
- package/src/mail/pdf-preview-toolbar.tsx +152 -0
- package/src/mail/pdf-preview.css +44 -0
- package/src/mail/pdf-preview.tsx +156 -0
- package/src/mail/pdf-translation-layout.ts +95 -0
- package/src/mail/print-message.ts +92 -0
- package/src/mail/reader-pane.tsx +535 -0
- package/src/mail/recipient-combobox.tsx +335 -0
- package/src/mail/recipient-field-row.tsx +34 -0
- package/src/mail/reply-to-warning.tsx +50 -0
- package/src/mail/sanitize-email-html.ts +430 -0
- package/src/mail/sender-actions.tsx +149 -0
- package/src/mail/sender-authentication.tsx +485 -0
- package/src/mail/sender-dialogs.tsx +384 -0
- package/src/mail/sender-security.tsx +545 -0
- package/src/mail/toolbar-tooltip.tsx +29 -0
- package/src/mail/translation-html.ts +49 -0
- package/src/mail/translation-language.ts +21 -0
- package/src/mail/types.ts +53 -0
- package/src/mail/unread-document-indicator.tsx +60 -0
- package/src/mail/use-compose-submission.ts +208 -0
- package/src/mail/use-composer-attachment-preflight.ts +184 -0
- package/src/mail/use-composer-submission.ts +117 -0
- package/src/mail/use-conversation-selection.ts +186 -0
- package/src/mail/use-mail-controller.ts +427 -0
- package/src/mail/use-mail-data.ts +279 -0
- package/src/mail/use-mail-safety.ts +155 -0
- package/src/mail/use-mail-send.ts +142 -0
- package/src/mail/use-pdf-translation-overlay.ts +156 -0
- package/src/mail/use-pdf-translation.ts +100 -0
- package/src/mail/use-pdf-viewer.ts +215 -0
- package/src/mail/use-reply-submission.ts +114 -0
- package/src/mail/use-sanitized-email-html.ts +20 -0
- package/src/mail/use-visible-message-read.ts +138 -0
- package/src/pwa/push-subscription.ts +151 -0
- package/src/settings/mail-apps-page.tsx +235 -0
- package/src/settings/notifications-page.tsx +291 -0
- package/worker/admin/blocked-sender-routes.ts +166 -0
- package/worker/admin/schemas.ts +11 -0
- package/worker/bindings.d.ts +14 -10
- package/worker/db/schema.ts +63 -40
- package/worker/jmap/eventsource.ts +84 -16
- package/worker/jmap/methods.ts +1630 -524
- package/worker/jmap/push-types.ts +27 -0
- package/worker/jmap/push.ts +140 -56
- package/worker/jmap/routes.ts +366 -105
- package/worker/mail/access.ts +258 -21
- package/worker/mail/ai-classification.ts +36 -20
- package/worker/mail/ai-translation.ts +13 -6
- package/worker/mail/auth-headers.ts +395 -137
- package/worker/mail/bimi.ts +200 -73
- package/worker/mail/bootstrap.ts +79 -0
- package/worker/mail/capped-body.ts +36 -0
- package/worker/mail/classification-signals.ts +35 -25
- package/worker/mail/conversation-cursor.ts +30 -19
- package/worker/mail/delivery-events.ts +88 -62
- package/worker/mail/delivery-facts.ts +46 -10
- package/worker/mail/demo-routes.ts +34 -10
- package/worker/mail/doh.ts +62 -23
- package/worker/mail/downloads.ts +75 -40
- package/worker/mail/edge-cache.ts +155 -0
- package/worker/mail/header-metadata.ts +88 -22
- package/worker/mail/impersonation.ts +160 -38
- package/worker/mail/import-routes.ts +313 -0
- package/worker/mail/inbound-delivery.ts +19 -9
- package/worker/mail/inbound-threading.ts +18 -8
- package/worker/mail/inbound.ts +82 -40
- package/worker/mail/ip-intel.ts +110 -27
- package/worker/mail/isolate-cache.ts +35 -0
- package/worker/mail/link-domains.ts +29 -7
- package/worker/mail/mailbox-deletion.ts +10 -4
- package/worker/mail/mailbox-directory.ts +16 -6
- package/worker/mail/mailing-list.ts +94 -39
- package/worker/mail/message-security.ts +90 -15
- package/worker/mail/message-view.ts +18 -6
- package/worker/mail/office-conversion.ts +31 -9
- package/worker/mail/office-preview-container.ts +40 -13
- package/worker/mail/office-preview-queue.ts +76 -32
- package/worker/mail/org-domain.ts +8 -1
- package/worker/mail/outbound-content.ts +71 -26
- package/worker/mail/outbound-delivery.ts +31 -17
- package/worker/mail/outbound-service.ts +48 -30
- package/worker/mail/outbound-threading.ts +30 -17
- package/worker/mail/outbound.ts +97 -70
- package/worker/mail/outgoing-context.ts +25 -15
- package/worker/mail/participants.ts +44 -29
- package/worker/mail/push-notifications.ts +271 -173
- package/worker/mail/quote-parser.ts +21 -10
- package/worker/mail/r2-presigned-urls.ts +31 -25
- package/worker/mail/receive.ts +23 -11
- package/worker/mail/recipients.ts +6 -1
- package/worker/mail/remote-proxy.ts +187 -31
- package/worker/mail/remote-routes.ts +87 -0
- package/worker/mail/remote-token.ts +104 -0
- package/worker/mail/repeat.ts +19 -0
- package/worker/mail/reply-plan.ts +62 -33
- package/worker/mail/rfc.ts +32 -7
- package/worker/mail/routes.ts +870 -541
- package/worker/mail/safety-routes.ts +328 -200
- package/worker/mail/schemas.ts +84 -105
- package/worker/mail/search.ts +1 -0
- package/worker/mail/security-settings.ts +41 -9
- package/worker/mail/sender-intel.ts +206 -51
- package/worker/mail/spamhaus.ts +92 -45
- package/worker/mail/unsubscribe.ts +76 -18
- package/worker/mail/uploads.ts +126 -93
- package/worker/mail/webhook-source.ts +35 -12
- package/worker/mail/workspace-safety.ts +97 -38
- package/worker/mailbox/demo-html.ts +7 -7
- package/worker/mailbox/demo-seed.ts +10 -44
- package/worker/mailbox/demo.ts +595 -225
- package/worker/mailbox/email-index.ts +53 -0
- package/worker/mailbox/folder-model.ts +53 -17
- package/worker/mailbox/import-placement.ts +88 -0
- package/worker/mailbox/inbox-counts.ts +106 -0
- package/worker/mailbox/index.ts +1734 -721
- package/worker/mailbox/jmap-store.ts +139 -35
- package/worker/mailbox/model.ts +8 -6
- package/worker/mailbox/office-preview-jobs.ts +56 -25
- package/worker/mailbox/schema.ts +87 -66
- package/worker/mailbox/senders.ts +176 -70
- package/worker/mcp/mail-action-tools.ts +128 -87
- package/worker/mcp/mail-compose-tools.ts +133 -82
- package/worker/mcp/mail-query-tools.ts +120 -71
- package/worker/mcp/mail-safety-tools.ts +321 -248
- package/worker/mcp/schemas.ts +43 -0
- package/worker/mcp/tools.ts +13 -10
- package/worker/module.ts +43 -18
- package/worker/sql.d.ts +8 -0
- package/alchemy.ts +0 -142
- package/containers/office-preview/Dockerfile +0 -10
- package/shared/mail-rules.ts +0 -156
- package/worker/admin/report-routes.ts +0 -164
- package/worker/mail/reported-messages.ts +0 -68
- package/worker/mailbox/migrations.ts +0 -10
- package/worker/mailbox/rules.ts +0 -110
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AlertDialog,
|
|
3
|
+
AlertDialogAction,
|
|
4
|
+
AlertDialogCancel,
|
|
5
|
+
AlertDialogContent,
|
|
6
|
+
AlertDialogDescription,
|
|
7
|
+
AlertDialogFooter,
|
|
8
|
+
AlertDialogHeader,
|
|
9
|
+
AlertDialogTitle,
|
|
10
|
+
Checkbox,
|
|
11
|
+
RadioCard,
|
|
12
|
+
RadioGroup,
|
|
13
|
+
cn,
|
|
14
|
+
} from "@open-workspace/core/ui";
|
|
15
|
+
import { ExternalLink, LoaderCircle, MailMinus, ShieldBan } from "lucide-react";
|
|
16
|
+
import { useState } from "react";
|
|
17
|
+
import type { ReactNode } from "react";
|
|
18
|
+
import { toast } from "sonner";
|
|
19
|
+
|
|
20
|
+
import type { Mailbox, MessageDetail } from "./types";
|
|
21
|
+
import { useBlockSender, useUnsubscribe } from "./use-mail-safety";
|
|
22
|
+
|
|
23
|
+
export function senderLabel(
|
|
24
|
+
message: Pick<MessageDetail, "fromName" | "fromAddress">
|
|
25
|
+
) {
|
|
26
|
+
return message.fromName || message.fromAddress;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function addressDomain(address: string) {
|
|
30
|
+
return address.slice(address.lastIndexOf("@") + 1).toLowerCase();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function urlHost(url: string | null | undefined) {
|
|
34
|
+
if (!url) return null;
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
return new URL(url).hostname;
|
|
38
|
+
} catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function mailtoAddress(uri: string | null | undefined) {
|
|
44
|
+
if (!uri) return null;
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
return decodeURIComponent(new URL(uri).pathname);
|
|
48
|
+
} catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function CheckRow({
|
|
54
|
+
checked,
|
|
55
|
+
disabled,
|
|
56
|
+
onChange,
|
|
57
|
+
children,
|
|
58
|
+
hint,
|
|
59
|
+
}: {
|
|
60
|
+
checked: boolean;
|
|
61
|
+
disabled?: boolean;
|
|
62
|
+
onChange: (checked: boolean) => void;
|
|
63
|
+
children: ReactNode;
|
|
64
|
+
hint?: ReactNode;
|
|
65
|
+
}) {
|
|
66
|
+
return (
|
|
67
|
+
<label
|
|
68
|
+
className={cn(
|
|
69
|
+
"flex items-start gap-2.5 text-[13px] leading-5",
|
|
70
|
+
disabled && "opacity-60"
|
|
71
|
+
)}
|
|
72
|
+
>
|
|
73
|
+
<Checkbox
|
|
74
|
+
className="mt-0.5"
|
|
75
|
+
checked={checked}
|
|
76
|
+
disabled={disabled}
|
|
77
|
+
onCheckedChange={(value) => onChange(value === true)}
|
|
78
|
+
/>
|
|
79
|
+
<span className="min-w-0">
|
|
80
|
+
<span className="text-foreground font-medium">{children}</span>
|
|
81
|
+
{hint && (
|
|
82
|
+
<span className="text-muted-foreground block text-xs">{hint}</span>
|
|
83
|
+
)}
|
|
84
|
+
</span>
|
|
85
|
+
</label>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The sender's unsubscribe page, opened only by an explicit click, without a referrer. */
|
|
90
|
+
function UnsubscribePageLink({
|
|
91
|
+
url,
|
|
92
|
+
onOpen,
|
|
93
|
+
}: {
|
|
94
|
+
url: string;
|
|
95
|
+
onOpen: () => void;
|
|
96
|
+
}) {
|
|
97
|
+
return (
|
|
98
|
+
<a
|
|
99
|
+
href={url}
|
|
100
|
+
target="_blank"
|
|
101
|
+
rel="noopener noreferrer"
|
|
102
|
+
referrerPolicy="no-referrer"
|
|
103
|
+
onClick={onOpen}
|
|
104
|
+
className="bg-primary text-primary-foreground hover:bg-primary/90 focus-visible:ring-ring/40 inline-flex h-9 items-center justify-center gap-1.5 rounded-md px-3 text-sm font-medium outline-none focus-visible:ring-3"
|
|
105
|
+
>
|
|
106
|
+
<ExternalLink className="size-4" /> Open unsubscribe page
|
|
107
|
+
</a>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function UnsubscribeDialog({
|
|
112
|
+
message,
|
|
113
|
+
mailbox,
|
|
114
|
+
open,
|
|
115
|
+
onOpenChange,
|
|
116
|
+
}: {
|
|
117
|
+
message: MessageDetail;
|
|
118
|
+
mailbox: Mailbox;
|
|
119
|
+
open: boolean;
|
|
120
|
+
onOpenChange: (open: boolean) => void;
|
|
121
|
+
}) {
|
|
122
|
+
const methods = message.security?.listUnsubscribe;
|
|
123
|
+
const unsubscribe = useUnsubscribe();
|
|
124
|
+
|
|
125
|
+
const [fallback, setFallback] = useState<{
|
|
126
|
+
url: string;
|
|
127
|
+
detail: string | null;
|
|
128
|
+
} | null>(null);
|
|
129
|
+
|
|
130
|
+
const name = senderLabel(message);
|
|
131
|
+
|
|
132
|
+
const domain =
|
|
133
|
+
message.security?.fromDomain ?? addressDomain(message.fromAddress);
|
|
134
|
+
|
|
135
|
+
const host = urlHost(methods?.httpsUrl);
|
|
136
|
+
const mailto = mailtoAddress(methods?.mailto);
|
|
137
|
+
const canMail = Boolean(mailto && mailbox.canSend);
|
|
138
|
+
const automatic = Boolean(methods?.oneClick || canMail);
|
|
139
|
+
|
|
140
|
+
const linkUrl =
|
|
141
|
+
fallback?.url ?? (automatic ? null : (methods?.httpsUrl ?? null));
|
|
142
|
+
|
|
143
|
+
function close(next: boolean) {
|
|
144
|
+
if (!next) setFallback(null);
|
|
145
|
+
onOpenChange(next);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function recordOpened() {
|
|
149
|
+
unsubscribe.mutate(
|
|
150
|
+
{ mailboxId: mailbox.id, messageId: message.id, method: "link" },
|
|
151
|
+
{
|
|
152
|
+
onSuccess: () => close(false),
|
|
153
|
+
onError: (error) => toast.error(error.message),
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function confirm() {
|
|
159
|
+
unsubscribe.mutate(
|
|
160
|
+
{ mailboxId: mailbox.id, messageId: message.id, method: "auto" },
|
|
161
|
+
{
|
|
162
|
+
onSuccess: (result) => {
|
|
163
|
+
if (result.outcome === "done") {
|
|
164
|
+
toast.success(`Unsubscribed from ${name}`);
|
|
165
|
+
close(false);
|
|
166
|
+
} else if (result.outcome === "requested") {
|
|
167
|
+
toast.success(
|
|
168
|
+
`Unsubscribe email sent to ${result.unsubscription?.target ?? "the list"}`
|
|
169
|
+
);
|
|
170
|
+
close(false);
|
|
171
|
+
} else if (result.outcome === "link" && result.url) {
|
|
172
|
+
setFallback({ url: result.url, detail: result.detail });
|
|
173
|
+
} else {
|
|
174
|
+
toast.error(result.detail ?? "Could not unsubscribe");
|
|
175
|
+
close(false);
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
onError: (error) => toast.error(error.message),
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<AlertDialog open={open} onOpenChange={close}>
|
|
185
|
+
<AlertDialogContent className="sm:max-w-md">
|
|
186
|
+
<AlertDialogHeader>
|
|
187
|
+
<AlertDialogTitle className="flex items-center gap-2">
|
|
188
|
+
<MailMinus className="text-muted-foreground size-4" />
|
|
189
|
+
Unsubscribe from {name}?
|
|
190
|
+
</AlertDialogTitle>
|
|
191
|
+
<AlertDialogDescription
|
|
192
|
+
render={<div />}
|
|
193
|
+
className="space-y-2 text-[13px] leading-5"
|
|
194
|
+
>
|
|
195
|
+
{linkUrl ? (
|
|
196
|
+
<>
|
|
197
|
+
{fallback ? (
|
|
198
|
+
<p>
|
|
199
|
+
{fallback.detail ??
|
|
200
|
+
"We couldn't unsubscribe automatically."}{" "}
|
|
201
|
+
You can finish on the sender's page.
|
|
202
|
+
</p>
|
|
203
|
+
) : (
|
|
204
|
+
<p>
|
|
205
|
+
{name} only offers an unsubscribe page. Nothing is opened
|
|
206
|
+
until you choose to.
|
|
207
|
+
</p>
|
|
208
|
+
)}
|
|
209
|
+
<p>
|
|
210
|
+
It opens in a new tab on{" "}
|
|
211
|
+
<span className="text-foreground font-medium">
|
|
212
|
+
{urlHost(linkUrl)}
|
|
213
|
+
</span>
|
|
214
|
+
, outside OpenWorkspace.
|
|
215
|
+
</p>
|
|
216
|
+
</>
|
|
217
|
+
) : (
|
|
218
|
+
<>
|
|
219
|
+
<p>
|
|
220
|
+
{methods?.oneClick ? (
|
|
221
|
+
<>
|
|
222
|
+
We'll ask{" "}
|
|
223
|
+
<span
|
|
224
|
+
className="text-foreground font-medium"
|
|
225
|
+
title={host ?? undefined}
|
|
226
|
+
>
|
|
227
|
+
{domain}
|
|
228
|
+
</span>{" "}
|
|
229
|
+
to stop sending{" "}
|
|
230
|
+
</>
|
|
231
|
+
) : (
|
|
232
|
+
<>
|
|
233
|
+
We'll email{" "}
|
|
234
|
+
<span className="text-foreground font-medium">
|
|
235
|
+
{mailto}
|
|
236
|
+
</span>{" "}
|
|
237
|
+
from {mailbox.address} to stop sending{" "}
|
|
238
|
+
</>
|
|
239
|
+
)}
|
|
240
|
+
{message.listId ? (
|
|
241
|
+
<>
|
|
242
|
+
the list{" "}
|
|
243
|
+
<span className="text-foreground font-medium">
|
|
244
|
+
{message.listId}
|
|
245
|
+
</span>
|
|
246
|
+
</>
|
|
247
|
+
) : (
|
|
248
|
+
"these messages"
|
|
249
|
+
)}{" "}
|
|
250
|
+
to {mailbox.address}.
|
|
251
|
+
</p>
|
|
252
|
+
{methods?.oneClick && canMail && (
|
|
253
|
+
<p title={mailto ?? undefined}>
|
|
254
|
+
If their server doesn't answer, we'll send an unsubscribe
|
|
255
|
+
email from {mailbox.address} instead.
|
|
256
|
+
</p>
|
|
257
|
+
)}
|
|
258
|
+
<p>No links in the message are opened.</p>
|
|
259
|
+
</>
|
|
260
|
+
)}
|
|
261
|
+
</AlertDialogDescription>
|
|
262
|
+
</AlertDialogHeader>
|
|
263
|
+
<AlertDialogFooter>
|
|
264
|
+
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
265
|
+
{linkUrl ? (
|
|
266
|
+
<UnsubscribePageLink url={linkUrl} onOpen={recordOpened} />
|
|
267
|
+
) : (
|
|
268
|
+
<AlertDialogAction
|
|
269
|
+
type="button"
|
|
270
|
+
disabled={unsubscribe.isPending}
|
|
271
|
+
onClick={confirm}
|
|
272
|
+
>
|
|
273
|
+
{unsubscribe.isPending && (
|
|
274
|
+
<LoaderCircle className="animate-spin" />
|
|
275
|
+
)}
|
|
276
|
+
Unsubscribe
|
|
277
|
+
</AlertDialogAction>
|
|
278
|
+
)}
|
|
279
|
+
</AlertDialogFooter>
|
|
280
|
+
</AlertDialogContent>
|
|
281
|
+
</AlertDialog>
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export function BlockSenderDialog({
|
|
286
|
+
message,
|
|
287
|
+
mailbox,
|
|
288
|
+
open,
|
|
289
|
+
onOpenChange,
|
|
290
|
+
onMoved,
|
|
291
|
+
}: {
|
|
292
|
+
message: MessageDetail;
|
|
293
|
+
mailbox: Mailbox;
|
|
294
|
+
open: boolean;
|
|
295
|
+
onOpenChange: (open: boolean) => void;
|
|
296
|
+
onMoved?: () => void;
|
|
297
|
+
}) {
|
|
298
|
+
const block = useBlockSender();
|
|
299
|
+
const [scope, setScope] = useState<"address" | "domain">("address");
|
|
300
|
+
const [moveExisting, setMoveExisting] = useState(true);
|
|
301
|
+
const name = senderLabel(message);
|
|
302
|
+
const domain = addressDomain(message.fromAddress);
|
|
303
|
+
const ownDomain = domain === addressDomain(mailbox.address);
|
|
304
|
+
|
|
305
|
+
function confirm() {
|
|
306
|
+
const pattern = scope === "domain" ? `@${domain}` : message.fromAddress;
|
|
307
|
+
block.mutate(
|
|
308
|
+
{ mailboxId: mailbox.id, pattern, moveExisting },
|
|
309
|
+
{
|
|
310
|
+
onSuccess: (result) => {
|
|
311
|
+
toast.success(
|
|
312
|
+
result.moved
|
|
313
|
+
? `Blocked ${result.block.pattern}; moved ${result.moved} conversation${result.moved === 1 ? "" : "s"} to Spam`
|
|
314
|
+
: `Blocked ${result.block.pattern}`
|
|
315
|
+
);
|
|
316
|
+
onOpenChange(false);
|
|
317
|
+
|
|
318
|
+
if (result.moved) onMoved?.();
|
|
319
|
+
},
|
|
320
|
+
onError: (error) => toast.error(error.message),
|
|
321
|
+
}
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return (
|
|
326
|
+
<AlertDialog open={open} onOpenChange={onOpenChange}>
|
|
327
|
+
<AlertDialogContent className="sm:max-w-md">
|
|
328
|
+
<AlertDialogHeader>
|
|
329
|
+
<AlertDialogTitle className="flex items-center gap-2">
|
|
330
|
+
<ShieldBan className="text-muted-foreground size-4" />
|
|
331
|
+
Block {name}?
|
|
332
|
+
</AlertDialogTitle>
|
|
333
|
+
<AlertDialogDescription className="text-[13px] leading-5">
|
|
334
|
+
New messages will go straight to Spam for everyone using this
|
|
335
|
+
mailbox. The sender isn't told, and you can unblock at any time.
|
|
336
|
+
</AlertDialogDescription>
|
|
337
|
+
</AlertDialogHeader>
|
|
338
|
+
<RadioGroup
|
|
339
|
+
aria-label="What to block"
|
|
340
|
+
value={scope}
|
|
341
|
+
onValueChange={(value: "address" | "domain") => setScope(value)}
|
|
342
|
+
>
|
|
343
|
+
{(
|
|
344
|
+
[
|
|
345
|
+
["address", message.fromAddress, "Only this address"],
|
|
346
|
+
["domain", `@${domain}`, "Everyone at this domain"],
|
|
347
|
+
] as const
|
|
348
|
+
).map(([value, label, hint]) => (
|
|
349
|
+
<RadioCard
|
|
350
|
+
key={value}
|
|
351
|
+
value={value}
|
|
352
|
+
disabled={value === "domain" && ownDomain}
|
|
353
|
+
className="items-center rounded-md px-3 py-2 data-disabled:opacity-50 *:data-[slot=radio-card-indicator]:mt-0"
|
|
354
|
+
>
|
|
355
|
+
<span className="min-w-0">
|
|
356
|
+
<span className="block truncate text-[13px] font-medium">
|
|
357
|
+
{label}
|
|
358
|
+
</span>
|
|
359
|
+
<span className="text-muted-foreground block text-xs">
|
|
360
|
+
{hint}
|
|
361
|
+
</span>
|
|
362
|
+
</span>
|
|
363
|
+
</RadioCard>
|
|
364
|
+
))}
|
|
365
|
+
</RadioGroup>
|
|
366
|
+
<CheckRow checked={moveExisting} onChange={setMoveExisting}>
|
|
367
|
+
Also move existing conversations to Spam
|
|
368
|
+
</CheckRow>
|
|
369
|
+
<AlertDialogFooter>
|
|
370
|
+
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
371
|
+
<AlertDialogAction
|
|
372
|
+
type="button"
|
|
373
|
+
variant="destructive"
|
|
374
|
+
disabled={block.isPending}
|
|
375
|
+
onClick={confirm}
|
|
376
|
+
>
|
|
377
|
+
{block.isPending && <LoaderCircle className="animate-spin" />}
|
|
378
|
+
Block
|
|
379
|
+
</AlertDialogAction>
|
|
380
|
+
</AlertDialogFooter>
|
|
381
|
+
</AlertDialogContent>
|
|
382
|
+
</AlertDialog>
|
|
383
|
+
);
|
|
384
|
+
}
|