@open-workspace/email 0.3.0 → 0.4.1

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 (221) hide show
  1. package/README.md +22 -22
  2. package/alchemy/index.ts +273 -0
  3. package/drizzle/mailbox/0000_puzzling_dracula.sql +149 -0
  4. package/drizzle/mailbox/0001_mute_jack_flag.sql +12 -0
  5. package/drizzle/mailbox/meta/0000_snapshot.json +1002 -0
  6. package/drizzle/mailbox/meta/0001_snapshot.json +1002 -0
  7. package/drizzle/mailbox/meta/_journal.json +20 -0
  8. package/drizzle/mailbox/migrations.js +12 -0
  9. package/index.ts +3 -1
  10. package/migrations/{0000_email.sql → 0000_dry_moon_knight.sql} +26 -20
  11. package/migrations/meta/0000_snapshot.json +125 -109
  12. package/migrations/meta/_journal.json +2 -2
  13. package/package.json +74 -68
  14. package/shared/attachment-preview.ts +37 -27
  15. package/shared/folder-order.ts +106 -0
  16. package/shared/mail-authentication.ts +8 -3
  17. package/shared/mail-feedback.ts +18 -25
  18. package/shared/mail-headers.ts +114 -39
  19. package/shared/mail-import.ts +38 -0
  20. package/shared/mail-path.ts +42 -0
  21. package/shared/mail-received.ts +174 -31
  22. package/shared/mail-remote.ts +59 -2
  23. package/shared/mail-sender-intel.ts +22 -4
  24. package/shared/mail.ts +77 -28
  25. package/shared/module.ts +33 -0
  26. package/shared/office-preview.ts +14 -2
  27. package/shared/pdfjs-assets.ts +35 -0
  28. package/shared/permissions.ts +73 -0
  29. package/shared/webhooks.ts +41 -0
  30. package/src/admin/blocked-senders.tsx +189 -0
  31. package/src/client.tsx +97 -0
  32. package/src/lib/mail-api.ts +9 -0
  33. package/src/mail/attachment-preview-dialog.tsx +161 -0
  34. package/src/mail/blocked-senders.tsx +138 -0
  35. package/src/mail/compose-window-chrome.tsx +194 -0
  36. package/src/mail/compose-window.tsx +486 -0
  37. package/src/mail/composer-asset-bookmarks.ts +409 -0
  38. package/src/mail/composer-asset.tsx +229 -0
  39. package/src/mail/composer-attachment-list.tsx +138 -0
  40. package/src/mail/composer-editor-document.ts +65 -0
  41. package/src/mail/composer-editor.tsx +284 -0
  42. package/src/mail/composer-linked-attachment-text.ts +12 -0
  43. package/src/mail/composer-recipient-fields.tsx +165 -0
  44. package/src/mail/composer-recipients.ts +208 -0
  45. package/src/mail/composer-session.ts +562 -0
  46. package/src/mail/composer-toolbar.tsx +303 -0
  47. package/src/mail/composer-upload-client.ts +105 -0
  48. package/src/mail/composer-upload-progress.ts +53 -0
  49. package/src/mail/conversation-list.tsx +550 -0
  50. package/src/mail/conversation-loading-skeleton.tsx +119 -0
  51. package/src/mail/conversation-message.tsx +346 -0
  52. package/src/mail/conversation-reply.tsx +470 -0
  53. package/src/mail/conversation-selection-toolbar.tsx +322 -0
  54. package/src/mail/conversation-view.tsx +437 -0
  55. package/src/mail/delivery-indicator.tsx +272 -0
  56. package/src/mail/email-html-body.tsx +203 -0
  57. package/src/mail/folder-glyph.tsx +46 -0
  58. package/src/mail/folder-manager.tsx +532 -0
  59. package/src/mail/format-bytes.ts +7 -0
  60. package/src/mail/mail-app-bar.tsx +253 -0
  61. package/src/mail/mail-background.tsx +12 -0
  62. package/src/mail/mail-dock.tsx +137 -0
  63. package/src/mail/mail-folders.ts +44 -0
  64. package/src/mail/mail-layout.css +236 -0
  65. package/src/mail/mail-location.ts +73 -0
  66. package/src/mail/mail-mailbox-sheet.tsx +275 -0
  67. package/src/mail/mail-nav-rail.tsx +129 -0
  68. package/src/mail/mail-nav.tsx +324 -0
  69. package/src/mail/mail-prefetch.ts +59 -0
  70. package/src/mail/mail-primitives.tsx +66 -0
  71. package/src/mail/mail-queries.ts +209 -0
  72. package/src/mail/mail-query-cache.ts +486 -0
  73. package/src/mail/mail-seed.ts +47 -0
  74. package/src/mail/mail-shell.tsx +126 -0
  75. package/src/mail/mailbox-ai-settings.tsx +185 -0
  76. package/src/mail/mailbox-realtime.tsx +251 -0
  77. package/src/mail/mailbox-route.tsx +15 -0
  78. package/src/mail/message-actions.tsx +353 -0
  79. package/src/mail/message-attachments.tsx +200 -0
  80. package/src/mail/message-format.ts +75 -0
  81. package/src/mail/message-header.tsx +260 -0
  82. package/src/mail/message-translation.tsx +225 -0
  83. package/src/mail/original-message-sheet.tsx +619 -0
  84. package/src/mail/original-message.ts +191 -0
  85. package/src/mail/outbound-notification.ts +53 -0
  86. package/src/mail/pane-splitter.tsx +117 -0
  87. package/src/mail/pdf-preview-toolbar.tsx +152 -0
  88. package/src/mail/pdf-preview.css +44 -0
  89. package/src/mail/pdf-preview.tsx +156 -0
  90. package/src/mail/pdf-translation-layout.ts +95 -0
  91. package/src/mail/print-message.ts +92 -0
  92. package/src/mail/reader-pane.tsx +535 -0
  93. package/src/mail/recipient-combobox.tsx +335 -0
  94. package/src/mail/recipient-field-row.tsx +34 -0
  95. package/src/mail/reply-to-warning.tsx +50 -0
  96. package/src/mail/sanitize-email-html.ts +430 -0
  97. package/src/mail/sender-actions.tsx +149 -0
  98. package/src/mail/sender-authentication.tsx +485 -0
  99. package/src/mail/sender-dialogs.tsx +384 -0
  100. package/src/mail/sender-security.tsx +545 -0
  101. package/src/mail/toolbar-tooltip.tsx +29 -0
  102. package/src/mail/translation-html.ts +49 -0
  103. package/src/mail/translation-language.ts +21 -0
  104. package/src/mail/types.ts +53 -0
  105. package/src/mail/unread-document-indicator.tsx +60 -0
  106. package/src/mail/use-compose-submission.ts +208 -0
  107. package/src/mail/use-composer-attachment-preflight.ts +184 -0
  108. package/src/mail/use-composer-submission.ts +117 -0
  109. package/src/mail/use-conversation-selection.ts +186 -0
  110. package/src/mail/use-mail-controller.ts +427 -0
  111. package/src/mail/use-mail-data.ts +279 -0
  112. package/src/mail/use-mail-safety.ts +155 -0
  113. package/src/mail/use-mail-send.ts +142 -0
  114. package/src/mail/use-pdf-translation-overlay.ts +156 -0
  115. package/src/mail/use-pdf-translation.ts +100 -0
  116. package/src/mail/use-pdf-viewer.ts +215 -0
  117. package/src/mail/use-reply-submission.ts +114 -0
  118. package/src/mail/use-sanitized-email-html.ts +20 -0
  119. package/src/mail/use-visible-message-read.ts +138 -0
  120. package/src/pwa/push-subscription.ts +151 -0
  121. package/src/settings/mail-apps-page.tsx +235 -0
  122. package/src/settings/notifications-page.tsx +291 -0
  123. package/worker/admin/blocked-sender-routes.ts +166 -0
  124. package/worker/admin/schemas.ts +11 -0
  125. package/worker/bindings.d.ts +14 -10
  126. package/worker/db/schema.ts +63 -40
  127. package/worker/jmap/eventsource.ts +84 -16
  128. package/worker/jmap/methods.ts +1630 -524
  129. package/worker/jmap/push-types.ts +27 -0
  130. package/worker/jmap/push.ts +140 -56
  131. package/worker/jmap/routes.ts +366 -105
  132. package/worker/mail/access.ts +258 -21
  133. package/worker/mail/ai-classification.ts +36 -20
  134. package/worker/mail/ai-translation.ts +13 -6
  135. package/worker/mail/auth-headers.ts +395 -137
  136. package/worker/mail/bimi.ts +200 -73
  137. package/worker/mail/bootstrap.ts +79 -0
  138. package/worker/mail/capped-body.ts +36 -0
  139. package/worker/mail/classification-signals.ts +35 -25
  140. package/worker/mail/conversation-cursor.ts +30 -19
  141. package/worker/mail/delivery-events.ts +88 -62
  142. package/worker/mail/delivery-facts.ts +46 -10
  143. package/worker/mail/demo-routes.ts +34 -10
  144. package/worker/mail/doh.ts +62 -23
  145. package/worker/mail/downloads.ts +75 -40
  146. package/worker/mail/edge-cache.ts +155 -0
  147. package/worker/mail/header-metadata.ts +88 -22
  148. package/worker/mail/impersonation.ts +160 -38
  149. package/worker/mail/import-routes.ts +313 -0
  150. package/worker/mail/inbound-delivery.ts +19 -9
  151. package/worker/mail/inbound-threading.ts +18 -8
  152. package/worker/mail/inbound.ts +82 -40
  153. package/worker/mail/ip-intel.ts +110 -27
  154. package/worker/mail/isolate-cache.ts +35 -0
  155. package/worker/mail/link-domains.ts +29 -7
  156. package/worker/mail/mailbox-deletion.ts +10 -4
  157. package/worker/mail/mailbox-directory.ts +16 -6
  158. package/worker/mail/mailing-list.ts +94 -39
  159. package/worker/mail/message-security.ts +90 -15
  160. package/worker/mail/message-view.ts +18 -6
  161. package/worker/mail/office-conversion.ts +31 -9
  162. package/worker/mail/office-preview-container.ts +40 -13
  163. package/worker/mail/office-preview-queue.ts +76 -32
  164. package/worker/mail/org-domain.ts +8 -1
  165. package/worker/mail/outbound-content.ts +71 -26
  166. package/worker/mail/outbound-delivery.ts +31 -17
  167. package/worker/mail/outbound-service.ts +48 -30
  168. package/worker/mail/outbound-threading.ts +30 -17
  169. package/worker/mail/outbound.ts +97 -70
  170. package/worker/mail/outgoing-context.ts +25 -15
  171. package/worker/mail/participants.ts +44 -29
  172. package/worker/mail/push-notifications.ts +271 -173
  173. package/worker/mail/quote-parser.ts +21 -10
  174. package/worker/mail/r2-presigned-urls.ts +31 -25
  175. package/worker/mail/receive.ts +23 -11
  176. package/worker/mail/recipients.ts +6 -1
  177. package/worker/mail/remote-proxy.ts +187 -31
  178. package/worker/mail/remote-routes.ts +87 -0
  179. package/worker/mail/remote-token.ts +104 -0
  180. package/worker/mail/repeat.ts +19 -0
  181. package/worker/mail/reply-plan.ts +62 -33
  182. package/worker/mail/rfc.ts +32 -7
  183. package/worker/mail/routes.ts +870 -541
  184. package/worker/mail/safety-routes.ts +328 -200
  185. package/worker/mail/schemas.ts +84 -105
  186. package/worker/mail/search.ts +1 -0
  187. package/worker/mail/security-settings.ts +41 -9
  188. package/worker/mail/sender-intel.ts +206 -51
  189. package/worker/mail/spamhaus.ts +92 -45
  190. package/worker/mail/unsubscribe.ts +76 -18
  191. package/worker/mail/uploads.ts +126 -93
  192. package/worker/mail/webhook-source.ts +35 -12
  193. package/worker/mail/workspace-safety.ts +97 -38
  194. package/worker/mailbox/demo-html.ts +7 -7
  195. package/worker/mailbox/demo-seed.ts +10 -44
  196. package/worker/mailbox/demo.ts +595 -225
  197. package/worker/mailbox/email-index.ts +53 -0
  198. package/worker/mailbox/folder-model.ts +53 -17
  199. package/worker/mailbox/import-placement.ts +88 -0
  200. package/worker/mailbox/inbox-counts.ts +106 -0
  201. package/worker/mailbox/index.ts +1734 -721
  202. package/worker/mailbox/jmap-store.ts +139 -35
  203. package/worker/mailbox/model.ts +8 -6
  204. package/worker/mailbox/office-preview-jobs.ts +56 -25
  205. package/worker/mailbox/schema.ts +87 -66
  206. package/worker/mailbox/senders.ts +176 -70
  207. package/worker/mcp/mail-action-tools.ts +128 -87
  208. package/worker/mcp/mail-compose-tools.ts +133 -82
  209. package/worker/mcp/mail-query-tools.ts +120 -71
  210. package/worker/mcp/mail-safety-tools.ts +321 -248
  211. package/worker/mcp/schemas.ts +43 -0
  212. package/worker/mcp/tools.ts +13 -10
  213. package/worker/module.ts +43 -18
  214. package/worker/sql.d.ts +8 -0
  215. package/alchemy.ts +0 -142
  216. package/containers/office-preview/Dockerfile +0 -10
  217. package/shared/mail-rules.ts +0 -156
  218. package/worker/admin/report-routes.ts +0 -164
  219. package/worker/mail/reported-messages.ts +0 -68
  220. package/worker/mailbox/migrations.ts +0 -10
  221. package/worker/mailbox/rules.ts +0 -110
@@ -0,0 +1,485 @@
1
+ import { cn } from "@open-workspace/core/ui";
2
+ import { ShieldAlert, ShieldCheck, ShieldQuestion } from "lucide-react";
3
+ import type { ReactNode } from "react";
4
+
5
+ import type {
6
+ AuthResult,
7
+ InboundAuthentication,
8
+ ListUnsubscribe,
9
+ SenderVerdict,
10
+ SenderVerdictReason,
11
+ UpstreamAuthenticationClaim,
12
+ } from "../../shared/mail-authentication";
13
+
14
+ const AUTHENTICATION_DOCS =
15
+ "https://developers.cloudflare.com/email-service/concepts/email-authentication/";
16
+
17
+ type Tone = "pass" | "fail" | "warn" | "neutral";
18
+
19
+ function resultTone(
20
+ value: AuthResult | "pass" | "fail" | "none" | null | undefined
21
+ ): Tone {
22
+ if (value === "pass") return "pass";
23
+
24
+ if (value === "fail" || value === "permerror") return "fail";
25
+
26
+ if (value === "softfail" || value === "temperror") return "warn";
27
+
28
+ return "neutral";
29
+ }
30
+
31
+ function Verdict({ tone, children }: { tone: Tone; children: ReactNode }) {
32
+ return (
33
+ <span
34
+ className={cn(
35
+ "inline-flex h-5 items-center rounded-full px-2 text-[11px] font-semibold tracking-wide whitespace-nowrap",
36
+ tone === "pass" && "bg-success/12 text-success",
37
+ tone === "fail" && "bg-destructive/12 text-destructive",
38
+ tone === "warn" && "bg-warning/18 text-amber-800 dark:text-amber-300",
39
+ tone === "neutral" && "bg-muted text-muted-foreground"
40
+ )}
41
+ >
42
+ {children}
43
+ </span>
44
+ );
45
+ }
46
+
47
+ function CheckRow({
48
+ label,
49
+ result,
50
+ href,
51
+ children,
52
+ }: {
53
+ label: string;
54
+ result: AuthResult | "pass" | "fail" | "none" | null;
55
+ href: string;
56
+ children?: ReactNode;
57
+ }) {
58
+ return (
59
+ <div className="grid grid-cols-[3.75rem_4.75rem_minmax(0,1fr)] items-baseline gap-x-3 py-2.5">
60
+ <dt className="text-muted-foreground text-xs font-medium">
61
+ <a
62
+ href={href}
63
+ target="_blank"
64
+ rel="noreferrer"
65
+ className="hover:text-foreground hover:underline"
66
+ >
67
+ {label}
68
+ </a>
69
+ </dt>
70
+ <dd>
71
+ <Verdict tone={resultTone(result)}>
72
+ {result ? result.toUpperCase() : "N/A"}
73
+ </Verdict>
74
+ </dd>
75
+ <dd className="min-w-0 text-xs leading-5 [overflow-wrap:anywhere] max-sm:col-span-2 max-sm:col-start-2 max-sm:mt-1">
76
+ {children}
77
+ </dd>
78
+ </div>
79
+ );
80
+ }
81
+
82
+ function Muted({ children }: { children: ReactNode }) {
83
+ return <span className="text-muted-foreground">{children}</span>;
84
+ }
85
+
86
+ function Mono({ children }: { children: ReactNode }) {
87
+ return <span className="font-mono text-[11.5px]">{children}</span>;
88
+ }
89
+
90
+ export const verdictCopy: Record<SenderVerdict, { title: string; tone: Tone }> =
91
+ {
92
+ verified: { title: "Verified sender", tone: "pass" },
93
+ unverified: { title: "Partially verified", tone: "neutral" },
94
+ suspicious: { title: "Unverified sender", tone: "warn" },
95
+ unavailable: { title: "Not checked", tone: "neutral" },
96
+ };
97
+
98
+ function verdictExplanation(
99
+ reason: SenderVerdictReason,
100
+ fromDomain: string | null
101
+ ) {
102
+ const domain = fromDomain ?? "the sender's domain";
103
+
104
+ switch (reason) {
105
+ case "dmarc_pass": {
106
+ return `DMARC passed: ${domain} authorized this message.`;
107
+ }
108
+
109
+ case "aligned_dkim": {
110
+ return `Signed by ${domain}. The domain publishes no DMARC policy.`;
111
+ }
112
+
113
+ case "forwarded_arc": {
114
+ return "The message was forwarded. The forwarder recorded passing results before the change.";
115
+ }
116
+
117
+ case "dmarc_fail": {
118
+ return `DMARC failed: nothing proves this message came from ${domain}.`;
119
+ }
120
+
121
+ case "no_aligned_pass": {
122
+ return `Neither the signature nor the sending server belongs to ${domain}.`;
123
+ }
124
+
125
+ case "partial": {
126
+ return `Some checks passed, but ${domain} does not publish a DMARC policy to confirm them.`;
127
+ }
128
+
129
+ case "not_cloudflare": {
130
+ return "This message did not arrive through Cloudflare Email Routing, so no receiver checks were recorded.";
131
+ }
132
+
133
+ case "missing_results": {
134
+ return "Cloudflare did not report authentication results for this message.";
135
+ }
136
+
137
+ default: {
138
+ const unexpected: never = reason;
139
+ throw new Error(`Unknown sender verdict reason: ${String(unexpected)}`);
140
+ }
141
+ }
142
+ }
143
+
144
+ function VerdictSummary({
145
+ authentication,
146
+ }: {
147
+ authentication: InboundAuthentication;
148
+ }) {
149
+ const copy = verdictCopy[authentication.verdict];
150
+
151
+ const Icon =
152
+ copy.tone === "pass"
153
+ ? ShieldCheck
154
+ : copy.tone === "warn"
155
+ ? ShieldAlert
156
+ : ShieldQuestion;
157
+
158
+ return (
159
+ <div className="border-border bg-surface-sunken/60 mb-1 flex items-start gap-2.5 rounded-lg border p-3">
160
+ <span
161
+ className={cn(
162
+ "grid size-7 shrink-0 place-items-center rounded-full",
163
+ copy.tone === "pass" && "bg-success/12 text-success",
164
+ copy.tone === "warn" &&
165
+ "bg-warning/18 text-amber-700 dark:text-amber-300",
166
+ copy.tone === "neutral" && "bg-muted text-muted-foreground"
167
+ )}
168
+ >
169
+ <Icon className="size-3.5" />
170
+ </span>
171
+ <div className="min-w-0 text-xs leading-5">
172
+ <p className="text-[13px] font-semibold">{copy.title}</p>
173
+ <p className="text-muted-foreground">
174
+ {verdictExplanation(
175
+ authentication.verdictReason,
176
+ authentication.fromDomain
177
+ )}
178
+ </p>
179
+ </div>
180
+ </div>
181
+ );
182
+ }
183
+
184
+ function listFormat(items: string[]) {
185
+ return new Intl.ListFormat("en", {
186
+ style: "long",
187
+ type: "conjunction",
188
+ }).format(items);
189
+ }
190
+
191
+ function claimSummary(claim: UpstreamAuthenticationClaim) {
192
+ return (
193
+ [
194
+ claim.spf && `SPF ${claim.spf}`,
195
+ claim.dkim && `DKIM ${claim.dkim}`,
196
+ claim.dmarc && `DMARC ${claim.dmarc}`,
197
+ ]
198
+ .filter(Boolean)
199
+ .join(", ") || "no results"
200
+ );
201
+ }
202
+
203
+ function SpfRow({ authentication }: { authentication: InboundAuthentication }) {
204
+ const { spf, spfHelo, remoteIp } = authentication;
205
+
206
+ return (
207
+ <CheckRow
208
+ label="SPF"
209
+ result={spf?.result ?? null}
210
+ href={`${AUTHENTICATION_DOCS}#spf-sender-policy-framework`}
211
+ >
212
+ {spf ? (
213
+ <>
214
+ {remoteIp && (
215
+ <>
216
+ with IP <Mono>{remoteIp}</Mono>{" "}
217
+ </>
218
+ )}
219
+ {spf.domain && (
220
+ <Muted>
221
+ · mailed-by {spf.domain}
222
+ {spf.aligned ? " (aligned)" : " (not aligned)"}
223
+ </Muted>
224
+ )}
225
+ {spfHelo && (
226
+ <div className="text-muted-foreground text-[11px]">
227
+ HELO {spfHelo.domain ?? authentication.helo ?? "check"}:{" "}
228
+ {spfHelo.result}
229
+ </div>
230
+ )}
231
+ </>
232
+ ) : (
233
+ <Muted>Not reported</Muted>
234
+ )}
235
+ </CheckRow>
236
+ );
237
+ }
238
+
239
+ function DkimRow({
240
+ authentication,
241
+ }: {
242
+ authentication: InboundAuthentication;
243
+ }) {
244
+ const signatures = [...authentication.dkim].sort(
245
+ (left, right) =>
246
+ Number(right.result === "pass") - Number(left.result === "pass") ||
247
+ Number(right.aligned) - Number(left.aligned)
248
+ );
249
+
250
+ const primary = signatures[0];
251
+
252
+ return (
253
+ <CheckRow
254
+ label="DKIM"
255
+ result={primary?.result ?? "none"}
256
+ href={`${AUTHENTICATION_DOCS}#dkim-domainkeys-identified-mail`}
257
+ >
258
+ {primary ? (
259
+ <ul className="space-y-0.5">
260
+ {signatures.map((signature, index) => (
261
+ <li key={`${signature.domain}-${index}`}>
262
+ {index === 0
263
+ ? "with domain "
264
+ : signature.result === "pass"
265
+ ? "Also signed by "
266
+ : `${signature.result.toUpperCase()}: signed by `}
267
+ <span className="font-medium">{signature.domain}</span>{" "}
268
+ <Muted>
269
+ (
270
+ {[
271
+ signature.selector && `selector ${signature.selector}`,
272
+ signature.aligned ? "aligned" : "not aligned",
273
+ ]
274
+ .filter(Boolean)
275
+ .join(", ")}
276
+ )
277
+ </Muted>
278
+ </li>
279
+ ))}
280
+ </ul>
281
+ ) : (
282
+ <Muted>The message was not signed</Muted>
283
+ )}
284
+ </CheckRow>
285
+ );
286
+ }
287
+
288
+ function DmarcRow({
289
+ authentication,
290
+ }: {
291
+ authentication: InboundAuthentication;
292
+ }) {
293
+ const { dmarc } = authentication;
294
+ const href = `${AUTHENTICATION_DOCS}#dmarc-domain-based-message-authentication-reporting--conformance`;
295
+
296
+ if (!dmarc) {
297
+ return (
298
+ <CheckRow label="DMARC" result={null} href={href}>
299
+ <Muted>Not reported</Muted>
300
+ </CheckRow>
301
+ );
302
+ }
303
+
304
+ const via = dmarc.alignedVia.map((method) => method.toUpperCase());
305
+
306
+ return (
307
+ <CheckRow label="DMARC" result={dmarc.result} href={href}>
308
+ {dmarc.result === "none" && !dmarc.policy ? (
309
+ <Muted>
310
+ {dmarc.headerFrom ?? "The domain"} publishes no DMARC policy
311
+ </Muted>
312
+ ) : (
313
+ <>
314
+ {dmarc.policy && (
315
+ <>
316
+ policy <span className="font-medium">{dmarc.policy}</span>
317
+ </>
318
+ )}
319
+ {via.length > 0 && <Muted> · aligned via {listFormat(via)}</Muted>}
320
+ {dmarc.policy === "none" && (
321
+ <div className="text-muted-foreground text-[11px]">
322
+ Monitoring only: the domain does not ask receivers to reject
323
+ failures.
324
+ </div>
325
+ )}
326
+ </>
327
+ )}
328
+ </CheckRow>
329
+ );
330
+ }
331
+
332
+ function ArcRow({ authentication }: { authentication: InboundAuthentication }) {
333
+ const { arc } = authentication;
334
+ const href = "https://www.rfc-editor.org/rfc/rfc8617.html";
335
+
336
+ if (!arc || (arc.result === "none" && arc.chainLength <= 1)) {
337
+ return (
338
+ <CheckRow label="ARC" result="none" href={href}>
339
+ <Muted>No forwarding chain</Muted>
340
+ </CheckRow>
341
+ );
342
+ }
343
+
344
+ const sealers = arc.sealers.flatMap((sealer) =>
345
+ sealer.domain ? [sealer.domain] : []
346
+ );
347
+
348
+ return (
349
+ <CheckRow label="ARC" result={arc.result} href={href}>
350
+ {sealers.length > 0 && (
351
+ <>
352
+ Forwarded via{" "}
353
+ <span className="font-medium">{listFormat(sealers)}</span>
354
+ </>
355
+ )}
356
+ {arc.result === "fail" && (
357
+ <div className="text-destructive">
358
+ The forwarding chain is broken; earlier results cannot be trusted.
359
+ </div>
360
+ )}
361
+ {arc.oldest && (
362
+ <div className="text-muted-foreground text-[11px]">
363
+ Before forwarding: {claimSummary(arc.oldest)} · reported by{" "}
364
+ {arc.oldest.authservId}, chain verified by Cloudflare
365
+ </div>
366
+ )}
367
+ </CheckRow>
368
+ );
369
+ }
370
+
371
+ function SpamScore({ score }: { score: number | null }) {
372
+ if (score === null) return null;
373
+
374
+ return (
375
+ <div className="grid grid-cols-[3.75rem_4.75rem_minmax(0,1fr)] items-baseline gap-x-3 py-2.5">
376
+ <dt className="text-muted-foreground text-xs font-medium">Spam</dt>
377
+ <dd>
378
+ <Verdict tone={score >= 3 ? "warn" : "neutral"}>{score} / 5</Verdict>
379
+ </dd>
380
+ <dd className="text-muted-foreground text-xs leading-5 max-sm:col-span-2 max-sm:col-start-2 max-sm:mt-1">
381
+ Cloudflare spam score (X-CF-SpamH-Score). Experimental; not used to
382
+ filter mail.
383
+ </dd>
384
+ </div>
385
+ );
386
+ }
387
+
388
+ /** Gmail-style SPF / DKIM / DMARC / ARC lines from the trusted Cloudflare results. */
389
+ export function SenderAuthentication({
390
+ authentication,
391
+ }: {
392
+ authentication: InboundAuthentication | null;
393
+ }) {
394
+ if (!authentication) {
395
+ return (
396
+ <p className="text-muted-foreground text-xs">
397
+ Authentication results are not available for this message.
398
+ </p>
399
+ );
400
+ }
401
+
402
+ const unavailable = authentication.verdict === "unavailable";
403
+
404
+ return (
405
+ <div>
406
+ <VerdictSummary authentication={authentication} />
407
+ {!unavailable && (
408
+ <dl className="divide-border divide-y">
409
+ <SpfRow authentication={authentication} />
410
+ <DkimRow authentication={authentication} />
411
+ <DmarcRow authentication={authentication} />
412
+ <ArcRow authentication={authentication} />
413
+ <SpamScore score={authentication.spamScore} />
414
+ </dl>
415
+ )}
416
+ {unavailable && authentication.spamScore !== null && (
417
+ <dl>
418
+ <SpamScore score={authentication.spamScore} />
419
+ </dl>
420
+ )}
421
+ {(authentication.ignoredCloudflareClaims > 0 ||
422
+ authentication.upstream.length > 0) && (
423
+ <div className="border-border text-muted-foreground mt-2 space-y-1 border-t pt-2.5 text-[11px] leading-4">
424
+ {authentication.ignoredCloudflareClaims > 0 && (
425
+ <p className="text-amber-800 dark:text-amber-300">
426
+ Ignored {authentication.ignoredCloudflareClaims} header
427
+ {authentication.ignoredCloudflareClaims === 1 ? "" : "s"} below
428
+ Cloudflare's block that claimed to come from Cloudflare.
429
+ </p>
430
+ )}
431
+ {authentication.upstream.map((claim, index) => (
432
+ <p key={index}>
433
+ Reported by {claim.authservId} (unverified, added before
434
+ Cloudflare): {claimSummary(claim)}
435
+ </p>
436
+ ))}
437
+ </div>
438
+ )}
439
+ {authentication.trustedHeader && (
440
+ <details className="group mt-2 text-[11px]">
441
+ <summary className="text-muted-foreground hover:text-foreground cursor-pointer select-none">
442
+ Trusted Authentication-Results header
443
+ </summary>
444
+ <pre className="bg-surface-sunken ring-border mt-1.5 overflow-x-auto rounded-md p-2.5 font-mono text-[10.5px] leading-[1.55] [overflow-wrap:anywhere] whitespace-pre-wrap ring-1">
445
+ {authentication.trustedHeader.replaceAll(/;\s*/gu, ";\n ")}
446
+ </pre>
447
+ </details>
448
+ )}
449
+ </div>
450
+ );
451
+ }
452
+
453
+ const unsubscribeReasons: Record<
454
+ NonNullable<ListUnsubscribe["reason"]>,
455
+ string
456
+ > = {
457
+ "invalid-uri": "the header has no valid link or address",
458
+ "no-https": "only an email address is offered",
459
+ "no-post": "the sender did not opt in to one-click (RFC 8058)",
460
+ unsigned: "no passing DKIM signature covers the header",
461
+ unaligned: "the covering signature does not belong to the sender's domain",
462
+ "post-not-signed": "the signature does not cover List-Unsubscribe-Post",
463
+ };
464
+
465
+ export function unsubscribeSummary(value: ListUnsubscribe) {
466
+ const methods: string[] = [];
467
+
468
+ if (value.httpsUrl) methods.push("link");
469
+
470
+ if (value.mailto) methods.push("email");
471
+
472
+ if (value.oneClick) {
473
+ return `One-click (RFC 8058)${value.mailto ? ", email" : ""}`;
474
+ }
475
+
476
+ const listed = listFormat(methods);
477
+
478
+ const offered = methods.length
479
+ ? `${listed.charAt(0).toUpperCase()}${listed.slice(1)}`
480
+ : "Not usable";
481
+
482
+ return value.reason
483
+ ? `${offered} · no one-click: ${unsubscribeReasons[value.reason]}`
484
+ : offered;
485
+ }