@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.
Files changed (223) hide show
  1. package/README.md +23 -20
  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_dry_moon_knight.sql +77 -0
  11. package/migrations/meta/0000_snapshot.json +248 -106
  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 +78 -26
  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 +90 -34
  127. package/worker/jmap/eventsource.ts +169 -0
  128. package/worker/jmap/methods.ts +1716 -361
  129. package/worker/jmap/push-types.ts +27 -0
  130. package/worker/jmap/push.ts +207 -0
  131. package/worker/jmap/routes.ts +448 -86
  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 +84 -52
  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 +283 -171
  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 +871 -542
  184. package/worker/mail/safety-routes.ts +329 -202
  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 +153 -91
  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 +597 -227
  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 +1761 -737
  202. package/worker/mailbox/jmap-store.ts +139 -35
  203. package/worker/mailbox/model.ts +7 -14
  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 -126
  216. package/containers/office-preview/Dockerfile +0 -10
  217. package/migrations/0000_email.sql +0 -53
  218. package/shared/mail-rules.ts +0 -156
  219. package/worker/admin/report-routes.ts +0 -164
  220. package/worker/mail/reported-messages.ts +0 -68
  221. package/worker/mailbox/legacy-migrations.ts +0 -41
  222. package/worker/mailbox/migrations.ts +0 -10
  223. package/worker/mailbox/rules.ts +0 -110
@@ -0,0 +1,545 @@
1
+ /* oxlint-disable react/jsx-key -- rows are [label, value] tuples, rendered with the label as key */
2
+ import {
3
+ Tooltip,
4
+ TooltipContent,
5
+ TooltipTrigger,
6
+ cn,
7
+ } from "@open-workspace/core/ui";
8
+ import {
9
+ Ban,
10
+ Check,
11
+ LoaderCircle,
12
+ OctagonAlert,
13
+ ShieldQuestion,
14
+ X,
15
+ } from "lucide-react";
16
+ import { useState } from "react";
17
+ import type { ReactNode } from "react";
18
+
19
+ import { countryFlag } from "../../shared/mail-sender-intel";
20
+ import type {
21
+ LookupStatus,
22
+ SecurityWarning,
23
+ SenderIntel,
24
+ SpamhausCheck,
25
+ } from "../../shared/mail-sender-intel";
26
+ import { Monogram } from "./mail-primitives";
27
+ import type { MessageDetail } from "./types";
28
+
29
+ /** BIMI logo when DMARC allowed one, else the initials monogram. */
30
+ export function SenderAvatar({
31
+ name,
32
+ logoUrl,
33
+ className,
34
+ }: {
35
+ name: string;
36
+ logoUrl?: string | null;
37
+ className?: string;
38
+ }) {
39
+ const [failed, setFailed] = useState<string | null>(null);
40
+
41
+ if (logoUrl && failed !== logoUrl) {
42
+ return (
43
+ <img
44
+ src={logoUrl}
45
+ alt=""
46
+ aria-hidden="true"
47
+ draggable={false}
48
+ onError={() => setFailed(logoUrl)}
49
+ className={cn(
50
+ "bg-surface ring-border shrink-0 object-cover ring-1",
51
+ className
52
+ )}
53
+ />
54
+ );
55
+ }
56
+
57
+ return <Monogram name={name} className={className} />;
58
+ }
59
+
60
+ const lookupFailure: Partial<Record<LookupStatus, string>> = {
61
+ timeout: "Lookup timed out",
62
+ error: "Lookup failed",
63
+ skipped: "Not checked",
64
+ };
65
+
66
+ function networkLabel(network: SenderIntel["network"]) {
67
+ if (network.asn === null) return null;
68
+
69
+ return [`AS${network.asn}`, network.asName].filter(Boolean).join(" ");
70
+ }
71
+
72
+ function Country({ code }: { code: string | null }) {
73
+ if (!code) return null;
74
+ const flag = countryFlag(code);
75
+
76
+ return (
77
+ <span className="whitespace-nowrap" title={code}>
78
+ {flag && (
79
+ <span aria-hidden="true" className="mr-0.5">
80
+ {flag}
81
+ </span>
82
+ )}
83
+ {code}
84
+ </span>
85
+ );
86
+ }
87
+
88
+ function Muted({ children }: { children: ReactNode }) {
89
+ return <span className="text-muted-foreground">{children}</span>;
90
+ }
91
+
92
+ function spamhausRow(
93
+ label: string,
94
+ check: SpamhausCheck,
95
+ target: ReactNode
96
+ ): [string, ReactNode] {
97
+ if (check.status !== "ok") {
98
+ return [
99
+ label,
100
+ <Muted>
101
+ {check.error ?? lookupFailure[check.status] ?? "Not checked"}
102
+ </Muted>,
103
+ ];
104
+ }
105
+
106
+ if (!check.listings.length) {
107
+ return [
108
+ label,
109
+ <span className="inline-flex items-center gap-1">
110
+ <Check className="text-success size-3" />
111
+ Not listed <Muted>{target}</Muted>
112
+ </span>,
113
+ ];
114
+ }
115
+
116
+ return [
117
+ label,
118
+ <ul className="space-y-0.5">
119
+ {check.listings.map((listing) => (
120
+ <li
121
+ key={`${listing.target}-${listing.code}`}
122
+ className={
123
+ listing.severity === "abuse"
124
+ ? "text-destructive"
125
+ : "text-amber-800 dark:text-amber-300"
126
+ }
127
+ >
128
+ <span className="font-medium">{listing.target}</span> · {listing.list}{" "}
129
+ <span className="font-mono text-[10.5px] opacity-75">
130
+ {listing.code}
131
+ </span>
132
+ </li>
133
+ ))}
134
+ </ul>,
135
+ ];
136
+ }
137
+
138
+ /** Rows for the "Sender" section of Show original. */
139
+ export function senderIntelRows(intel: SenderIntel): [string, ReactNode][] {
140
+ const rows: [string, ReactNode][] = [];
141
+ const ptrFailure = lookupFailure[intel.ptr.status];
142
+ rows.push([
143
+ "Reverse DNS",
144
+ intel.ptr.names.length ? (
145
+ <span>
146
+ {intel.ptr.names.join(", ")}
147
+ {intel.ptr.generic && (
148
+ <Muted> · looks like a dynamic or end-user address</Muted>
149
+ )}
150
+ </span>
151
+ ) : (
152
+ <Muted>{ptrFailure ?? "No PTR record"}</Muted>
153
+ ),
154
+ ]);
155
+
156
+ if (intel.ptr.status === "ok" || intel.ptr.status === "nxdomain") {
157
+ rows.push([
158
+ "FCrDNS",
159
+ intel.ptr.fcrdns ? (
160
+ <span>
161
+ <span className="text-success">
162
+ <Check className="mr-1 inline size-3 align-[-1px]" />
163
+ Forward-confirmed
164
+ </span>
165
+ <Muted> · the name resolves back to {intel.ip}</Muted>
166
+ </span>
167
+ ) : (
168
+ <span className="text-amber-800 dark:text-amber-300">
169
+ <X className="mr-1 inline size-3 align-[-1px]" />
170
+ {intel.ptr.names.length
171
+ ? "The name does not resolve back to this IP"
172
+ : "No reverse DNS to confirm"}
173
+ </span>
174
+ ),
175
+ ]);
176
+ }
177
+
178
+ if (intel.heloMatchesPtr !== null) {
179
+ rows.push([
180
+ "HELO match",
181
+ intel.heloMatchesPtr ? (
182
+ "HELO matches the reverse DNS"
183
+ ) : (
184
+ <Muted>HELO differs from the reverse DNS</Muted>
185
+ ),
186
+ ]);
187
+ }
188
+
189
+ const network = networkLabel(intel.network);
190
+ rows.push([
191
+ "Network",
192
+ network ? (
193
+ <span className="inline-flex flex-wrap items-center gap-x-1.5">
194
+ <span className="font-medium">{network}</span>
195
+ {intel.network.prefix && <Muted>· {intel.network.prefix}</Muted>}
196
+ {intel.network.country && (
197
+ <Muted>
198
+ · <Country code={intel.network.country} />
199
+ </Muted>
200
+ )}
201
+ {intel.network.registry && (
202
+ <Muted>· {intel.network.registry.toUpperCase()}</Muted>
203
+ )}
204
+ </span>
205
+ ) : (
206
+ <Muted>{lookupFailure[intel.network.status] ?? "No ASN data"}</Muted>
207
+ ),
208
+ ]);
209
+
210
+ if (intel.spamhaus) {
211
+ rows.push(
212
+ spamhausRow(
213
+ "Spamhaus ZEN",
214
+ intel.spamhaus.zen,
215
+ intel.ip ? `(${intel.ip})` : null
216
+ ),
217
+ spamhausRow(
218
+ "Spamhaus DBL",
219
+ intel.spamhaus.dbl,
220
+ intel.spamhaus.dbl.domains.length
221
+ ? `(${intel.spamhaus.dbl.domains.length} domain${intel.spamhaus.dbl.domains.length === 1 ? "" : "s"})`
222
+ : null
223
+ )
224
+ );
225
+ }
226
+
227
+ if (intel.bimi) {
228
+ rows.push([
229
+ "BIMI",
230
+ intel.bimi.status === "ok" ? (
231
+ <span>
232
+ Logo from {intel.bimi.domain}{" "}
233
+ <Muted>· not verified with a mark certificate</Muted>
234
+ </span>
235
+ ) : (
236
+ <Muted>{intel.bimi.reason ?? "No logo"}</Muted>
237
+ ),
238
+ ]);
239
+ }
240
+
241
+ rows.push([
242
+ "Checked",
243
+ <Muted>
244
+ {new Date(intel.checkedAt).toLocaleString("en", {
245
+ dateStyle: "medium",
246
+ timeStyle: "short",
247
+ })}
248
+ {intel.source === "demo"
249
+ ? " · demo data"
250
+ : " · DNS over HTTPS, Team Cymru"}
251
+ </Muted>,
252
+ ]);
253
+
254
+ return rows;
255
+ }
256
+
257
+ function listFormat(items: string[]) {
258
+ return new Intl.ListFormat("en", {
259
+ style: "long",
260
+ type: "conjunction",
261
+ }).format(items);
262
+ }
263
+
264
+ function warningHeadline(warning: SecurityWarning, message: MessageDetail) {
265
+ switch (warning.kind) {
266
+ case "dbl_listed": {
267
+ const lists = listFormat(
268
+ warning.lists.map((list) => list.replace(/^DBL /u, "a "))
269
+ );
270
+
271
+ return warning.senderDomain
272
+ ? `The sender's domain ${warning.domains[0]} is on the Spamhaus Domain Blocklist as ${lists}.`
273
+ : `Links in this message lead to ${listFormat(warning.domains)}, which Spamhaus lists as ${lists}.`;
274
+ }
275
+
276
+ case "lookalike_domain": {
277
+ return `${warning.domain} looks like ${warning.resembles}, but it is a different domain.`;
278
+ }
279
+
280
+ case "display_name_impersonation": {
281
+ return `This sender uses the name ${warning.name}, but ${message.fromAddress} is outside your organization.`;
282
+ }
283
+
284
+ case "zen_listed": {
285
+ return warning.severity === "danger"
286
+ ? `The sending server ${warning.ip} is on a Spamhaus blocklist (${listFormat(warning.lists)}).`
287
+ : `The sending server ${warning.ip} is in an end-user address range (${listFormat(warning.lists)}).`;
288
+ }
289
+
290
+ case "embedded_address": {
291
+ return `The sender's name shows ${warning.claimed}, but the message came from ${message.fromAddress}.`;
292
+ }
293
+
294
+ case "unverified_sender": {
295
+ return `We couldn't verify that this message came from ${warning.domain ?? message.fromAddress}.`;
296
+ }
297
+
298
+ case "reply_to_mismatch": {
299
+ return `Replies go to ${warning.address}, not to ${message.security?.fromDomain ?? "the sender's domain"}.`;
300
+ }
301
+
302
+ case "addressed_elsewhere": {
303
+ const via = warning.forwardedVia
304
+ ? ` through ${warning.forwardedVia}`
305
+ : "";
306
+
307
+ return warning.severity === "danger"
308
+ ? `This account alert is about ${warning.addressedTo}, not you, and was forwarded to you${via}. Real alerts only go to the account they are about.`
309
+ : `This message was written for ${warning.addressedTo} and forwarded to you${via}.`;
310
+ }
311
+
312
+ default: {
313
+ const unexpected: never = warning;
314
+ throw new Error(
315
+ `Unknown security warning: ${JSON.stringify(unexpected)}`
316
+ );
317
+ }
318
+ }
319
+ }
320
+
321
+ /**
322
+ * One calm banner for every sender warning on a message: the most serious
323
+ * one is the headline, the rest follow as short lines.
324
+ */
325
+ export function SenderSecurityBanner({
326
+ message,
327
+ onShowOriginal,
328
+ onTrust,
329
+ }: {
330
+ message: MessageDetail;
331
+ onShowOriginal?: () => void;
332
+ /** Offered only when every warning is caution-level. */
333
+ onTrust?: () => void;
334
+ }) {
335
+ const warnings = message.security?.warnings ?? [];
336
+ const [first, ...rest] = warnings;
337
+ const pending = message.senderIntelPending;
338
+
339
+ if (!first) {
340
+ // Blocklist results can still add a warning: say so instead of nothing.
341
+ return pending ? (
342
+ <p
343
+ role="status"
344
+ data-testid="sender-intel-pending"
345
+ className="text-muted-foreground mt-3 flex items-center gap-2 text-xs @lg/reader:ml-12"
346
+ >
347
+ <LoaderCircle className="size-3.5 shrink-0 animate-spin" />
348
+ Checking the sender's server and blocklists…
349
+ </p>
350
+ ) : null;
351
+ }
352
+
353
+ const danger = warnings.some((warning) => warning.severity === "danger");
354
+ const Icon = danger ? OctagonAlert : ShieldQuestion;
355
+
356
+ return (
357
+ <div
358
+ role="note"
359
+ data-testid="sender-security-banner"
360
+ className={cn(
361
+ "text-foreground mt-3 flex items-start gap-2.5 rounded-md px-3 py-2 text-xs ring-1 ring-inset @lg/reader:ml-12",
362
+ danger
363
+ ? "bg-destructive/6 ring-destructive/20"
364
+ : "bg-warning/10 ring-warning/25"
365
+ )}
366
+ >
367
+ <Icon
368
+ className={cn(
369
+ "mt-px size-3.5 shrink-0",
370
+ danger ? "text-destructive" : "text-amber-700 dark:text-amber-300"
371
+ )}
372
+ />
373
+ <div className="min-w-0 flex-1 leading-5">
374
+ <p className="font-medium">{warningHeadline(first, message)}</p>
375
+ {rest.length > 0 && (
376
+ <ul className="text-muted-foreground marker:text-border mt-0.5 list-disc pl-4">
377
+ {rest.map((warning) => (
378
+ <li key={warning.kind}>{warningHeadline(warning, message)}</li>
379
+ ))}
380
+ </ul>
381
+ )}
382
+ <p className="text-muted-foreground">
383
+ {pending && "Still checking the sender's server and blocklists. "}
384
+ {message.security?.firstTimeSender &&
385
+ "This is the first message from this address. "}
386
+ Be careful with links, attachments, and requests for payment or
387
+ sign-in details.
388
+ {onTrust && !danger && !pending && !message.sender?.block && (
389
+ <>
390
+ {" "}
391
+ <Tooltip>
392
+ <TooltipTrigger
393
+ render={
394
+ // oxlint-disable-next-line jsx-a11y/control-has-associated-label -- the tooltip trigger renders its children inside this button
395
+ <button
396
+ type="button"
397
+ onClick={onTrust}
398
+ className={cn(
399
+ bannerLinkClass,
400
+ "decoration-border underline"
401
+ )}
402
+ />
403
+ }
404
+ >
405
+ I know this sender
406
+ </TooltipTrigger>
407
+ <TooltipContent>
408
+ Trust this sender: hide these hints for future messages
409
+ </TooltipContent>
410
+ </Tooltip>
411
+ </>
412
+ )}
413
+ </p>
414
+ </div>
415
+ {onShowOriginal && (
416
+ <button
417
+ type="button"
418
+ onClick={onShowOriginal}
419
+ className={bannerLinkClass}
420
+ >
421
+ Details
422
+ </button>
423
+ )}
424
+ </div>
425
+ );
426
+ }
427
+
428
+ const bannerLinkClass =
429
+ "shrink-0 rounded-sm font-medium text-foreground underline-offset-2 outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring";
430
+
431
+ function shortDay(at: number) {
432
+ return new Date(at).toLocaleDateString("en", {
433
+ month: "short",
434
+ day: "numeric",
435
+ year:
436
+ new Date(at).getFullYear() === new Date().getFullYear()
437
+ ? undefined
438
+ : "numeric",
439
+ });
440
+ }
441
+
442
+ const unsubscribedCopy = {
443
+ done: "Unsubscribed",
444
+ requested: "Unsubscribe requested",
445
+ opened: "Unsubscribe page opened",
446
+ failed: null,
447
+ } as const;
448
+
449
+ /** "Unsubscribe" beside the sender, or what happened when someone already did. */
450
+ export function SubscriptionAction({
451
+ message,
452
+ onUnsubscribe,
453
+ }: {
454
+ message: MessageDetail;
455
+ onUnsubscribe?: () => void;
456
+ }) {
457
+ const record = message.unsubscription;
458
+ const label = record ? unsubscribedCopy[record.status] : null;
459
+
460
+ if (label && record) {
461
+ return (
462
+ <span
463
+ data-testid="unsubscribed-label"
464
+ className="text-muted-foreground hidden shrink-0 text-xs @sm/reader:inline"
465
+ title={`${label} on ${new Date(record.at).toLocaleString("en", { dateStyle: "medium", timeStyle: "short" })}${record.target ? ` via ${record.target}` : ""}`}
466
+ >
467
+ {label} on {shortDay(record.at)}
468
+ </span>
469
+ );
470
+ }
471
+
472
+ if (!onUnsubscribe) return null;
473
+
474
+ return (
475
+ <button
476
+ type="button"
477
+ onClick={onUnsubscribe}
478
+ className="text-muted-foreground decoration-border hover:text-foreground focus-visible:ring-ring hidden shrink-0 rounded-sm px-0.5 text-xs font-medium underline underline-offset-2 outline-none hover:decoration-current focus-visible:ring-2 @sm/reader:inline"
479
+ >
480
+ Unsubscribe
481
+ </button>
482
+ );
483
+ }
484
+
485
+ /** Calm one-liners for decisions people made about this sender or message. */
486
+ export function SenderStatusNotice({
487
+ message,
488
+ onUnblock,
489
+ }: {
490
+ message: MessageDetail;
491
+ onUnblock?: () => void;
492
+ }) {
493
+ const block = message.sender?.block;
494
+
495
+ const lines: {
496
+ key: string;
497
+ text: string;
498
+ action?: { label: string; run: () => void };
499
+ }[] = [];
500
+
501
+ if (block) {
502
+ lines.push({
503
+ key: "block",
504
+ text: block.workspace
505
+ ? `An administrator blocked ${block.pattern} for everyone. New messages go to Spam.`
506
+ : `You blocked ${block.scope === "domain" ? `everyone at ${block.pattern.slice(1)}` : block.pattern}. New messages go to Spam.`,
507
+ action:
508
+ !block.workspace && onUnblock
509
+ ? { label: "Unblock", run: onUnblock }
510
+ : undefined,
511
+ });
512
+ }
513
+
514
+ if (message.reported) {
515
+ lines.push({ key: "report", text: "Reported as spam." });
516
+ }
517
+
518
+ if (!lines.length) return null;
519
+
520
+ return (
521
+ <div
522
+ data-testid="sender-status-notice"
523
+ className="mt-3 space-y-1 @lg/reader:ml-12"
524
+ >
525
+ {lines.map((line) => (
526
+ <p
527
+ key={line.key}
528
+ className="text-muted-foreground flex items-center gap-2 text-xs"
529
+ >
530
+ <Ban className="size-3.5 shrink-0" />
531
+ <span className="min-w-0">{line.text}</span>
532
+ {line.action && (
533
+ <button
534
+ type="button"
535
+ onClick={line.action.run}
536
+ className={bannerLinkClass}
537
+ >
538
+ {line.action.label}
539
+ </button>
540
+ )}
541
+ </p>
542
+ ))}
543
+ </div>
544
+ );
545
+ }
@@ -0,0 +1,29 @@
1
+ import {
2
+ Tooltip,
3
+ TooltipContent,
4
+ TooltipTrigger,
5
+ } from "@open-workspace/core/ui";
6
+ import type { ReactNode } from "react";
7
+
8
+ export function ToolbarTooltip({
9
+ label,
10
+ side = "top",
11
+ sideOffset = 7,
12
+ children,
13
+ }: {
14
+ label: string;
15
+ side?: "top" | "right" | "bottom" | "left";
16
+ sideOffset?: number;
17
+ children: ReactNode;
18
+ }) {
19
+ return (
20
+ <Tooltip>
21
+ <TooltipTrigger render={<span className="inline-flex" />}>
22
+ {children}
23
+ </TooltipTrigger>
24
+ <TooltipContent side={side} sideOffset={sideOffset}>
25
+ {label}
26
+ </TooltipContent>
27
+ </Tooltip>
28
+ );
29
+ }
@@ -0,0 +1,49 @@
1
+ const SKIP_TEXT_IN = new Set(["SCRIPT", "STYLE", "NOSCRIPT", "TEMPLATE"]);
2
+
3
+ function textNodes(root: Node): Text[] {
4
+ const nodes: Text[] = [];
5
+
6
+ function visit(node: Node) {
7
+ if (node instanceof Text) {
8
+ if (node.data.trim()) nodes.push(node);
9
+
10
+ return;
11
+ }
12
+
13
+ if (node instanceof Element && SKIP_TEXT_IN.has(node.tagName)) return;
14
+
15
+ for (const child of Array.from(node.childNodes)) visit(child);
16
+ }
17
+
18
+ visit(root);
19
+
20
+ return nodes;
21
+ }
22
+
23
+ export function emailHtmlTextSegments(html: string) {
24
+ const document = new DOMParser().parseFromString(html, "text/html");
25
+
26
+ return textNodes(document.body).map((node) => node.data.trim());
27
+ }
28
+
29
+ export function translatedEmailHtml(
30
+ html: string,
31
+ translations: string[],
32
+ fullDocument: boolean
33
+ ) {
34
+ const document = new DOMParser().parseFromString(html, "text/html");
35
+ const nodes = textNodes(document.body);
36
+
37
+ if (nodes.length !== translations.length) return null;
38
+ nodes.forEach((node, index) => {
39
+ const original = node.textContent ?? "";
40
+ const leading = original.match(/^\s*/u)?.[0] ?? "";
41
+ const trailing = original.match(/\s*$/u)?.[0] ?? "";
42
+ // textContent keeps model output inert while the original elements and attributes survive.
43
+ node.textContent = leading + translations[index] + trailing;
44
+ });
45
+
46
+ return fullDocument
47
+ ? `<!doctype html>${document.documentElement.outerHTML}`
48
+ : document.body.innerHTML;
49
+ }
@@ -0,0 +1,21 @@
1
+ export const COMMON_LANGUAGES = [
2
+ "en",
3
+ "es",
4
+ "fr",
5
+ "de",
6
+ "it",
7
+ "pt",
8
+ "ru",
9
+ "uk",
10
+ "sr",
11
+ "tr",
12
+ "ar",
13
+ "hi",
14
+ "zh",
15
+ "ja",
16
+ "ko",
17
+ ];
18
+
19
+ export function browserLanguage() {
20
+ return navigator.languages?.[0] || navigator.language || "en";
21
+ }
@@ -0,0 +1,53 @@
1
+ import type { SuccessfulResponse } from "@open-workspace/core/ui";
2
+
3
+ import type { mailApi } from "../lib/mail-api";
4
+
5
+ export type {
6
+ MailboxState,
7
+ RecipientDeliveryStatus,
8
+ ReplyAction,
9
+ ReplyActionMode,
10
+ ReplyPlan,
11
+ TransportState,
12
+ } from "../../shared/mail";
13
+
14
+ type MailboxesResponse = SuccessfulResponse<
15
+ Awaited<ReturnType<typeof mailApi.api.mail.mailboxes.$get>>
16
+ >;
17
+
18
+ type FoldersResponse = SuccessfulResponse<
19
+ Awaited<
20
+ ReturnType<(typeof mailApi.api.mail.mailboxes)[":id"]["folders"]["$get"]>
21
+ >
22
+ >;
23
+
24
+ type MailboxAiGet = (typeof mailApi.api.mail.mailboxes)[":id"]["ai"]["$get"];
25
+
26
+ type MailboxAiSettingsResponse = SuccessfulResponse<
27
+ Awaited<ReturnType<MailboxAiGet>>
28
+ >;
29
+
30
+ type ConversationsResponse = SuccessfulResponse<
31
+ Awaited<ReturnType<typeof mailApi.api.mail.conversations.$get>>
32
+ >;
33
+
34
+ type ConversationResponse = SuccessfulResponse<
35
+ Awaited<ReturnType<(typeof mailApi.api.mail.conversations)[":id"]["$get"]>>
36
+ >;
37
+
38
+ export type Mailbox = MailboxesResponse["mailboxes"][number];
39
+
40
+ export type MailFolder = FoldersResponse["folders"][number];
41
+
42
+ export type MailboxAiSettings = MailboxAiSettingsResponse["settings"];
43
+
44
+ export type MailboxAiConfiguration = MailboxAiSettings["configuration"];
45
+
46
+ export type ConversationSummary =
47
+ ConversationsResponse["conversations"][number];
48
+
49
+ export type MessageDetail = ConversationResponse["messages"][number];
50
+
51
+ export type MessageAttachment = MessageDetail["attachments"][number];
52
+
53
+ export type Folder = string;