@open-workspace/email 0.2.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 +23 -20
- 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_dry_moon_knight.sql +77 -0
- package/migrations/meta/0000_snapshot.json +248 -106
- 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 +78 -26
- 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 +90 -34
- package/worker/jmap/eventsource.ts +169 -0
- package/worker/jmap/methods.ts +1716 -361
- package/worker/jmap/push-types.ts +27 -0
- package/worker/jmap/push.ts +207 -0
- package/worker/jmap/routes.ts +448 -86
- 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 +84 -52
- 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 +283 -171
- 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 +871 -542
- package/worker/mail/safety-routes.ts +329 -202
- 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 +153 -91
- 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 +597 -227
- 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 +1761 -737
- package/worker/mailbox/jmap-store.ts +139 -35
- package/worker/mailbox/model.ts +7 -14
- 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 -126
- package/containers/office-preview/Dockerfile +0 -10
- package/migrations/0000_email.sql +0 -53
- 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/legacy-migrations.ts +0 -41
- package/worker/mailbox/migrations.ts +0 -10
- package/worker/mailbox/rules.ts +0 -110
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
buttonVariants,
|
|
4
|
+
Sheet,
|
|
5
|
+
SheetContent,
|
|
6
|
+
SheetDescription,
|
|
7
|
+
SheetHeader,
|
|
8
|
+
SheetTitle,
|
|
9
|
+
responseJson,
|
|
10
|
+
cn,
|
|
11
|
+
} from "@open-workspace/core/ui";
|
|
12
|
+
import { useQuery } from "@tanstack/react-query";
|
|
13
|
+
import { format } from "date-fns";
|
|
14
|
+
import {
|
|
15
|
+
BadgeCheck,
|
|
16
|
+
Check,
|
|
17
|
+
Copy,
|
|
18
|
+
Download,
|
|
19
|
+
LoaderCircle,
|
|
20
|
+
Lock,
|
|
21
|
+
LockOpen,
|
|
22
|
+
ShieldAlert,
|
|
23
|
+
ShieldCheck,
|
|
24
|
+
Sparkles,
|
|
25
|
+
} from "lucide-react";
|
|
26
|
+
import { useMemo, useState } from "react";
|
|
27
|
+
import type { ReactNode } from "react";
|
|
28
|
+
import { z } from "zod";
|
|
29
|
+
|
|
30
|
+
import { mailApi } from "../lib/mail-api";
|
|
31
|
+
import { formatBytes } from "./format-bytes";
|
|
32
|
+
import {
|
|
33
|
+
ipKind,
|
|
34
|
+
mimeStructure,
|
|
35
|
+
originalSenderDetails,
|
|
36
|
+
receivedHops,
|
|
37
|
+
transitTime,
|
|
38
|
+
} from "./original-message";
|
|
39
|
+
import type { IpKind, MimePart, ReceivedHop } from "./original-message";
|
|
40
|
+
import {
|
|
41
|
+
SenderAuthentication,
|
|
42
|
+
unsubscribeSummary,
|
|
43
|
+
} from "./sender-authentication";
|
|
44
|
+
import { senderIntelRows } from "./sender-security";
|
|
45
|
+
import type { MessageDetail } from "./types";
|
|
46
|
+
|
|
47
|
+
export function originalSourceUrl(mailboxId: string, messageId: string) {
|
|
48
|
+
return `/api/mail/messages/${encodeURIComponent(messageId)}/original?mailboxId=${encodeURIComponent(mailboxId)}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const errorBody = z.object({ error: z.object({ message: z.string() }) });
|
|
52
|
+
|
|
53
|
+
async function responseMessage(response: Response) {
|
|
54
|
+
try {
|
|
55
|
+
const body = errorBody.safeParse(await response.json());
|
|
56
|
+
|
|
57
|
+
return body.success ? body.data.error.message : undefined;
|
|
58
|
+
} catch {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function Section({
|
|
64
|
+
title,
|
|
65
|
+
aside,
|
|
66
|
+
children,
|
|
67
|
+
}: {
|
|
68
|
+
title: string;
|
|
69
|
+
aside?: ReactNode;
|
|
70
|
+
children: ReactNode;
|
|
71
|
+
}) {
|
|
72
|
+
return (
|
|
73
|
+
<section className="border-border border-t px-5 py-4">
|
|
74
|
+
<div className="mb-2 flex items-baseline justify-between gap-3">
|
|
75
|
+
<h3 className="text-[13px] font-semibold">{title}</h3>
|
|
76
|
+
{aside}
|
|
77
|
+
</div>
|
|
78
|
+
{children}
|
|
79
|
+
</section>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function AiCheck({
|
|
84
|
+
classification,
|
|
85
|
+
}: {
|
|
86
|
+
classification: NonNullable<MessageDetail["aiClassification"]>;
|
|
87
|
+
}) {
|
|
88
|
+
const score = Math.round(classification.spamConfidence * 100);
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<div className="border-border bg-surface-sunken/60 rounded-lg border p-3.5">
|
|
92
|
+
<div className="flex items-center gap-2.5">
|
|
93
|
+
<span
|
|
94
|
+
className={cn(
|
|
95
|
+
"grid size-8 shrink-0 place-items-center rounded-full",
|
|
96
|
+
classification.spam
|
|
97
|
+
? "bg-destructive/12 text-destructive"
|
|
98
|
+
: "bg-success/12 text-success"
|
|
99
|
+
)}
|
|
100
|
+
>
|
|
101
|
+
{classification.spam ? (
|
|
102
|
+
<ShieldAlert className="size-4" />
|
|
103
|
+
) : (
|
|
104
|
+
<ShieldCheck className="size-4" />
|
|
105
|
+
)}
|
|
106
|
+
</span>
|
|
107
|
+
<div className="min-w-0 flex-1">
|
|
108
|
+
<p className="text-[13px] font-semibold">
|
|
109
|
+
{classification.spam ? "Looks like spam" : "Looks legitimate"}
|
|
110
|
+
</p>
|
|
111
|
+
<p className="text-muted-foreground text-xs">
|
|
112
|
+
Spam likelihood {score}%
|
|
113
|
+
</p>
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
<div
|
|
117
|
+
className="bg-muted mt-3 h-1.5 overflow-hidden rounded-full"
|
|
118
|
+
aria-hidden="true"
|
|
119
|
+
>
|
|
120
|
+
<div
|
|
121
|
+
className={cn(
|
|
122
|
+
"h-full rounded-full",
|
|
123
|
+
classification.spam ? "bg-destructive" : "bg-success"
|
|
124
|
+
)}
|
|
125
|
+
style={{ width: `${Math.max(score, 2)}%` }}
|
|
126
|
+
/>
|
|
127
|
+
</div>
|
|
128
|
+
<p className="mt-3 text-[13px] leading-5">{classification.reason}</p>
|
|
129
|
+
<p className="text-muted-foreground mt-2 font-mono text-[11px]">
|
|
130
|
+
{classification.model} ·{" "}
|
|
131
|
+
{format(new Date(classification.processedAt), "MMM d, HH:mm")}
|
|
132
|
+
</p>
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const MAX_DISPLAY_DELAY_MS = 7 * 24 * 3_600_000;
|
|
138
|
+
|
|
139
|
+
function formatDelay(ms: number) {
|
|
140
|
+
if (ms > MAX_DISPLAY_DELAY_MS) return "> 7 d";
|
|
141
|
+
|
|
142
|
+
if (ms < 1000) return `${ms} ms`;
|
|
143
|
+
|
|
144
|
+
if (ms < 60_000) return `${Math.round(ms / 1000)} s`;
|
|
145
|
+
|
|
146
|
+
if (ms < 3_600_000) return `${Math.round(ms / 60_000)} min`;
|
|
147
|
+
|
|
148
|
+
return `${(ms / 3_600_000).toFixed(1)} h`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const ipKindLabels: Record<IpKind, string> = {
|
|
152
|
+
public: "Public",
|
|
153
|
+
private: "Private network",
|
|
154
|
+
loopback: "Loopback",
|
|
155
|
+
reserved: "Reserved range",
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
function IpAddress({ ip }: { ip: string }) {
|
|
159
|
+
const kind = ipKind(ip);
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<span className="inline-flex flex-wrap items-center gap-x-1.5 gap-y-0.5">
|
|
163
|
+
<span className="font-mono text-[11.5px] whitespace-nowrap">{ip}</span>
|
|
164
|
+
<span
|
|
165
|
+
className={cn(
|
|
166
|
+
"rounded px-1 py-px text-[10px] font-medium whitespace-nowrap",
|
|
167
|
+
kind === "public"
|
|
168
|
+
? "bg-info/10 text-info"
|
|
169
|
+
: "bg-muted text-muted-foreground"
|
|
170
|
+
)}
|
|
171
|
+
>
|
|
172
|
+
{ipKindLabels[kind]}
|
|
173
|
+
</span>
|
|
174
|
+
</span>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function HopDelay({ hop }: { hop: ReceivedHop }) {
|
|
179
|
+
if (hop.delayMs === null) return null;
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<span
|
|
183
|
+
className="text-muted-foreground shrink-0 text-[11px] tabular-nums"
|
|
184
|
+
title={
|
|
185
|
+
hop.skewMs === null
|
|
186
|
+
? undefined
|
|
187
|
+
: "This server's clock is behind the previous one"
|
|
188
|
+
}
|
|
189
|
+
>
|
|
190
|
+
+{formatDelay(hop.delayMs)}
|
|
191
|
+
{hop.skewMs !== null && <> (clock skew −{formatDelay(-hop.skewMs)})</>}
|
|
192
|
+
</span>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function DeliveryPath({
|
|
197
|
+
hops,
|
|
198
|
+
transit,
|
|
199
|
+
deliveredAt,
|
|
200
|
+
}: {
|
|
201
|
+
hops: ReceivedHop[];
|
|
202
|
+
transit: ReturnType<typeof transitTime>;
|
|
203
|
+
deliveredAt: Date;
|
|
204
|
+
}) {
|
|
205
|
+
if (!hops.length) {
|
|
206
|
+
return (
|
|
207
|
+
<p className="text-muted-foreground text-xs">
|
|
208
|
+
No Received headers in this message.
|
|
209
|
+
</p>
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const arrival = hops.find((hop) => hop.trusted)?.at;
|
|
214
|
+
|
|
215
|
+
const mailboxDelay = arrival
|
|
216
|
+
? deliveredAt.getTime() - arrival.getTime()
|
|
217
|
+
: null;
|
|
218
|
+
|
|
219
|
+
return (
|
|
220
|
+
<>
|
|
221
|
+
<ol className="relative">
|
|
222
|
+
{hops.map((hop, index) => (
|
|
223
|
+
<li
|
|
224
|
+
key={index}
|
|
225
|
+
className="relative grid grid-cols-[1.25rem_minmax(0,1fr)] gap-x-2.5 pb-3.5 last:pb-0"
|
|
226
|
+
>
|
|
227
|
+
<span aria-hidden="true" className="relative flex justify-center">
|
|
228
|
+
<span
|
|
229
|
+
className={cn(
|
|
230
|
+
"bg-surface z-10 mt-1 size-2.5 rounded-full border-2",
|
|
231
|
+
hop.trusted ? "border-success" : "border-muted-foreground/50"
|
|
232
|
+
)}
|
|
233
|
+
/>
|
|
234
|
+
{index < hops.length - 1 && (
|
|
235
|
+
<span className="bg-border absolute top-3.5 bottom-[-0.25rem] w-px" />
|
|
236
|
+
)}
|
|
237
|
+
</span>
|
|
238
|
+
<div className="min-w-0 text-xs">
|
|
239
|
+
<div className="flex items-baseline justify-between gap-3">
|
|
240
|
+
<p
|
|
241
|
+
className="min-w-0 truncate font-medium"
|
|
242
|
+
title={hop.by ?? undefined}
|
|
243
|
+
>
|
|
244
|
+
{hop.by ?? "Unknown server"}
|
|
245
|
+
</p>
|
|
246
|
+
<HopDelay hop={hop} />
|
|
247
|
+
</div>
|
|
248
|
+
<p className="text-muted-foreground mt-0.5 [overflow-wrap:anywhere]">
|
|
249
|
+
from {hop.from ?? "unknown"}
|
|
250
|
+
{hop.reverseDns && <> · rDNS {hop.reverseDns}</>}
|
|
251
|
+
</p>
|
|
252
|
+
<div className="text-muted-foreground mt-1 flex flex-wrap items-center gap-x-2.5 gap-y-1">
|
|
253
|
+
{hop.trusted ? (
|
|
254
|
+
<span className="text-success inline-flex items-center gap-1 font-medium">
|
|
255
|
+
<BadgeCheck className="size-3" />
|
|
256
|
+
Verified by Cloudflare
|
|
257
|
+
</span>
|
|
258
|
+
) : (
|
|
259
|
+
<span className="text-[11px]">Reported by sender</span>
|
|
260
|
+
)}
|
|
261
|
+
{hop.ip && <IpAddress ip={hop.ip} />}
|
|
262
|
+
{hop.protocol && (
|
|
263
|
+
<span className="font-mono text-[11px]">{hop.protocol}</span>
|
|
264
|
+
)}
|
|
265
|
+
{hop.tls ? (
|
|
266
|
+
<span className="text-success inline-flex items-center gap-1">
|
|
267
|
+
<Lock className="size-3" />
|
|
268
|
+
{hop.tls}
|
|
269
|
+
</span>
|
|
270
|
+
) : (
|
|
271
|
+
<span className="inline-flex items-center gap-1">
|
|
272
|
+
<LockOpen className="size-3" />
|
|
273
|
+
{hop.trusted ? "TLS not reported" : "No TLS noted"}
|
|
274
|
+
</span>
|
|
275
|
+
)}
|
|
276
|
+
{hop.at && (
|
|
277
|
+
<span className="tabular-nums">
|
|
278
|
+
{format(hop.at, "HH:mm:ss")}
|
|
279
|
+
</span>
|
|
280
|
+
)}
|
|
281
|
+
</div>
|
|
282
|
+
</div>
|
|
283
|
+
</li>
|
|
284
|
+
))}
|
|
285
|
+
</ol>
|
|
286
|
+
<p className="text-muted-foreground mt-3 text-[11px]">
|
|
287
|
+
{[
|
|
288
|
+
`${hops.length} hop${hops.length === 1 ? "" : "s"}`,
|
|
289
|
+
transit &&
|
|
290
|
+
`in transit ${formatDelay(transit.ms)}${transit.basis === "date-header" ? " since the sender's Date header" : ""}`,
|
|
291
|
+
mailboxDelay !== null &&
|
|
292
|
+
mailboxDelay >= 0 &&
|
|
293
|
+
`delivered to the mailbox +${formatDelay(mailboxDelay)}`,
|
|
294
|
+
]
|
|
295
|
+
.filter(Boolean)
|
|
296
|
+
.join(" · ")}
|
|
297
|
+
</p>
|
|
298
|
+
</>
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function MimeTree({ parts }: { parts: MimePart[] }) {
|
|
303
|
+
return (
|
|
304
|
+
<ul className="space-y-1 text-xs">
|
|
305
|
+
{parts.map((part, index) => (
|
|
306
|
+
<li
|
|
307
|
+
key={index}
|
|
308
|
+
className="flex items-baseline gap-2"
|
|
309
|
+
style={{ paddingLeft: `${part.depth * 0.875}rem` }}
|
|
310
|
+
>
|
|
311
|
+
<span className="font-mono text-[11.5px]">{part.contentType}</span>
|
|
312
|
+
<span className="text-muted-foreground min-w-0 truncate">
|
|
313
|
+
{[
|
|
314
|
+
part.filename,
|
|
315
|
+
part.charset,
|
|
316
|
+
part.encoding,
|
|
317
|
+
part.contentType.startsWith("multipart/")
|
|
318
|
+
? null
|
|
319
|
+
: formatBytes(part.bytes),
|
|
320
|
+
]
|
|
321
|
+
.filter(Boolean)
|
|
322
|
+
.join(" · ")}
|
|
323
|
+
</span>
|
|
324
|
+
</li>
|
|
325
|
+
))}
|
|
326
|
+
</ul>
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function DetailRows({ rows }: { rows: [string, ReactNode][] }) {
|
|
331
|
+
return (
|
|
332
|
+
<dl className="grid grid-cols-[6.5rem_minmax(0,1fr)] gap-x-3 gap-y-1.5 text-xs">
|
|
333
|
+
{rows.map(([term, value]) => (
|
|
334
|
+
<div key={term} className="contents">
|
|
335
|
+
<dt className="text-muted-foreground">{term}</dt>
|
|
336
|
+
<dd className="[overflow-wrap:anywhere]">{value}</dd>
|
|
337
|
+
</div>
|
|
338
|
+
))}
|
|
339
|
+
</dl>
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function OriginalMessageBody({
|
|
344
|
+
mailboxId,
|
|
345
|
+
message,
|
|
346
|
+
}: {
|
|
347
|
+
mailboxId: string;
|
|
348
|
+
message: MessageDetail;
|
|
349
|
+
}) {
|
|
350
|
+
const [copied, setCopied] = useState(false);
|
|
351
|
+
const sourceUrl = originalSourceUrl(mailboxId, message.id);
|
|
352
|
+
|
|
353
|
+
const source = useQuery({
|
|
354
|
+
queryKey: ["message-original", mailboxId, message.id],
|
|
355
|
+
queryFn: async () => {
|
|
356
|
+
const response = await fetch(sourceUrl);
|
|
357
|
+
|
|
358
|
+
if (!response.ok) {
|
|
359
|
+
throw new Error(
|
|
360
|
+
(await responseMessage(response)) ??
|
|
361
|
+
`Original message failed (${response.status})`
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
return response.text();
|
|
366
|
+
},
|
|
367
|
+
staleTime: Infinity,
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
const details = useQuery({
|
|
371
|
+
queryKey: ["message-authentication", mailboxId, message.id],
|
|
372
|
+
queryFn: async () =>
|
|
373
|
+
responseJson(
|
|
374
|
+
await mailApi.api.mail.messages[":messageId"].authentication.$get({
|
|
375
|
+
param: { messageId: message.id },
|
|
376
|
+
query: { mailboxId },
|
|
377
|
+
})
|
|
378
|
+
),
|
|
379
|
+
staleTime: Infinity,
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
const authentication = details.data?.authentication ?? null;
|
|
383
|
+
const security = details.data?.security ?? null;
|
|
384
|
+
const original = details.data?.original;
|
|
385
|
+
const senderIntel = details.data?.senderIntel ?? message.senderIntel;
|
|
386
|
+
|
|
387
|
+
const parsed = useMemo(() => {
|
|
388
|
+
if (!source.data) return null;
|
|
389
|
+
const hops = receivedHops(source.data);
|
|
390
|
+
|
|
391
|
+
return {
|
|
392
|
+
hops,
|
|
393
|
+
transit: transitTime(source.data, hops),
|
|
394
|
+
sender: originalSenderDetails(source.data, authentication, hops),
|
|
395
|
+
parts: mimeStructure(source.data),
|
|
396
|
+
};
|
|
397
|
+
}, [source.data, authentication]);
|
|
398
|
+
|
|
399
|
+
const sourceBytes = useMemo(
|
|
400
|
+
() =>
|
|
401
|
+
source.data ? new TextEncoder().encode(source.data).byteLength : null,
|
|
402
|
+
[source.data]
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
function senderRows(sender: NonNullable<typeof parsed>["sender"]) {
|
|
406
|
+
const rows: [string, ReactNode][] = [
|
|
407
|
+
["Return-Path", sender.returnPath ?? "—"],
|
|
408
|
+
];
|
|
409
|
+
|
|
410
|
+
if (
|
|
411
|
+
original?.envelopeTo &&
|
|
412
|
+
!message.toAddresses.includes(original.envelopeTo)
|
|
413
|
+
) {
|
|
414
|
+
rows.push(["Envelope to", original.envelopeTo]);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
rows.push([
|
|
418
|
+
"Sending IP",
|
|
419
|
+
sender.senderIp ? (
|
|
420
|
+
// oxlint-disable-next-line react/jsx-key -- a [label, value] row, rendered with the label as key
|
|
421
|
+
<IpAddress ip={sender.senderIp} />
|
|
422
|
+
) : (
|
|
423
|
+
"—"
|
|
424
|
+
),
|
|
425
|
+
]);
|
|
426
|
+
|
|
427
|
+
if (authentication?.helo) rows.push(["HELO", authentication.helo]);
|
|
428
|
+
|
|
429
|
+
if (senderIntel?.ip) rows.push(...senderIntelRows(senderIntel));
|
|
430
|
+
|
|
431
|
+
if (security?.mailedBy) rows.push(["Mailed-by", security.mailedBy]);
|
|
432
|
+
|
|
433
|
+
if (security?.signedBy) rows.push(["Signed-by", security.signedBy]);
|
|
434
|
+
|
|
435
|
+
if (message.replyToAddresses.length) {
|
|
436
|
+
rows.push(["Reply-To", message.replyToAddresses.join(", ")]);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (sender.mailer) rows.push(["Mailer", sender.mailer]);
|
|
440
|
+
|
|
441
|
+
if (sender.listId) rows.push(["List", sender.listId]);
|
|
442
|
+
|
|
443
|
+
if (security?.listUnsubscribe) {
|
|
444
|
+
rows.push(["Unsubscribe", unsubscribeSummary(security.listUnsubscribe)]);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (sender.precedence) rows.push(["Precedence", sender.precedence]);
|
|
448
|
+
|
|
449
|
+
return rows;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
async function copySource() {
|
|
453
|
+
if (!source.data) return;
|
|
454
|
+
await navigator.clipboard.writeText(source.data);
|
|
455
|
+
setCopied(true);
|
|
456
|
+
window.setTimeout(() => setCopied(false), 2000);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
return (
|
|
460
|
+
<div className="min-h-0 flex-1 overflow-y-auto">
|
|
461
|
+
{original && (
|
|
462
|
+
<dl className="grid grid-cols-[5.5rem_minmax(0,1fr)] gap-x-3 gap-y-1.5 px-5 pb-4 text-xs">
|
|
463
|
+
<dt className="text-muted-foreground">From</dt>
|
|
464
|
+
<dd className="[overflow-wrap:anywhere]">{original.from}</dd>
|
|
465
|
+
<dt className="text-muted-foreground">To</dt>
|
|
466
|
+
<dd className="[overflow-wrap:anywhere]">{original.to.join(", ")}</dd>
|
|
467
|
+
<dt className="text-muted-foreground">Received</dt>
|
|
468
|
+
<dd>
|
|
469
|
+
{format(
|
|
470
|
+
new Date(original.receivedAt),
|
|
471
|
+
"EEE, MMM d, yyyy 'at' HH:mm:ss"
|
|
472
|
+
)}
|
|
473
|
+
</dd>
|
|
474
|
+
<dt className="text-muted-foreground">Message-ID</dt>
|
|
475
|
+
<dd className="font-mono text-[11px] [overflow-wrap:anywhere]">
|
|
476
|
+
{original.messageId ?? "Unavailable"}
|
|
477
|
+
</dd>
|
|
478
|
+
</dl>
|
|
479
|
+
)}
|
|
480
|
+
|
|
481
|
+
<div className="border-border lg:divide-border grid border-t lg:grid-cols-2 lg:divide-x [&>div>section:first-child]:border-t-0">
|
|
482
|
+
<div className="min-w-0">
|
|
483
|
+
<Section
|
|
484
|
+
title="AI check"
|
|
485
|
+
aside={<Sparkles className="text-muted-foreground size-3.5" />}
|
|
486
|
+
>
|
|
487
|
+
{message.aiClassification ? (
|
|
488
|
+
<AiCheck classification={message.aiClassification} />
|
|
489
|
+
) : (
|
|
490
|
+
<p className="text-muted-foreground text-xs">
|
|
491
|
+
This message was not checked by AI sorting.
|
|
492
|
+
</p>
|
|
493
|
+
)}
|
|
494
|
+
</Section>
|
|
495
|
+
|
|
496
|
+
<Section
|
|
497
|
+
title="Authentication"
|
|
498
|
+
aside={
|
|
499
|
+
authentication?.authservId ? (
|
|
500
|
+
<span className="text-muted-foreground font-mono text-[11px]">
|
|
501
|
+
{authentication.authservId}
|
|
502
|
+
</span>
|
|
503
|
+
) : undefined
|
|
504
|
+
}
|
|
505
|
+
>
|
|
506
|
+
{details.isLoading ? (
|
|
507
|
+
<p className="text-muted-foreground flex items-center gap-2 py-2 text-xs">
|
|
508
|
+
<LoaderCircle className="size-3.5 animate-spin" /> Reading
|
|
509
|
+
authentication results…
|
|
510
|
+
</p>
|
|
511
|
+
) : details.isError ? (
|
|
512
|
+
<p className="text-destructive text-xs">
|
|
513
|
+
{details.error.message}
|
|
514
|
+
</p>
|
|
515
|
+
) : (
|
|
516
|
+
<SenderAuthentication authentication={authentication} />
|
|
517
|
+
)}
|
|
518
|
+
</Section>
|
|
519
|
+
|
|
520
|
+
{parsed && (
|
|
521
|
+
<Section title="Sender">
|
|
522
|
+
<DetailRows rows={parsed ? senderRows(parsed.sender) : []} />
|
|
523
|
+
</Section>
|
|
524
|
+
)}
|
|
525
|
+
</div>
|
|
526
|
+
<div className="min-w-0">
|
|
527
|
+
<Section title="Delivery path">
|
|
528
|
+
{parsed ? (
|
|
529
|
+
<DeliveryPath
|
|
530
|
+
hops={parsed.hops}
|
|
531
|
+
transit={parsed.transit}
|
|
532
|
+
deliveredAt={new Date(message.timelineAt)}
|
|
533
|
+
/>
|
|
534
|
+
) : (
|
|
535
|
+
<p className="text-muted-foreground text-xs">Loading…</p>
|
|
536
|
+
)}
|
|
537
|
+
</Section>
|
|
538
|
+
{parsed && parsed.parts.length > 0 && (
|
|
539
|
+
<Section title="Structure">
|
|
540
|
+
<MimeTree parts={parsed.parts} />
|
|
541
|
+
</Section>
|
|
542
|
+
)}
|
|
543
|
+
</div>
|
|
544
|
+
</div>
|
|
545
|
+
|
|
546
|
+
<Section
|
|
547
|
+
title="Raw source"
|
|
548
|
+
aside={
|
|
549
|
+
<div className="flex items-center gap-1">
|
|
550
|
+
{sourceBytes !== null && (
|
|
551
|
+
<span className="text-muted-foreground mr-1 text-[11px] tabular-nums">
|
|
552
|
+
{sourceBytes.toLocaleString()} bytes
|
|
553
|
+
</span>
|
|
554
|
+
)}
|
|
555
|
+
<Button
|
|
556
|
+
variant="ghost"
|
|
557
|
+
size="xs"
|
|
558
|
+
onClick={() => void copySource()}
|
|
559
|
+
disabled={!source.data}
|
|
560
|
+
>
|
|
561
|
+
{copied ? <Check /> : <Copy />} {copied ? "Copied" : "Copy"}
|
|
562
|
+
</Button>
|
|
563
|
+
<a
|
|
564
|
+
className={buttonVariants({ variant: "ghost", size: "xs" })}
|
|
565
|
+
href={sourceUrl}
|
|
566
|
+
download={`${message.id}.eml`}
|
|
567
|
+
>
|
|
568
|
+
<Download /> Download
|
|
569
|
+
</a>
|
|
570
|
+
</div>
|
|
571
|
+
}
|
|
572
|
+
>
|
|
573
|
+
{source.isLoading ? (
|
|
574
|
+
<div className="bg-surface-sunken text-muted-foreground grid h-40 place-items-center rounded-md">
|
|
575
|
+
<LoaderCircle className="size-4 animate-spin" />
|
|
576
|
+
</div>
|
|
577
|
+
) : source.isError ? (
|
|
578
|
+
<p className="text-destructive text-xs">{source.error.message}</p>
|
|
579
|
+
) : (
|
|
580
|
+
<pre className="bg-surface-sunken ring-border max-h-[50dvh] overflow-auto rounded-md p-3 font-mono text-[11px] leading-[1.6] whitespace-pre ring-1">
|
|
581
|
+
{source.data}
|
|
582
|
+
</pre>
|
|
583
|
+
)}
|
|
584
|
+
</Section>
|
|
585
|
+
</div>
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/** Original source, authentication results and the AI check, beside the conversation. */
|
|
590
|
+
export function OriginalMessageSheet({
|
|
591
|
+
mailboxId,
|
|
592
|
+
message,
|
|
593
|
+
onClose,
|
|
594
|
+
}: {
|
|
595
|
+
mailboxId: string;
|
|
596
|
+
message: MessageDetail | null;
|
|
597
|
+
onClose: () => void;
|
|
598
|
+
}) {
|
|
599
|
+
return (
|
|
600
|
+
<Sheet open={Boolean(message)} onOpenChange={(open) => !open && onClose()}>
|
|
601
|
+
<SheetContent
|
|
602
|
+
side="right"
|
|
603
|
+
className="w-full gap-0 data-[side=right]:sm:max-w-[min(72rem,94vw)]"
|
|
604
|
+
>
|
|
605
|
+
{message && (
|
|
606
|
+
<>
|
|
607
|
+
<SheetHeader className="px-5 pt-5 pb-3">
|
|
608
|
+
<SheetTitle>Original message</SheetTitle>
|
|
609
|
+
<SheetDescription className="truncate pr-8">
|
|
610
|
+
{message.subject || "(no subject)"}
|
|
611
|
+
</SheetDescription>
|
|
612
|
+
</SheetHeader>
|
|
613
|
+
<OriginalMessageBody mailboxId={mailboxId} message={message} />
|
|
614
|
+
</>
|
|
615
|
+
)}
|
|
616
|
+
</SheetContent>
|
|
617
|
+
</Sheet>
|
|
618
|
+
);
|
|
619
|
+
}
|