@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,470 @@
1
+ import {
2
+ Badge,
3
+ Button,
4
+ useConfirm,
5
+ cn,
6
+ DropdownMenu,
7
+ DropdownMenuContent,
8
+ DropdownMenuGroup,
9
+ DropdownMenuItem,
10
+ DropdownMenuLabel,
11
+ DropdownMenuTrigger,
12
+ InputGroup,
13
+ InputGroupAddon,
14
+ InputGroupButton,
15
+ InputGroupText,
16
+ InputGroupTextarea,
17
+ } from "@open-workspace/core/ui";
18
+ import {
19
+ Check,
20
+ ChevronDown,
21
+ LoaderCircle,
22
+ Paperclip,
23
+ Reply,
24
+ ReplyAll,
25
+ Send,
26
+ Users,
27
+ X,
28
+ } from "lucide-react";
29
+ import { useMemo, useRef, useState } from "react";
30
+ import type { DragEvent } from "react";
31
+
32
+ import { normalizeExternalEmailAddress } from "../../shared/mail";
33
+ import { ComposerAttachmentList } from "./composer-attachment-list";
34
+ import {
35
+ recipientsWithPendingInput,
36
+ validateComposerRecipients,
37
+ } from "./composer-recipients";
38
+ import type { RecipientFieldValue } from "./composer-recipients";
39
+ import { useComposerSession } from "./composer-session";
40
+ import { RecipientCombobox } from "./recipient-combobox";
41
+ import { ReplyToWarning } from "./reply-to-warning";
42
+ import type {
43
+ Mailbox,
44
+ MessageDetail,
45
+ ReplyAction,
46
+ ReplyActionMode,
47
+ } from "./types";
48
+ import { useComposerAttachmentPreflight } from "./use-composer-attachment-preflight";
49
+ import { useReplySubmission } from "./use-reply-submission";
50
+ import type { SentReply } from "./use-reply-submission";
51
+
52
+ export type { SentReply } from "./use-reply-submission";
53
+
54
+ const EMPTY_RECIPIENT_FIELD: RecipientFieldValue = {
55
+ recipients: [],
56
+ input: "",
57
+ };
58
+
59
+ function recipientField(addresses: string[]): RecipientFieldValue {
60
+ return {
61
+ recipients: addresses.map((address) => ({ address, name: null })),
62
+ input: "",
63
+ };
64
+ }
65
+
66
+ function recipientAddresses(value: RecipientFieldValue) {
67
+ return recipientsWithPendingInput(value).map(
68
+ (recipient) => recipient.address
69
+ );
70
+ }
71
+
72
+ function recipientAddressSet(value: RecipientFieldValue) {
73
+ return new Set(recipientAddresses(value).map(normalizeExternalEmailAddress));
74
+ }
75
+
76
+ export function ConversationReply({
77
+ mailbox,
78
+ parent,
79
+ mode,
80
+ onModeChange,
81
+ onCancel,
82
+ onSent,
83
+ }: {
84
+ mailbox?: Mailbox;
85
+ parent: MessageDetail;
86
+ mode: ReplyActionMode;
87
+ onModeChange: (mode: ReplyActionMode) => void;
88
+ onCancel: () => void;
89
+ onSent: (result: SentReply) => void;
90
+ }) {
91
+ const fileInput = useRef<HTMLInputElement>(null);
92
+ const initialAction = findAction(parent, mode);
93
+ const fieldsSource = `${mode}\0${parent.id}`;
94
+ const [body, setBody] = useState("");
95
+ const [cc, setCc] = useState(() => recipientField(initialAction?.cc ?? []));
96
+ const [bcc, setBcc] = useState<RecipientFieldValue>(EMPTY_RECIPIENT_FIELD);
97
+ const [showCc, setShowCc] = useState(Boolean(initialAction?.cc.length));
98
+ const [showBcc, setShowBcc] = useState(false);
99
+ const [ccSource, setCcSource] = useState(fieldsSource);
100
+
101
+ // Another reply mode or parent message resets Cc to its own; adjusted
102
+ // while rendering, so the old Cc never shows with the new reply.
103
+ if (ccSource !== fieldsSource) {
104
+ setCcSource(fieldsSource);
105
+ setCc(recipientField(initialAction?.cc ?? []));
106
+ setShowCc(Boolean(initialAction?.cc.length));
107
+ }
108
+
109
+ const { session, snapshot } = useComposerSession(mailbox?.id ?? "");
110
+ const activeAssets = snapshot.assets;
111
+ const uploadLimitError = session.limitError();
112
+
113
+ const uploadsPending = activeAssets.some(
114
+ (asset) => asset.status === "uploading"
115
+ );
116
+
117
+ const uploadsFailed = activeAssets.some((asset) => asset.status === "error");
118
+ const action = useMemo(() => findAction(parent, mode), [mode, parent]);
119
+
120
+ const recipients = validateComposerRecipients({
121
+ to: recipientField(action?.to ?? []),
122
+ cc,
123
+ bcc,
124
+ });
125
+
126
+ useComposerAttachmentPreflight(
127
+ session,
128
+ {
129
+ kind: "reply",
130
+ mailboxId: mailbox?.id ?? "",
131
+ sourceEmailId: parent.id,
132
+ mode: action?.mode ?? mode,
133
+ cc: recipients.cc,
134
+ bcc: recipients.bcc,
135
+ bodyText: body,
136
+ },
137
+ activeAssets,
138
+ snapshot.phase === "editing" && Boolean(mailbox && action)
139
+ );
140
+
141
+ const submission = useReplySubmission({
142
+ session,
143
+ phase: snapshot.phase,
144
+ mailbox,
145
+ parent,
146
+ action,
147
+ recipients,
148
+ body,
149
+ uploadLimitError,
150
+ uploadsPending,
151
+ uploadsFailed,
152
+ onSuccess: (result) => {
153
+ setBody("");
154
+ setBcc(EMPTY_RECIPIENT_FIELD);
155
+ onSent(result);
156
+ },
157
+ });
158
+
159
+ const { busy } = submission;
160
+ const { confirm, dialog: confirmDialog } = useConfirm();
161
+ const linkedIds = snapshot.linkedAssetIds;
162
+
163
+ const toAddresses = new Set(
164
+ (action?.to ?? []).map(normalizeExternalEmailAddress)
165
+ );
166
+
167
+ const ccExcludedAddresses = new Set([
168
+ ...toAddresses,
169
+ ...recipientAddressSet(bcc),
170
+ ]);
171
+
172
+ const bccExcludedAddresses = new Set([
173
+ ...toAddresses,
174
+ ...recipientAddressSet(cc),
175
+ ]);
176
+
177
+ if (!mailbox?.canSend || !action || action.to.length === 0) return null;
178
+
179
+ function selectAction(next: ReplyAction) {
180
+ onModeChange(next.mode);
181
+ setCc(recipientField(next.cc));
182
+ setShowCc(next.cc.length > 0);
183
+ }
184
+
185
+ async function cancel() {
186
+ if (
187
+ (body.trim() || activeAssets.length > 0) &&
188
+ !(await confirm({
189
+ title: "Discard this reply?",
190
+ description:
191
+ activeAssets.length > 0
192
+ ? "The text you wrote and its attachments are deleted."
193
+ : "The text you wrote is deleted.",
194
+ action: "Discard reply",
195
+ destructive: true,
196
+ }))
197
+ ) {
198
+ return;
199
+ }
200
+
201
+ onCancel();
202
+ }
203
+
204
+ function handleDrop(event: DragEvent<HTMLFormElement>) {
205
+ if (!event.dataTransfer.types.includes("Files")) return;
206
+ event.preventDefault();
207
+
208
+ if (busy) return;
209
+ session.addFiles(Array.from(event.dataTransfer.files), "attachment");
210
+ }
211
+
212
+ return (
213
+ <div>
214
+ {confirmDialog}
215
+ {/* oxlint-disable-next-line jsx-a11y/no-noninteractive-element-interactions -- files can be dropped anywhere on the form */}
216
+ <form
217
+ className="animate-rise border-input bg-surface focus-within:border-ring/60 focus-within:ring-ring/12 overflow-hidden rounded-lg border shadow-sm transition-shadow focus-within:ring-3"
218
+ aria-busy={busy}
219
+ onDragOver={(event) => {
220
+ if (!event.dataTransfer.types.includes("Files")) return;
221
+ event.preventDefault();
222
+ event.dataTransfer.dropEffect = busy ? "none" : "copy";
223
+ }}
224
+ onDrop={handleDrop}
225
+ onSubmit={(event) => {
226
+ event.preventDefault();
227
+ void submission.submit();
228
+ }}
229
+ >
230
+ <div className="border-border flex min-h-10 items-center gap-2 border-b px-2">
231
+ <DropdownMenu>
232
+ <DropdownMenuTrigger
233
+ render={
234
+ <Button
235
+ type="button"
236
+ variant="ghost"
237
+ size="sm"
238
+ className="h-7 px-2"
239
+ disabled={busy}
240
+ />
241
+ }
242
+ >
243
+ <ReplyActionIcon mode={action.mode} />
244
+ {action.label}
245
+ <ChevronDown className="size-3.5" />
246
+ </DropdownMenuTrigger>
247
+ <DropdownMenuContent
248
+ align="start"
249
+ className="w-80 max-w-[calc(100vw-2rem)]"
250
+ >
251
+ <DropdownMenuGroup>
252
+ <DropdownMenuLabel>
253
+ Recipients from this message
254
+ </DropdownMenuLabel>
255
+ {parent.replyPlan.actions.map((candidate) => (
256
+ <DropdownMenuItem
257
+ key={candidate.mode}
258
+ disabled={busy}
259
+ onClick={() => selectAction(candidate)}
260
+ >
261
+ <ReplyActionIcon mode={candidate.mode} />
262
+ <span className="min-w-0 flex-1">
263
+ <span className="block">{candidate.label}</span>
264
+ <span className="text-muted-foreground block truncate text-xs">
265
+ {[...candidate.to, ...candidate.cc].join(", ")}
266
+ </span>
267
+ </span>
268
+ {candidate.mode === mode && <Check />}
269
+ </DropdownMenuItem>
270
+ ))}
271
+ </DropdownMenuGroup>
272
+ </DropdownMenuContent>
273
+ </DropdownMenu>
274
+
275
+ {action.mode === "reply_all" && (
276
+ <Badge variant="secondary">
277
+ {recipients.to.length + recipients.cc.length} people
278
+ </Badge>
279
+ )}
280
+ <div className="ml-auto flex items-center">
281
+ {!showCc && (
282
+ <Button
283
+ type="button"
284
+ variant="ghost"
285
+ size="xs"
286
+ className="text-muted-foreground"
287
+ disabled={busy}
288
+ onClick={() => setShowCc(true)}
289
+ >
290
+ Cc
291
+ </Button>
292
+ )}
293
+ {!showBcc && (
294
+ <Button
295
+ type="button"
296
+ variant="ghost"
297
+ size="xs"
298
+ className="text-muted-foreground"
299
+ disabled={busy}
300
+ onClick={() => setShowBcc(true)}
301
+ >
302
+ Bcc
303
+ </Button>
304
+ )}
305
+ <Button
306
+ type="button"
307
+ variant="ghost"
308
+ size="icon-xs"
309
+ className="text-muted-foreground ml-1"
310
+ aria-label="Discard reply"
311
+ disabled={busy}
312
+ onClick={cancel}
313
+ >
314
+ <X />
315
+ </Button>
316
+ </div>
317
+ </div>
318
+
319
+ <div className="border-border text-muted-foreground truncate border-b px-3.5 py-2 text-xs">
320
+ Replying to{" "}
321
+ <span className="text-foreground font-semibold">
322
+ {parent.fromName || parent.fromAddress}
323
+ </span>
324
+ <span aria-hidden="true"> · </span>
325
+ {parent.preview}
326
+ </div>
327
+ <ReplyToWarning
328
+ message={parent}
329
+ recipients={[...recipients.to, ...recipients.cc, ...recipients.bcc]}
330
+ className="border-border border-b"
331
+ />
332
+
333
+ {showCc && (
334
+ <div className="border-border border-b px-3">
335
+ <RecipientCombobox
336
+ mailboxId={mailbox.id}
337
+ label="Cc"
338
+ value={cc}
339
+ excludedAddresses={ccExcludedAddresses}
340
+ disabled={busy}
341
+ onChange={setCc}
342
+ />
343
+ </div>
344
+ )}
345
+ {showBcc && (
346
+ <div className="border-border border-b px-3">
347
+ <RecipientCombobox
348
+ mailboxId={mailbox.id}
349
+ label="Bcc"
350
+ value={bcc}
351
+ excludedAddresses={bccExcludedAddresses}
352
+ disabled={busy}
353
+ onChange={setBcc}
354
+ />
355
+ </div>
356
+ )}
357
+
358
+ <InputGroup className="min-h-24 rounded-none border-0 bg-transparent shadow-none has-[[data-slot=input-group-control]:focus-visible]:ring-0 dark:bg-transparent">
359
+ <InputGroupTextarea
360
+ className="min-h-28 px-3.5 pt-3 text-[0.9375rem] leading-[1.65]"
361
+ value={body}
362
+ disabled={busy}
363
+ onChange={(event) => setBody(event.target.value)}
364
+ onKeyDown={(event) => {
365
+ if (
366
+ !busy &&
367
+ (event.metaKey || event.ctrlKey) &&
368
+ event.key === "Enter" &&
369
+ (body.trim() || activeAssets.length > 0)
370
+ ) {
371
+ event.preventDefault();
372
+ void submission.submit();
373
+ }
374
+ }}
375
+ placeholder={
376
+ action.mode === "reply_all"
377
+ ? "Reply to everyone"
378
+ : `Reply to ${action.to.join(", ")}`
379
+ }
380
+ />
381
+ <InputGroupAddon
382
+ align="block-end"
383
+ className="border-border border-t px-2 py-1.5"
384
+ >
385
+ <input
386
+ ref={fileInput}
387
+ className="sr-only"
388
+ type="file"
389
+ multiple
390
+ disabled={busy}
391
+ onChange={(event) => {
392
+ session.addFiles(
393
+ Array.from(event.target.files ?? []),
394
+ "attachment"
395
+ );
396
+ event.target.value = "";
397
+ }}
398
+ />
399
+ <InputGroupButton
400
+ size="icon-sm"
401
+ disabled={busy}
402
+ onClick={() => fileInput.current?.click()}
403
+ >
404
+ <Paperclip />
405
+ <span className="sr-only">Add attachments</span>
406
+ </InputGroupButton>
407
+ <InputGroupText
408
+ className={cn(
409
+ "min-w-0 flex-1 text-xs",
410
+ (uploadLimitError || snapshot.planError) && "text-destructive"
411
+ )}
412
+ >
413
+ {uploadLimitError ||
414
+ (activeAssets.length > 0 && snapshot.planError ? (
415
+ "Could not check attachment delivery"
416
+ ) : activeAssets.length ? (
417
+ `${activeAssets.length} attachment${activeAssets.length === 1 ? "" : "s"}`
418
+ ) : (
419
+ <span className="hidden sm:inline">Ctrl + Enter to send</span>
420
+ ))}
421
+ </InputGroupText>
422
+ <Button
423
+ type="submit"
424
+ size="sm"
425
+ disabled={
426
+ busy ||
427
+ Boolean(uploadLimitError) ||
428
+ uploadsPending ||
429
+ uploadsFailed
430
+ }
431
+ >
432
+ {busy ? <LoaderCircle className="animate-spin" /> : <Send />}
433
+ Send
434
+ </Button>
435
+ </InputGroupAddon>
436
+ </InputGroup>
437
+
438
+ <ComposerAttachmentList
439
+ uploads={activeAssets}
440
+ linkedIds={linkedIds}
441
+ progress={session.progress}
442
+ disabled={busy}
443
+ onRemove={(asset) => session.remove(asset.id)}
444
+ onRetry={(asset) => void session.retry(asset.id)}
445
+ />
446
+ </form>
447
+ </div>
448
+ );
449
+ }
450
+
451
+ /** The plan's action for the mode, else its default; none for an empty plan. */
452
+ function findAction(parent: MessageDetail, requestedMode: ReplyActionMode) {
453
+ return (
454
+ parent.replyPlan.actions.find((action) => action.mode === requestedMode) ??
455
+ parent.replyPlan.actions.find(
456
+ (action) => action.mode === parent.replyPlan.defaultMode
457
+ ) ??
458
+ parent.replyPlan.actions[0]
459
+ );
460
+ }
461
+
462
+ export function ReplyActionIcon({ mode }: { mode: ReplyActionMode }) {
463
+ if (mode === "reply_all") return <ReplyAll />;
464
+
465
+ if (mode === "reply_list") return <Users />;
466
+
467
+ if (mode === "continue") return <Send />;
468
+
469
+ return <Reply />;
470
+ }