@open-workspace/email 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. package/README.md +9 -4
  2. package/alchemy/index.ts +130 -2
  3. package/drizzle/mailbox/0002_good_komodo.sql +2 -0
  4. package/drizzle/mailbox/0003_after_0_4_2.sql +180 -0
  5. package/drizzle/mailbox/meta/0002_snapshot.json +1017 -0
  6. package/drizzle/mailbox/meta/0003_snapshot.json +1507 -0
  7. package/drizzle/mailbox/meta/_journal.json +14 -0
  8. package/drizzle/mailbox/migrations.js +5 -1
  9. package/migrations/0001_overrated_ricochet.sql +2 -0
  10. package/migrations/0002_after_0_4_2.sql +35 -0
  11. package/migrations/meta/0001_snapshot.json +564 -0
  12. package/migrations/meta/0002_snapshot.json +807 -0
  13. package/migrations/meta/_journal.json +14 -0
  14. package/package.json +23 -7
  15. package/shared/attachment-preview.ts +18 -8
  16. package/shared/folder-order.ts +31 -6
  17. package/shared/mail-headers.ts +3 -3
  18. package/shared/mail-html.ts +25 -0
  19. package/shared/mail-import.ts +0 -7
  20. package/shared/mail-received.ts +4 -4
  21. package/shared/mail-rule-actions.ts +47 -0
  22. package/shared/mail.ts +70 -4
  23. package/shared/office-preview.ts +0 -4
  24. package/shared/pdfjs-assets.ts +1 -3
  25. package/shared/rich-content.ts +35 -0
  26. package/shared/signature.ts +15 -0
  27. package/src/admin/address-auto-reply.tsx +49 -0
  28. package/src/admin/blocked-senders.tsx +86 -66
  29. package/src/admin/forward-destinations.tsx +140 -0
  30. package/src/admin/mail-archive.tsx +134 -0
  31. package/src/admin/team-signature.tsx +90 -0
  32. package/src/client.tsx +130 -16
  33. package/src/mail/attachment-preview-dialog.tsx +13 -5
  34. package/src/mail/auto-reply-banner.tsx +61 -0
  35. package/src/mail/blocked-senders.tsx +124 -91
  36. package/src/mail/compose-window-chrome.tsx +20 -8
  37. package/src/mail/compose-window.tsx +387 -365
  38. package/src/mail/composer-asset-bookmarks.ts +47 -12
  39. package/src/mail/composer-attachment-list.tsx +42 -17
  40. package/src/mail/composer-editor-document.ts +54 -10
  41. package/src/mail/composer-editor.tsx +44 -44
  42. package/src/mail/composer-link-text.ts +42 -0
  43. package/src/mail/composer-recipient-fields.tsx +25 -16
  44. package/src/mail/composer-recipients.ts +62 -16
  45. package/src/mail/composer-session.ts +107 -23
  46. package/src/mail/composer-toolbar.tsx +15 -1
  47. package/src/mail/composer-upload-client.ts +29 -1
  48. package/src/mail/composer-upload-progress.ts +2 -2
  49. package/src/mail/conversation-actions-model.ts +56 -0
  50. package/src/mail/conversation-list.tsx +263 -128
  51. package/src/mail/conversation-loading-skeleton.tsx +165 -90
  52. package/src/mail/conversation-message.tsx +257 -102
  53. package/src/mail/conversation-order.ts +12 -0
  54. package/src/mail/conversation-reply.tsx +313 -189
  55. package/src/mail/conversation-selection-toolbar.tsx +188 -143
  56. package/src/mail/conversation-view.tsx +320 -85
  57. package/src/mail/delivery-indicator.tsx +33 -12
  58. package/src/mail/draft-attachments.ts +194 -0
  59. package/src/mail/email-html-body.tsx +97 -53
  60. package/src/mail/folder-cleanup-bar.tsx +193 -0
  61. package/src/mail/folder-glyph.tsx +5 -0
  62. package/src/mail/folder-manager.tsx +71 -38
  63. package/src/mail/mail-app-bar.tsx +15 -3
  64. package/src/mail/mail-dock.tsx +19 -3
  65. package/src/mail/mail-focus.ts +48 -0
  66. package/src/mail/mail-folders.ts +14 -2
  67. package/src/mail/mail-layout.css +20 -0
  68. package/src/mail/mail-mailbox-sheet.tsx +22 -69
  69. package/src/mail/mail-nav-rail.tsx +7 -4
  70. package/src/mail/mail-nav.tsx +66 -46
  71. package/src/mail/mail-prefetch.ts +30 -9
  72. package/src/mail/mail-primitives.tsx +6 -4
  73. package/src/mail/mail-queries.ts +122 -20
  74. package/src/mail/mail-query-cache.ts +1085 -173
  75. package/src/mail/mail-search-params.ts +35 -0
  76. package/src/mail/mail-shell.tsx +32 -9
  77. package/src/mail/mailbox-ai-settings.tsx +56 -42
  78. package/src/mail/mailbox-realtime.tsx +4 -12
  79. package/src/mail/mailbox-rules.tsx +898 -0
  80. package/src/mail/message-actions.tsx +38 -26
  81. package/src/mail/message-attachments.tsx +20 -12
  82. package/src/mail/message-body.ts +53 -0
  83. package/src/mail/message-format.ts +8 -2
  84. package/src/mail/message-header.tsx +3 -1
  85. package/src/mail/message-translation.tsx +34 -67
  86. package/src/mail/original-message-sheet.tsx +63 -50
  87. package/src/mail/original-message.ts +6 -6
  88. package/src/mail/pane-splitter.tsx +3 -3
  89. package/src/mail/pdf-preview.tsx +70 -62
  90. package/src/mail/plain-message-text.tsx +28 -0
  91. package/src/mail/print-message.ts +31 -36
  92. package/src/mail/reader-pane.tsx +134 -102
  93. package/src/mail/recipient-combobox.tsx +52 -29
  94. package/src/mail/recipient-field-row.tsx +3 -0
  95. package/src/mail/rich-content.ts +128 -0
  96. package/src/mail/sanitize-email-html.ts +57 -33
  97. package/src/mail/sender-actions.tsx +49 -39
  98. package/src/mail/sender-authentication.tsx +1 -1
  99. package/src/mail/sender-dialogs.tsx +67 -43
  100. package/src/mail/sender-security.tsx +9 -10
  101. package/src/mail/signature.ts +43 -0
  102. package/src/mail/translation-html.ts +3 -3
  103. package/src/mail/types.ts +12 -0
  104. package/src/mail/use-composer-attachment-preflight.ts +23 -60
  105. package/src/mail/use-composer-core.ts +286 -0
  106. package/src/mail/use-composer-navigation.ts +120 -0
  107. package/src/mail/use-composer-submission.ts +154 -19
  108. package/src/mail/use-conversation-actions.ts +292 -0
  109. package/src/mail/use-conversation-position.ts +51 -0
  110. package/src/mail/use-conversation-selection.ts +192 -89
  111. package/src/mail/use-draft-autosave.ts +394 -0
  112. package/src/mail/use-drafts.ts +194 -0
  113. package/src/mail/use-mail-controller.ts +754 -213
  114. package/src/mail/use-mail-data.ts +210 -100
  115. package/src/mail/use-mail-safety.ts +19 -38
  116. package/src/mail/use-mail-send.ts +18 -6
  117. package/src/mail/use-pdf-translation.ts +1 -1
  118. package/src/mail/use-reply-cc.ts +61 -0
  119. package/src/mail/use-visible-message-read.ts +128 -64
  120. package/src/pwa/push-key.ts +18 -0
  121. package/src/pwa/push-subscription.ts +88 -26
  122. package/src/settings/auto-reply-editor.tsx +454 -0
  123. package/src/settings/auto-reply-page.tsx +59 -0
  124. package/src/settings/mail-apps-page.tsx +52 -43
  125. package/src/settings/notifications-page.tsx +82 -67
  126. package/src/settings/rich-content-editor.tsx +182 -0
  127. package/src/settings/settings-queries.ts +57 -0
  128. package/src/settings/signature-editor.tsx +142 -0
  129. package/src/settings/signature-page.tsx +70 -0
  130. package/worker/admin/blocked-sender-routes.ts +10 -16
  131. package/worker/backups/eml.ts +185 -0
  132. package/worker/backups/file-parts.ts +140 -0
  133. package/worker/backups/mail-backup.ts +644 -0
  134. package/worker/backups/settings-backup.ts +866 -0
  135. package/worker/backups/stream-eml.ts +73 -0
  136. package/worker/db/schema.ts +98 -2
  137. package/worker/jmap/attachment-blobs.ts +113 -0
  138. package/worker/jmap/blobs.ts +162 -0
  139. package/worker/jmap/draft-content.ts +42 -0
  140. package/worker/jmap/drafts.ts +70 -0
  141. package/worker/jmap/email-body.ts +152 -0
  142. package/worker/jmap/email-methods.ts +1223 -0
  143. package/worker/jmap/eventsource.ts +9 -8
  144. package/worker/jmap/import-methods.ts +205 -0
  145. package/worker/jmap/mailbox-methods.ts +187 -0
  146. package/worker/jmap/method-core.ts +379 -0
  147. package/worker/jmap/methods.ts +108 -1815
  148. package/worker/jmap/push-subscription-methods.ts +373 -0
  149. package/worker/jmap/push-types.ts +46 -2
  150. package/worker/jmap/push.ts +24 -31
  151. package/worker/jmap/routes.ts +144 -153
  152. package/worker/jmap/submission-methods.ts +395 -0
  153. package/worker/mail/access.ts +35 -12
  154. package/worker/mail/ai-classification.ts +2 -2
  155. package/worker/mail/archive-object.ts +96 -0
  156. package/worker/mail/archive-routes.ts +35 -0
  157. package/worker/mail/archive.ts +682 -0
  158. package/worker/mail/auth-headers.ts +48 -40
  159. package/worker/mail/auto-reply-routes.ts +255 -0
  160. package/worker/mail/auto-reply.ts +243 -0
  161. package/worker/mail/bimi.ts +53 -36
  162. package/worker/mail/bootstrap.ts +11 -3
  163. package/worker/mail/capabilities.ts +69 -0
  164. package/worker/mail/classification-signals.ts +1 -1
  165. package/worker/mail/confusables-data.ts +9 -0
  166. package/worker/mail/conversation-cursor.ts +6 -15
  167. package/worker/mail/delivery-events.ts +9 -7
  168. package/worker/mail/delivery-facts.ts +1 -1
  169. package/worker/mail/demo-routes.ts +3 -3
  170. package/worker/mail/doh.ts +3 -3
  171. package/worker/mail/download-links.ts +153 -0
  172. package/worker/mail/downloads.ts +2 -6
  173. package/worker/mail/draft-routes.ts +473 -0
  174. package/worker/mail/draft-sender.ts +54 -0
  175. package/worker/mail/edge-cache.ts +41 -55
  176. package/worker/mail/email-routing.ts +123 -0
  177. package/worker/mail/forward-destinations.ts +114 -0
  178. package/worker/mail/forward-downloads.ts +115 -0
  179. package/worker/mail/forward-html.ts +85 -0
  180. package/worker/mail/header-metadata.ts +2 -5
  181. package/worker/mail/impersonation.ts +102 -101
  182. package/worker/mail/import-routes.ts +29 -82
  183. package/worker/mail/import.ts +130 -0
  184. package/worker/mail/inbound-delivery.ts +6 -5
  185. package/worker/mail/inbound.ts +58 -28
  186. package/worker/mail/ip-intel.ts +8 -17
  187. package/worker/mail/isolate-cache.ts +1 -1
  188. package/worker/mail/mailbox-deletion.ts +33 -12
  189. package/worker/mail/mailbox-directory.ts +39 -65
  190. package/worker/mail/mailing-list.ts +29 -58
  191. package/worker/mail/message-security.ts +3 -3
  192. package/worker/mail/message-view.ts +12 -10
  193. package/worker/mail/office-conversion.ts +3 -5
  194. package/worker/mail/office-preview-container.ts +3 -8
  195. package/worker/mail/outbound-content.ts +139 -65
  196. package/worker/mail/outbound-delivery.ts +20 -17
  197. package/worker/mail/outbound-service.ts +34 -9
  198. package/worker/mail/outbound.ts +146 -75
  199. package/worker/mail/outgoing-context.ts +60 -30
  200. package/worker/mail/participants.ts +10 -15
  201. package/worker/mail/plain-body.ts +39 -0
  202. package/worker/mail/push-endpoint.ts +17 -0
  203. package/worker/mail/push-notifications.ts +87 -43
  204. package/worker/mail/quote-parser.ts +107 -25
  205. package/worker/mail/r2-presigned-urls.ts +7 -0
  206. package/worker/mail/receive.ts +146 -39
  207. package/worker/mail/recipients.ts +1 -1
  208. package/worker/mail/remote-proxy.ts +3 -3
  209. package/worker/mail/repeat.ts +1 -1
  210. package/worker/mail/reply-plan.ts +124 -26
  211. package/worker/mail/rfc.ts +15 -7
  212. package/worker/mail/rich-content.ts +207 -0
  213. package/worker/mail/routes.ts +696 -304
  214. package/worker/mail/routing.ts +274 -0
  215. package/worker/mail/rules.ts +230 -0
  216. package/worker/mail/safety-routes.ts +88 -80
  217. package/worker/mail/schemas.ts +222 -31
  218. package/worker/mail/search.ts +25 -2
  219. package/worker/mail/security-settings.ts +4 -10
  220. package/worker/mail/send-message.ts +238 -0
  221. package/worker/mail/sender-intel.ts +12 -20
  222. package/worker/mail/signature-routes.ts +201 -0
  223. package/worker/mail/signatures.ts +195 -0
  224. package/worker/mail/spamhaus.ts +28 -16
  225. package/worker/mail/storage-keys.ts +35 -0
  226. package/worker/mail/unsubscribe.ts +19 -41
  227. package/worker/mail/uploads.ts +193 -80
  228. package/worker/mail/webhook-source.ts +3 -2
  229. package/worker/mail/workspace-safety.ts +194 -60
  230. package/worker/mailbox/demo.ts +13 -15
  231. package/worker/mailbox/email-index.ts +92 -13
  232. package/worker/mailbox/folder-model.ts +0 -20
  233. package/worker/mailbox/import-placement.ts +21 -36
  234. package/worker/mailbox/inbound-decision.ts +114 -0
  235. package/worker/mailbox/inbox-counts.ts +45 -25
  236. package/worker/mailbox/index.ts +843 -2888
  237. package/worker/mailbox/jmap-change-log.ts +195 -0
  238. package/worker/mailbox/jmap-email-rows.ts +186 -0
  239. package/worker/mailbox/jmap-mailboxes.ts +116 -0
  240. package/worker/mailbox/jmap-placement.ts +139 -0
  241. package/worker/mailbox/jmap-query-filter.ts +231 -0
  242. package/worker/mailbox/jmap-store.ts +167 -299
  243. package/worker/mailbox/mailbox-auto-reply.ts +301 -0
  244. package/worker/mailbox/mailbox-backup.ts +538 -0
  245. package/worker/mailbox/mailbox-drafts.ts +417 -0
  246. package/worker/mailbox/mailbox-folders.ts +242 -0
  247. package/worker/mailbox/mailbox-import.ts +450 -0
  248. package/worker/mailbox/mailbox-inbound.ts +934 -0
  249. package/worker/mailbox/mailbox-jmap.ts +294 -0
  250. package/worker/mailbox/mailbox-outbound.ts +413 -0
  251. package/worker/mailbox/mailbox-rules.ts +336 -0
  252. package/worker/mailbox/mailbox-senders.ts +294 -0
  253. package/worker/mailbox/mailbox-storage.ts +438 -0
  254. package/worker/mailbox/mailbox-views.ts +891 -0
  255. package/worker/mailbox/model.ts +1 -0
  256. package/worker/mailbox/office-preview-jobs.ts +59 -47
  257. package/worker/mailbox/placement.ts +933 -0
  258. package/worker/mailbox/restore-thread.ts +52 -0
  259. package/worker/mailbox/retention.ts +36 -0
  260. package/worker/mailbox/schema.ts +211 -1
  261. package/worker/mailbox/senders.ts +216 -178
  262. package/worker/mailbox/spam-undo-filing.ts +138 -0
  263. package/worker/mailbox/spam-undo.ts +240 -0
  264. package/worker/mailbox/support.ts +416 -0
  265. package/worker/mcp/mail-action-tools.ts +156 -0
  266. package/worker/mcp/mail-compose-tools.ts +8 -2
  267. package/worker/mcp/mail-safety-tools.ts +4 -4
  268. package/worker/module.ts +23 -2
  269. package/src/mail/use-compose-submission.ts +0 -208
  270. package/src/mail/use-reply-submission.ts +0 -114
  271. package/worker/mail/capped-body.ts +0 -36
@@ -21,6 +21,7 @@ import {
21
21
  Forward,
22
22
  Globe,
23
23
  Languages,
24
+ ListFilter,
24
25
  Mail,
25
26
  MailMinus,
26
27
  OctagonAlert,
@@ -35,7 +36,7 @@ import { ReplyActionIcon } from "./conversation-reply";
35
36
  import { senderName } from "./message-format";
36
37
  import { languageName } from "./message-translation";
37
38
  import type { MessageTranslationState } from "./message-translation";
38
- import { printMessage, renderedMessageHtml } from "./print-message";
39
+ import { printMessage } from "./print-message";
39
40
  import { ToolbarTooltip } from "./toolbar-tooltip";
40
41
  import type { MessageDetail, ReplyAction } from "./types";
41
42
 
@@ -48,9 +49,11 @@ const originalShortcutLabel =
48
49
 
49
50
  export type MessageHandlers = {
50
51
  onViewed: () => Promise<void>;
51
- onReply: (action: ReplyAction) => void;
52
- onForward: () => void;
53
- onResend: () => void;
52
+ send?: {
53
+ reply: (message: MessageDetail, action: ReplyAction) => void;
54
+ forward: (message: MessageDetail) => void;
55
+ resend: (message: MessageDetail) => void;
56
+ };
54
57
  /** Present when the message has a stored original to inspect. */
55
58
  onShowOriginal?: () => void;
56
59
  /** Download URL of the stored original (.eml). */
@@ -65,6 +68,8 @@ export type SenderHandlers = {
65
68
  onUnsubscribe?: () => void;
66
69
  onBlock?: () => void;
67
70
  onUnblock?: () => void;
71
+ /** Opens a new rule with this sender (and list) filled in. */
72
+ onFilter?: () => void;
68
73
  /** Reporting spam moves the conversation to Spam; absent where that makes no sense. */
69
74
  onReportSpam?: () => void;
70
75
  /** "Looks safe": trusts the sender and hides caution hints. */
@@ -93,28 +98,26 @@ export function actionButtonLabel(action: ReplyAction) {
93
98
  /** A message's reply button and its "More actions" menu. */
94
99
  export function MessageActions({
95
100
  message,
96
- canForward,
97
101
  translation,
98
102
  resendPending,
99
103
  handlers,
100
104
  }: {
101
105
  message: MessageDetail;
102
- mailboxId?: string;
103
- canForward: boolean;
104
106
  translation: MessageTranslationState;
105
107
  resendPending: boolean;
106
108
  handlers: MessageHandlers;
107
109
  }) {
110
+ const { send } = handlers;
108
111
  const [primaryAction, ...otherActions] = message.replyPlan.actions;
109
112
  const senderHandlers = handlers.sender;
110
113
 
111
114
  return (
112
115
  <div className="-mr-1.5 flex shrink-0 items-center">
113
- {primaryAction && (
116
+ {send && primaryAction && (
114
117
  <IconAction
115
118
  label={`${actionButtonLabel(primaryAction)} to this message`}
116
119
  tooltip={actionButtonLabel(primaryAction)}
117
- onClick={() => handlers.onReply(primaryAction)}
120
+ onClick={() => send.reply(message, primaryAction)}
118
121
  >
119
122
  <ReplyActionIcon mode={primaryAction.mode} />
120
123
  </IconAction>
@@ -138,21 +141,23 @@ export function MessageActions({
138
141
  <DropdownMenuContent align="end" className="w-64">
139
142
  {menuGroups([
140
143
  [
141
- ...otherActions.map((action) => (
142
- <DropdownMenuItem
143
- key={action.mode}
144
- aria-label={`${actionButtonLabel(action)} to this message`}
145
- onClick={() => handlers.onReply(action)}
146
- >
147
- <ReplyActionIcon mode={action.mode} />{" "}
148
- {actionButtonLabel(action)}
149
- </DropdownMenuItem>
150
- )),
151
- canForward && (
144
+ ...(send
145
+ ? otherActions.map((action) => (
146
+ <DropdownMenuItem
147
+ key={action.mode}
148
+ aria-label={`${actionButtonLabel(action)} to this message`}
149
+ onClick={() => send.reply(message, action)}
150
+ >
151
+ <ReplyActionIcon mode={action.mode} />{" "}
152
+ {actionButtonLabel(action)}
153
+ </DropdownMenuItem>
154
+ ))
155
+ : []),
156
+ send && (
152
157
  <DropdownMenuItem
153
158
  key="forward"
154
159
  aria-label="Forward this message"
155
- onClick={handlers.onForward}
160
+ onClick={() => send.forward(message)}
156
161
  >
157
162
  <Forward /> Forward
158
163
  </DropdownMenuItem>
@@ -164,11 +169,11 @@ export function MessageActions({
164
169
  <Mail /> Mark as unread from here
165
170
  </DropdownMenuItem>
166
171
  ),
167
- canRetry(message) && (
172
+ send && canRetry(message) && (
168
173
  <DropdownMenuItem
169
174
  key="resend"
170
175
  disabled={resendPending}
171
- onClick={handlers.onResend}
176
+ onClick={() => send.resend(message)}
172
177
  >
173
178
  <RotateCw />{" "}
174
179
  {message.transportState === "failed"
@@ -206,6 +211,14 @@ export function MessageActions({
206
211
  </span>
207
212
  </DropdownMenuItem>
208
213
  ) : null,
214
+ senderHandlers?.onFilter && (
215
+ <DropdownMenuItem
216
+ key="filter"
217
+ onClick={senderHandlers.onFilter}
218
+ >
219
+ <ListFilter /> Filter messages like this
220
+ </DropdownMenuItem>
221
+ ),
209
222
  ],
210
223
  [
211
224
  senderHandlers?.onReportSpam && (
@@ -270,9 +283,8 @@ export function MessageActions({
270
283
  [
271
284
  <DropdownMenuItem
272
285
  key="print"
273
- onClick={() =>
274
- printMessage(message, renderedMessageHtml(message.id))
275
- }
286
+ disabled={!translation.ready}
287
+ onClick={() => printMessage(message, translation.body)}
276
288
  >
277
289
  <Printer /> Print
278
290
  </DropdownMenuItem>,
@@ -29,13 +29,15 @@ const SHEET = /^(xlsx?|xlsm|ods|csv|tsv|numbers)$/u;
29
29
  const SLIDES = /^(pptx?|odp|key)$/u;
30
30
  const DOCUMENT = /^(docx?|odt|rtf|pages|txt|md)$/u;
31
31
 
32
- function fileHueStyle(
33
- hue: number
34
- ): CSSProperties & Record<"--file-hue", number> {
35
- return { "--file-hue": hue };
32
+ function fileHueStyle(hue: number) {
33
+ const style: CSSProperties & Record<"--file-hue", number> = {
34
+ "--file-hue": hue,
35
+ };
36
+
37
+ return style;
36
38
  }
37
39
 
38
- function fileKind(attachment: MessageAttachment): FileKind {
40
+ function fileKind(attachment: MessageAttachment) {
39
41
  const { filename } = attachment;
40
42
  const dot = filename.lastIndexOf(".");
41
43
  const extension = dot === -1 ? "" : filename.slice(dot + 1).toLowerCase();
@@ -44,24 +46,30 @@ function fileKind(attachment: MessageAttachment): FileKind {
44
46
  const label = extension ? extension.toUpperCase().slice(0, 5) : "File";
45
47
 
46
48
  if (type === "application/pdf" || extension === "pdf") {
47
- return { label: "PDF", Icon: FileText, hue: 25 };
49
+ return { label: "PDF", Icon: FileText, hue: 25 } satisfies FileKind;
48
50
  }
49
51
 
50
- if (type.startsWith("image/")) return { label, Icon: FileImage, hue: 300 };
52
+ if (type.startsWith("image/")) {
53
+ return { label, Icon: FileImage, hue: 300 } satisfies FileKind;
54
+ }
51
55
 
52
- if (SHEET.test(extension)) return { label, Icon: FileSpreadsheet, hue: 150 };
56
+ if (SHEET.test(extension)) {
57
+ return { label, Icon: FileSpreadsheet, hue: 150 } satisfies FileKind;
58
+ }
53
59
 
54
- if (SLIDES.test(extension)) return { label, Icon: Presentation, hue: 55 };
60
+ if (SLIDES.test(extension)) {
61
+ return { label, Icon: Presentation, hue: 55 } satisfies FileKind;
62
+ }
55
63
 
56
64
  if (DOCUMENT.test(extension) || type.startsWith("text/")) {
57
- return { label, Icon: FileText, hue: 255 };
65
+ return { label, Icon: FileText, hue: 255 } satisfies FileKind;
58
66
  }
59
67
 
60
68
  if (ARCHIVE.test(extension) || type.includes("zip")) {
61
- return { label, Icon: FileArchive, hue: 80 };
69
+ return { label, Icon: FileArchive, hue: 80 } satisfies FileKind;
62
70
  }
63
71
 
64
- return { label, Icon: File, hue: 260 };
72
+ return { label, Icon: File, hue: 260 } satisfies FileKind;
65
73
  }
66
74
 
67
75
  export function MessageAttachments({
@@ -0,0 +1,53 @@
1
+ import { createContext } from "react";
2
+
3
+ import type { MessageDetail } from "./types";
4
+ import { useSanitizedEmailHtml } from "./use-sanitized-email-html";
5
+
6
+ export const TranslationEnabled = createContext(false);
7
+
8
+ /** Incoming HTML keeps its isolated document. Composer HTML is safe in the app itself. */
9
+ export type MessageBodyContent = {
10
+ format: "document" | "html" | "text";
11
+ value: string;
12
+ };
13
+
14
+ export function useMessageBody(
15
+ mailboxId: string | undefined,
16
+ message: MessageDetail
17
+ ) {
18
+ const html = useSanitizedEmailHtml(mailboxId ?? "", message);
19
+
20
+ let body: MessageBodyContent = {
21
+ format: "text",
22
+ value:
23
+ message.bodyText ||
24
+ (message.quotedText && !message.bodyHtml
25
+ ? "No new text"
26
+ : message.preview || "No text body"),
27
+ };
28
+
29
+ if (
30
+ mailboxId &&
31
+ message.direction === "incoming" &&
32
+ html.data?.renderAsHtml
33
+ ) {
34
+ body = { format: "document", value: html.data.srcDoc };
35
+ } else if (
36
+ mailboxId &&
37
+ message.direction === "outgoing" &&
38
+ html.data?.composerHtml
39
+ ) {
40
+ body = { format: "html", value: html.data.composerHtml };
41
+ }
42
+
43
+ return {
44
+ body,
45
+ quoteInBody: Boolean(
46
+ message.quotedText &&
47
+ !message.hasSeparateHtmlQuote &&
48
+ body.format !== "text" &&
49
+ html.data?.hasHtmlQuote
50
+ ),
51
+ ready: !(mailboxId && message.bodyHtml && html.isPending),
52
+ };
53
+ }
@@ -3,7 +3,9 @@ import { format, isThisYear, isToday } from "date-fns";
3
3
 
4
4
  import type { Mailbox, MessageDetail } from "./types";
5
5
 
6
- export function senderName(message: MessageDetail) {
6
+ export function senderName(
7
+ message: Pick<MessageDetail, "fromName" | "fromAddress">
8
+ ) {
7
9
  return message.fromName || message.fromAddress;
8
10
  }
9
11
 
@@ -45,7 +47,11 @@ function recipientLabel(address: string, mailbox?: Mailbox) {
45
47
  return isOwnAddress(address, mailbox) ? "me" : address;
46
48
  }
47
49
 
48
- export function recipientSummary(message: MessageDetail, mailbox?: Mailbox) {
50
+ export function recipientSummary(
51
+ message: Pick<MessageDetail, "toAddresses" | "ccAddresses" | "bccAddresses"> &
52
+ Partial<Pick<MessageDetail, "viaList">>,
53
+ mailbox?: Mailbox
54
+ ) {
49
55
  const to = message.toAddresses.map((address) =>
50
56
  recipientLabel(address, mailbox)
51
57
  );
@@ -73,7 +73,9 @@ export function SenderLine({
73
73
  own,
74
74
  onCollapse,
75
75
  }: {
76
- message: MessageDetail;
76
+ /** A message, or the list row's sender while the message loads. */
77
+ message: Pick<MessageDetail, "fromAddress"> &
78
+ Partial<Pick<MessageDetail, "security" | "sender">>;
77
79
  sender: string;
78
80
  own: boolean;
79
81
  onCollapse?: () => void;
@@ -1,7 +1,7 @@
1
1
  import { responseJson } from "@open-workspace/core/ui";
2
2
  import { useMutation } from "@tanstack/react-query";
3
3
  import { Languages, LoaderCircle } from "lucide-react";
4
- import { useMemo, useState } from "react";
4
+ import { useContext, useState } from "react";
5
5
  import { toast } from "sonner";
6
6
 
7
7
  import {
@@ -9,11 +9,11 @@ import {
9
9
  MAX_TRANSLATION_SEGMENTS,
10
10
  } from "../../shared/mail-translation";
11
11
  import { mailApi } from "../lib/mail-api";
12
- import { EmailHtmlBody, messageTextClassName } from "./email-html-body";
13
- import { emailHtmlTextSegments } from "./translation-html";
12
+ import { TranslationEnabled } from "./message-body";
13
+ import type { MessageBodyContent } from "./message-body";
14
+ import { emailHtmlTextSegments, translatedEmailHtml } from "./translation-html";
14
15
  import { browserLanguage, COMMON_LANGUAGES } from "./translation-language";
15
16
  import type { MessageDetail } from "./types";
16
- import { useSanitizedEmailHtml } from "./use-sanitized-email-html";
17
17
 
18
18
  type TranslationResult = {
19
19
  messageId: string;
@@ -36,29 +36,14 @@ export type MessageTranslationState = ReturnType<typeof useMessageTranslation>;
36
36
  */
37
37
  export function useMessageTranslation(
38
38
  message: MessageDetail,
39
+ source: MessageBodyContent,
40
+ ready: boolean,
39
41
  mailboxId?: string
40
42
  ) {
41
43
  const [language, setLanguage] = useState(browserLanguage);
42
44
  const [result, setResult] = useState<TranslationResult | null>(null);
43
45
  const [showTranslation, setShowTranslation] = useState(false);
44
- const html = useSanitizedEmailHtml(mailboxId ?? "", message);
45
-
46
- const sourceHtml =
47
- message.direction === "incoming"
48
- ? html.data?.renderAsHtml
49
- ? html.data.srcDoc
50
- : null
51
- : html.data?.composerHtml || null;
52
-
53
- const segments = useMemo(
54
- () =>
55
- sourceHtml
56
- ? emailHtmlTextSegments(sourceHtml)
57
- : [message.bodyText || message.preview].filter((text) =>
58
- Boolean(text.trim())
59
- ),
60
- [message.bodyText, message.preview, sourceHtml]
61
- );
46
+ const enabled = useContext(TranslationEnabled);
62
47
 
63
48
  const mutation = useMutation({
64
49
  mutationFn: async ({
@@ -79,7 +64,23 @@ export function useMessageTranslation(
79
64
  });
80
65
 
81
66
  const cached = result?.messageId === message.id ? result : null;
82
- const visible = showTranslation && cached?.language === language;
67
+ const visible = enabled && showTranslation && cached?.language === language;
68
+ const translations = visible ? cached.translations : undefined;
69
+ const { format, value } = source;
70
+
71
+ const body: MessageBodyContent = translations
72
+ ? {
73
+ format,
74
+ value:
75
+ (format === "text"
76
+ ? translations[0]
77
+ : translatedEmailHtml(
78
+ value,
79
+ translations,
80
+ format === "document"
81
+ )) ?? value,
82
+ }
83
+ : { format, value };
83
84
 
84
85
  const languages = COMMON_LANGUAGES.includes(language)
85
86
  ? COMMON_LANGUAGES
@@ -96,6 +97,11 @@ export function useMessageTranslation(
96
97
 
97
98
  setShowTranslation(false);
98
99
 
100
+ const segments =
101
+ format === "text"
102
+ ? [value].filter((text) => text.trim())
103
+ : emailHtmlTextSegments(value);
104
+
99
105
  if (!segments.length) {
100
106
  toast.error("Message has no text to translate");
101
107
 
@@ -133,16 +139,17 @@ export function useMessageTranslation(
133
139
  }
134
140
 
135
141
  return {
136
- available: Boolean(mailboxId && (message.bodyText || message.bodyHtml)),
137
- ready: !(message.bodyHtml && html.isPending),
142
+ available: Boolean(
143
+ enabled && mailboxId && (message.bodyText || message.bodyHtml)
144
+ ),
145
+ ready,
138
146
  pending: mutation.isPending,
139
147
  language,
140
148
  languages,
141
149
  /** Translated text is cached for the current language. */
142
150
  hasResult: cached?.language === language,
143
151
  visible,
144
- translations: visible ? cached.translations : undefined,
145
- sourceHtml,
152
+ body,
146
153
  translate,
147
154
  showOriginal: () => setShowTranslation(false),
148
155
  };
@@ -183,43 +190,3 @@ export function TranslationBar({
183
190
  </div>
184
191
  );
185
192
  }
186
-
187
- /** Message body: sanitized HTML, composer HTML or plain text, translated in place when requested. */
188
- export function MessageBody({
189
- message,
190
- mailboxId,
191
- translation,
192
- }: {
193
- message: MessageDetail;
194
- mailboxId?: string;
195
- translation: MessageTranslationState;
196
- }) {
197
- if (!mailboxId || !(message.bodyText || message.bodyHtml)) {
198
- return (
199
- <div className={messageTextClassName}>
200
- {message.bodyText ||
201
- (message.quotedText
202
- ? "No new text"
203
- : message.preview || "No text body")}
204
- </div>
205
- );
206
- }
207
-
208
- const { translations } = translation;
209
-
210
- if (message.bodyHtml && (!translations || translation.sourceHtml)) {
211
- return (
212
- <EmailHtmlBody
213
- mailboxId={mailboxId}
214
- message={message}
215
- translations={translations}
216
- />
217
- );
218
- }
219
-
220
- return (
221
- <div className={messageTextClassName}>
222
- {translations ? translations[0] : message.bodyText}
223
- </div>
224
- );
225
- }
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  Button,
3
3
  buttonVariants,
4
+ DelayedFallback,
4
5
  Sheet,
5
6
  SheetContent,
6
7
  SheetDescription,
@@ -23,7 +24,7 @@ import {
23
24
  ShieldCheck,
24
25
  Sparkles,
25
26
  } from "lucide-react";
26
- import { useMemo, useState } from "react";
27
+ import { useState } from "react";
27
28
  import type { ReactNode } from "react";
28
29
  import { z } from "zod";
29
30
 
@@ -384,23 +385,20 @@ function OriginalMessageBody({
384
385
  const original = details.data?.original;
385
386
  const senderIntel = details.data?.senderIntel ?? message.senderIntel;
386
387
 
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
- );
388
+ const hops = source.data ? receivedHops(source.data) : [];
389
+
390
+ const parsed = source.data
391
+ ? {
392
+ hops,
393
+ transit: transitTime(source.data, hops),
394
+ sender: originalSenderDetails(source.data, authentication, hops),
395
+ parts: mimeStructure(source.data),
396
+ }
397
+ : null;
398
+
399
+ const sourceBytes = source.data
400
+ ? new TextEncoder().encode(source.data).byteLength
401
+ : null;
404
402
 
405
403
  function senderRows(sender: NonNullable<typeof parsed>["sender"]) {
406
404
  const rows: [string, ReactNode][] = [
@@ -503,18 +501,23 @@ function OriginalMessageBody({
503
501
  ) : undefined
504
502
  }
505
503
  >
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
- )}
504
+ <DelayedFallback
505
+ pending={details.isLoading}
506
+ fallback={
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
+ }
512
+ >
513
+ {details.isError ? (
514
+ <p className="text-destructive text-xs">
515
+ {details.error.message}
516
+ </p>
517
+ ) : (
518
+ <SenderAuthentication authentication={authentication} />
519
+ )}
520
+ </DelayedFallback>
518
521
  </Section>
519
522
 
520
523
  {parsed && (
@@ -525,15 +528,20 @@ function OriginalMessageBody({
525
528
  </div>
526
529
  <div className="min-w-0">
527
530
  <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
- )}
531
+ <DelayedFallback
532
+ pending={!parsed}
533
+ fallback={
534
+ <p className="text-muted-foreground text-xs">Loading…</p>
535
+ }
536
+ >
537
+ {parsed ? (
538
+ <DeliveryPath
539
+ hops={parsed.hops}
540
+ transit={parsed.transit}
541
+ deliveredAt={new Date(message.timelineAt)}
542
+ />
543
+ ) : null}
544
+ </DelayedFallback>
537
545
  </Section>
538
546
  {parsed && parsed.parts.length > 0 && (
539
547
  <Section title="Structure">
@@ -570,17 +578,22 @@ function OriginalMessageBody({
570
578
  </div>
571
579
  }
572
580
  >
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
- )}
581
+ <DelayedFallback
582
+ pending={source.isLoading}
583
+ fallback={
584
+ <div className="bg-surface-sunken text-muted-foreground grid h-40 place-items-center rounded-md">
585
+ <LoaderCircle className="size-4 animate-spin" />
586
+ </div>
587
+ }
588
+ >
589
+ {source.isError ? (
590
+ <p className="text-destructive text-xs">{source.error.message}</p>
591
+ ) : (
592
+ <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">
593
+ {source.data}
594
+ </pre>
595
+ )}
596
+ </DelayedFallback>
584
597
  </Section>
585
598
  </div>
586
599
  );
@@ -27,7 +27,7 @@ export function dkimSigningDomains(raw: string) {
27
27
  }
28
28
 
29
29
  function headerValue(raw: string, name: string) {
30
- return originalHeaderValues(raw, name)[0] ?? null;
30
+ return originalHeaderValues(raw, name).at(0) ?? null;
31
31
  }
32
32
 
33
33
  function tagValue(value: string, tag: string) {
@@ -44,7 +44,7 @@ type DkimSignature = {
44
44
  signedHeaders: string[];
45
45
  };
46
46
 
47
- export function dkimSignatures(raw: string): DkimSignature[] {
47
+ export function dkimSignatures(raw: string) {
48
48
  return originalHeaderValues(raw, "dkim-signature").flatMap((signature) => {
49
49
  const domain = tagValue(signature, "d");
50
50
 
@@ -59,7 +59,7 @@ export function dkimSignatures(raw: string): DkimSignature[] {
59
59
  .split(":")
60
60
  .map((header) => header.trim().toLocaleLowerCase())
61
61
  .filter(Boolean),
62
- },
62
+ } satisfies DkimSignature,
63
63
  ];
64
64
  });
65
65
  }
@@ -122,7 +122,7 @@ function walkMime(entity: string, depth: number, parts: MimePart[]) {
122
122
  }
123
123
 
124
124
  /** Flattened MIME tree, parents before children, capped for huge messages. */
125
- export function mimeStructure(raw: string): MimePart[] {
125
+ export function mimeStructure(raw: string) {
126
126
  const parts: MimePart[] = [];
127
127
  walkMime(raw, 0, parts);
128
128
 
@@ -146,7 +146,7 @@ export function originalSenderDetails(
146
146
  "remoteIp" | "envelopeFrom"
147
147
  > | null = null,
148
148
  hops: ReceivedHop[] = receivedHops(raw)
149
- ): OriginalSenderDetails {
149
+ ) {
150
150
  const trustedHop = hops.find((hop) => hop.trusted);
151
151
 
152
152
  return {
@@ -158,7 +158,7 @@ export function originalSenderDetails(
158
158
  mailer: headerValue(raw, "x-mailer") ?? headerValue(raw, "user-agent"),
159
159
  listId: headerValue(raw, "list-id"),
160
160
  precedence: headerValue(raw, "precedence"),
161
- };
161
+ } satisfies OriginalSenderDetails;
162
162
  }
163
163
 
164
164
  /**