@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
@@ -15,6 +15,7 @@ import {
15
15
  TabsTrigger,
16
16
  TooltipProvider,
17
17
  responseJson,
18
+ usePrefetchOnIntent,
18
19
  } from "@open-workspace/core/ui";
19
20
  import { useMutation, useQueryClient } from "@tanstack/react-query";
20
21
  import {
@@ -23,6 +24,7 @@ import {
23
24
  Check,
24
25
  Folder,
25
26
  FolderCog,
27
+ ListFilter,
26
28
  LoaderCircle,
27
29
  Pencil,
28
30
  Plus,
@@ -32,10 +34,11 @@ import {
32
34
  X,
33
35
  } from "lucide-react";
34
36
  import { useLayoutEffect, useRef, useState } from "react";
35
- import type { FormEvent } from "react";
37
+ import { useForm, useWatch } from "react-hook-form";
36
38
  import { toast } from "sonner";
37
39
 
38
40
  import {
41
+ DRAFTS_FOLDER_ID,
39
42
  folderOrderPositions,
40
43
  moveFolderInOrder,
41
44
  } from "../../shared/folder-order";
@@ -43,8 +46,10 @@ import { mailApi } from "../lib/mail-api";
43
46
  import { BlockedSendersManager } from "./blocked-senders";
44
47
  import { FolderGlyph } from "./folder-glyph";
45
48
  import { orderedFolders } from "./mail-folders";
46
- import { foldersQuery } from "./mail-queries";
49
+ import { foldersQuery, prefetchMailboxOrganization } from "./mail-queries";
50
+ import { applyMailboxChange } from "./mail-query-cache";
47
51
  import { MailboxAiSettings } from "./mailbox-ai-settings";
52
+ import { MailboxRules } from "./mailbox-rules";
48
53
  import { ToolbarTooltip } from "./toolbar-tooltip";
49
54
  import type { MailFolder } from "./types";
50
55
 
@@ -64,27 +69,34 @@ export function FolderManager({
64
69
  folders,
65
70
  onSelectFolder,
66
71
  controlled,
72
+ canOrganize,
67
73
  }: {
68
74
  mailboxId: string;
75
+ /** False for a shared inbox to someone who doesn't manage teams. */
76
+ canOrganize: boolean;
69
77
  activeFolderId: string;
70
78
  folders: MailFolder[];
71
79
  onSelectFolder: (folderId: string) => void;
72
80
  controlled?: { open: boolean; onOpenChange: (open: boolean) => void };
73
81
  }) {
74
82
  const client = useQueryClient();
83
+ const intent = usePrefetchOnIntent();
75
84
 
76
- // Every folder but Inbox, which stays first: system folders move too, but keep their names.
85
+ // Every folder but Inbox, which stays first, and Drafts, which follows
86
+ // Sent: system folders move too, but keep their names.
77
87
  const orderable = orderedFolders(folders).filter(
78
- (folder) => folder.id !== "inbox"
88
+ (folder) => folder.id !== "inbox" && folder.id !== DRAFTS_FOLDER_ID
79
89
  );
80
90
 
81
91
  const hasCustomFolders = orderable.some((folder) => folder.kind === "custom");
82
92
  const [ownOpen, setOwnOpen] = useState(false);
83
93
  const open = controlled ? controlled.open : ownOpen;
84
94
  const setOpen = controlled ? controlled.onOpenChange : setOwnOpen;
85
- const [newName, setNewName] = useState("");
95
+ const createForm = useForm({ defaultValues: { name: "" } });
96
+ const renameForm = useForm({ defaultValues: { name: "" } });
97
+ const newName = useWatch({ control: createForm.control, name: "name" });
98
+ const editingName = useWatch({ control: renameForm.control, name: "name" });
86
99
  const [editingId, setEditingId] = useState<string | null>(null);
87
- const [editingName, setEditingName] = useState("");
88
100
 
89
101
  const [deleteCandidate, setDeleteCandidate] = useState<MailFolder | null>(
90
102
  null
@@ -118,9 +130,9 @@ export function FolderManager({
118
130
  })
119
131
  );
120
132
  },
121
- onSuccess: async (_result, operation) => {
133
+ onSuccess: (_result, operation) => {
122
134
  if (operation.type === "create") {
123
- setNewName("");
135
+ createForm.reset();
124
136
  toast.success("Folder created");
125
137
  } else if (operation.type === "rename") {
126
138
  setEditingId(null);
@@ -132,10 +144,7 @@ export function FolderManager({
132
144
  toast.success("Folder deleted; its conversations moved to Inbox");
133
145
  }
134
146
 
135
- await Promise.all([
136
- client.invalidateQueries({ queryKey: ["folders", mailboxId] }),
137
- client.invalidateQueries({ queryKey: ["conversations", mailboxId] }),
138
- ]);
147
+ applyMailboxChange(client, mailboxId);
139
148
  },
140
149
  onError: async (error) => {
141
150
  toast.error(error.message);
@@ -187,19 +196,16 @@ export function FolderManager({
187
196
  },
188
197
  });
189
198
 
190
- function createFolder(event: FormEvent) {
191
- event.preventDefault();
192
- const name = newName.trim();
193
-
194
- if (name) mutation.mutate({ type: "create", name });
195
- }
196
-
197
- function renameFolder(event: FormEvent, folderId: string) {
198
- event.preventDefault();
199
- const name = editingName.trim();
199
+ const createFolder = createForm.handleSubmit(({ name }) => {
200
+ if (name.trim()) mutation.mutate({ type: "create", name: name.trim() });
201
+ });
200
202
 
201
- if (name) mutation.mutate({ type: "rename", folderId, name });
202
- }
203
+ const renameFolder = (folderId: string) =>
204
+ renameForm.handleSubmit(({ name }) => {
205
+ if (name.trim()) {
206
+ mutation.mutate({ type: "rename", folderId, name: name.trim() });
207
+ }
208
+ });
203
209
 
204
210
  // A moved row's arrow keeps focus, so the keyboard can press it again; at
205
211
  // either end, where that arrow turns off, focus goes to the other one.
@@ -257,6 +263,9 @@ export function FolderManager({
257
263
  {controlled ? null : (
258
264
  <ToolbarTooltip label="Manage folders and AI sorting" side="bottom">
259
265
  <DialogTrigger
266
+ {...intent((queryClient) =>
267
+ prefetchMailboxOrganization(queryClient, mailboxId)
268
+ )}
260
269
  render={
261
270
  <Button
262
271
  type="button"
@@ -271,7 +280,7 @@ export function FolderManager({
271
280
  </DialogTrigger>
272
281
  </ToolbarTooltip>
273
282
  )}
274
- <DialogContent className="sm:max-w-xl">
283
+ <DialogContent anchor="top" className="sm:max-w-xl">
275
284
  <DialogHeader>
276
285
  <DialogTitle>Folders &amp; AI sorting</DialogTitle>
277
286
  <DialogDescription>
@@ -284,7 +293,8 @@ export function FolderManager({
284
293
  value={section}
285
294
  onValueChange={(value) => setSection(String(value))}
286
295
  >
287
- <TabsList className="w-full">
296
+ {/* Four tabs fit a phone only as words. */}
297
+ <TabsList className="w-full max-sm:[&_svg]:hidden">
288
298
  <TabsTrigger value="folders">
289
299
  <Folder />
290
300
  Folders
@@ -293,6 +303,10 @@ export function FolderManager({
293
303
  <ShieldBan />
294
304
  Blocked
295
305
  </TabsTrigger>
306
+ <TabsTrigger value="rules">
307
+ <ListFilter />
308
+ Rules
309
+ </TabsTrigger>
296
310
  <TabsTrigger value="ai">
297
311
  <Sparkles />
298
312
  AI sorting
@@ -300,13 +314,21 @@ export function FolderManager({
300
314
  </TabsList>
301
315
 
302
316
  <TabsContent value="folders" className="space-y-4 pt-2">
303
- <form className="flex gap-2" onSubmit={createFolder}>
317
+ {canOrganize ? null : (
318
+ <p className="text-muted-foreground text-sm">
319
+ Only people who manage teams change a shared inbox's folders.
320
+ </p>
321
+ )}
322
+ <form
323
+ className="flex gap-2"
324
+ hidden={!canOrganize}
325
+ onSubmit={createFolder}
326
+ >
304
327
  <Input
305
328
  aria-label="New folder name"
306
329
  maxLength={80}
307
330
  placeholder="New folder name"
308
- value={newName}
309
- onChange={(event) => setNewName(event.target.value)}
331
+ {...createForm.register("name")}
310
332
  />
311
333
  <Button
312
334
  type="submit"
@@ -334,16 +356,13 @@ export function FolderManager({
334
356
  {editingId === folder.id ? (
335
357
  <form
336
358
  className="flex min-w-0 flex-1 items-center gap-2"
337
- onSubmit={(event) => renameFolder(event, folder.id)}
359
+ onSubmit={renameFolder(folder.id)}
338
360
  >
339
361
  <Input
340
362
  autoFocus
341
363
  aria-label={`Rename ${folder.name}`}
342
364
  maxLength={80}
343
- value={editingName}
344
- onChange={(event) =>
345
- setEditingName(event.target.value)
346
- }
365
+ {...renameForm.register("name")}
347
366
  />
348
367
  <ToolbarTooltip label="Save name">
349
368
  <Button
@@ -378,7 +397,10 @@ export function FolderManager({
378
397
  <span className="min-w-0 flex-1 truncate text-sm font-medium">
379
398
  {folder.name}
380
399
  </span>
381
- <div className="flex shrink-0 items-center">
400
+ <div
401
+ className="flex shrink-0 items-center"
402
+ hidden={!canOrganize}
403
+ >
382
404
  <ToolbarTooltip label="Move up">
383
405
  <Button
384
406
  type="button"
@@ -419,7 +441,7 @@ export function FolderManager({
419
441
  disabled={mutation.isPending}
420
442
  onClick={() => {
421
443
  setEditingId(folder.id);
422
- setEditingName(folder.name);
444
+ renameForm.reset({ name: folder.name });
423
445
  }}
424
446
  >
425
447
  <Pencil />
@@ -466,17 +488,28 @@ export function FolderManager({
466
488
  </p>
467
489
  </TabsContent>
468
490
 
491
+ {/* Every tab loads as the dialog opens, so picking one never waits. */}
469
492
  <TabsContent value="blocked" className="pt-2">
470
493
  <BlockedSendersManager
471
494
  mailboxId={mailboxId}
472
- active={open && section === "blocked"}
495
+ active={open}
496
+ canOrganize={canOrganize}
497
+ />
498
+ </TabsContent>
499
+
500
+ <TabsContent value="rules" keepMounted className="pt-2">
501
+ <MailboxRules
502
+ mailboxId={mailboxId}
503
+ folders={folders}
504
+ active={open}
473
505
  />
474
506
  </TabsContent>
475
507
 
476
508
  <TabsContent value="ai" keepMounted className="space-y-4 pt-2">
477
509
  <MailboxAiSettings
478
510
  mailboxId={mailboxId}
479
- active={open && section === "ai"}
511
+ active={open}
512
+ canEdit={canOrganize}
480
513
  />
481
514
  </TabsContent>
482
515
  </Tabs>
@@ -14,6 +14,8 @@ import {
14
14
  cn,
15
15
  initials,
16
16
  AppSwitcher,
17
+ prefetchScreen,
18
+ usePrefetchOnIntent,
17
19
  useWorkspaceBrand,
18
20
  WorkspaceLogo,
19
21
  } from "@open-workspace/core/ui";
@@ -113,7 +115,8 @@ export function SearchField({
113
115
  ref={inputRef}
114
116
  type="search"
115
117
  value={mail.search}
116
- placeholder={`Search ${mail.folderName.toLowerCase() === "inbox" ? "mail" : `in ${mail.folderName}`}`}
118
+ // The server searches the open folder only.
119
+ placeholder={`Search in ${mail.folderName}`}
117
120
  onChange={(event) => mail.setSearch(event.target.value)}
118
121
  onKeyDown={(event) => {
119
122
  if (event.key === "Escape") {
@@ -150,6 +153,7 @@ function AccountMenu({ mail }: { mail: MailController }) {
150
153
  const auth = useAuth();
151
154
  const { user } = auth;
152
155
  const fallback = initials(user?.name ?? "?");
156
+ const intent = usePrefetchOnIntent();
153
157
 
154
158
  return (
155
159
  <DropdownMenu>
@@ -200,12 +204,20 @@ function AccountMenu({ mail }: { mail: MailController }) {
200
204
  <DropdownMenuSeparator />
201
205
  <AppearanceMenuRow />
202
206
  <DropdownMenuSeparator />
203
- <DropdownMenuItem onClick={mail.openSettings}>
207
+ <DropdownMenuItem
208
+ {...intent((queryClient) =>
209
+ prefetchScreen(queryClient, "/settings/profile")
210
+ )}
211
+ onClick={mail.openSettings}
212
+ >
204
213
  <Settings />
205
214
  Settings
206
215
  </DropdownMenuItem>
207
216
  {Boolean(user?.permissions.length) && (
208
- <DropdownMenuItem onClick={mail.openAdministration}>
217
+ <DropdownMenuItem
218
+ {...intent((queryClient) => prefetchScreen(queryClient, "/admin"))}
219
+ onClick={mail.openAdministration}
220
+ >
209
221
  <ShieldCheck />
210
222
  Administration
211
223
  </DropdownMenuItem>
@@ -4,14 +4,16 @@ import {
4
4
  TooltipTrigger,
5
5
  useActiveInView,
6
6
  useEdgeFade,
7
+ usePrefetchOnIntent,
7
8
  cn,
8
9
  } from "@open-workspace/core/ui";
9
10
  import { FolderCog, PenLine } from "lucide-react";
10
11
  import { useRef } from "react";
11
12
 
12
13
  import { FolderGlyph } from "./folder-glyph";
13
- import { orderedFolders, unreadOf } from "./mail-folders";
14
+ import { folderCountLabel, orderedFolders, unreadOf } from "./mail-folders";
14
15
  import { DockMailboxSwitcher } from "./mail-mailbox-sheet";
16
+ import { prefetchMailboxOrganization } from "./mail-queries";
15
17
  import type { MailController } from "./use-mail-controller";
16
18
 
17
19
  /**
@@ -29,13 +31,17 @@ export function MobileDock({
29
31
  const folders = orderedFolders(mail.folders ?? []);
30
32
  const scroller = useRef<HTMLDivElement>(null);
31
33
  const fade = useEdgeFade(scroller);
34
+ const intent = usePrefetchOnIntent();
32
35
  useActiveInView(scroller, `${mail.folder} ${folders.length}`);
33
36
 
34
37
  const tabClass =
35
38
  "relative flex h-12 shrink-0 snap-start flex-col items-center justify-center gap-0.5 rounded-xl px-2 text-[10.5px] font-medium outline-none focus-visible:ring-2 focus-visible:ring-ring";
36
39
 
37
40
  return (
38
- <div className="pointer-events-none fixed inset-x-0 bottom-[calc(0.625rem+env(safe-area-inset-bottom))] z-30 flex justify-center gap-2 px-3 sm:bottom-20 lg:hidden">
41
+ <div
42
+ data-mail-dock
43
+ className="pointer-events-none fixed inset-x-0 bottom-[calc(0.625rem+env(safe-area-inset-bottom))] z-30 flex justify-center gap-2 px-3 sm:bottom-20 lg:hidden"
44
+ >
39
45
  <nav
40
46
  aria-label="Mailbox and folders"
41
47
  className="mail-pane pointer-events-auto flex w-full max-w-sm min-w-0 items-center overflow-hidden rounded-2xl shadow-[0_8px_24px_-10px_var(--shadow-color-strong),0_1px_2px_var(--shadow-color-weak)]"
@@ -62,8 +68,9 @@ export function MobileDock({
62
68
  type="button"
63
69
  data-active={active || undefined}
64
70
  aria-current={active ? "page" : undefined}
65
- aria-label={`${item.name}${unread ? `, ${unread} unread` : ""}`}
71
+ aria-label={`${item.name}${unread ? `, ${folderCountLabel(item, unread)}` : ""}`}
66
72
  title={item.kind === "custom" ? item.name : undefined}
73
+ {...mail.listIntent(mail.mailbox?.id, item.id)}
67
74
  onClick={() => mail.selectFolder(item.id)}
68
75
  className={cn(
69
76
  tabClass,
@@ -107,6 +114,14 @@ export function MobileDock({
107
114
  type="button"
108
115
  aria-haspopup="dialog"
109
116
  aria-label="Manage folders and AI sorting"
117
+ {...intent((queryClient) =>
118
+ mail.mailbox
119
+ ? prefetchMailboxOrganization(
120
+ queryClient,
121
+ mail.mailbox.id
122
+ )
123
+ : undefined
124
+ )}
110
125
  onClick={onManageFolders}
111
126
  className={cn(
112
127
  tabClass,
@@ -126,6 +141,7 @@ export function MobileDock({
126
141
  <button
127
142
  type="button"
128
143
  aria-label="New message"
144
+ data-compose-opener
129
145
  disabled={!mail.mailbox?.canSend}
130
146
  onClick={mail.openCompose}
131
147
  className="bg-primary text-primary-foreground focus-visible:ring-ring pointer-events-auto grid size-14 shrink-0 place-items-center rounded-2xl shadow-[inset_0_1px_0_oklch(1_0_0/0.2),0_8px_20px_-8px_var(--primary)] transition-[filter,transform] outline-none hover:brightness-110 focus-visible:ring-2 focus-visible:ring-offset-2 active:scale-95 disabled:opacity-50"
@@ -0,0 +1,48 @@
1
+ import { restoreFocus } from "@open-workspace/core/ui";
2
+
3
+ /** The list pane, which takes focus when no row can. */
4
+ export const CONVERSATION_LIST_ID = "mail-conversation-list";
5
+
6
+ /** The list row button of a conversation, if it is listed. */
7
+ function rowButton(conversationId: string) {
8
+ return document.querySelector<HTMLElement>(
9
+ `li[data-conversation-id="${CSS.escape(conversationId)}"] > button`
10
+ );
11
+ }
12
+
13
+ /**
14
+ * Focus after an action that takes the focused control away: the first of
15
+ * `conversationIds`'s rows that is listed then, else the list itself.
16
+ */
17
+ export function focusListAfter(conversationIds: readonly string[]) {
18
+ restoreFocus(() => [
19
+ ...conversationIds.map(rowButton),
20
+ document.querySelector<HTMLElement>(`#${CONVERSATION_LIST_ID}`),
21
+ ]);
22
+ }
23
+
24
+ /**
25
+ * The rows to focus once `ids` leave the list (`listed`, in its order): the
26
+ * one after the first of them still listed, else the one before.
27
+ */
28
+ export function rowsAround(
29
+ listed: readonly { conversationId: string }[],
30
+ ids: ReadonlySet<string>,
31
+ /** Whether they stay listed (marked read or unread), to focus the first. */
32
+ staying = false
33
+ ) {
34
+ const index = listed.findIndex((item) => ids.has(item.conversationId));
35
+
36
+ if (index === -1) return [];
37
+ const first = listed[index]?.conversationId;
38
+
39
+ if (staying && first) return [first];
40
+
41
+ const remaining = (item: { conversationId: string }) =>
42
+ !ids.has(item.conversationId);
43
+
44
+ return [
45
+ listed.slice(index + 1).find(remaining),
46
+ listed.slice(0, index).findLast(remaining),
47
+ ].flatMap((item) => (item ? [item.conversationId] : []));
48
+ }
@@ -4,6 +4,7 @@ import type { Folder, MailFolder } from "./types";
4
4
  const systemFolderLabels = new Map([
5
5
  ["inbox", "Inbox"],
6
6
  ["sent", "Sent"],
7
+ ["drafts", "Drafts"],
7
8
  ["archive", "Archive"],
8
9
  ["spam", "Spam"],
9
10
  ["trash", "Trash"],
@@ -21,11 +22,22 @@ export function folderShowsUnreadCount(folder: MailFolder | undefined) {
21
22
  return folder?.kind === "custom" || folder?.systemType === "inbox";
22
23
  }
23
24
 
24
- /** The unread count a folder shows: Inbox and custom folders only. */
25
+ /** The count a folder shows: unread in Inbox and custom folders, every draft in Drafts. */
25
26
  export function unreadOf(folder: MailFolder) {
27
+ if (folder.systemType === "drafts") return folder.totalCount;
28
+
26
29
  return folderShowsUnreadCount(folder) ? folder.unreadCount : 0;
27
30
  }
28
31
 
32
+ /** What a folder's count (`unreadOf`) says, read aloud: Drafts counts drafts. */
33
+ export function folderCountLabel(folder: MailFolder, count: number) {
34
+ if (folder.systemType === "drafts") {
35
+ return `${count} ${count === 1 ? "draft" : "drafts"}`;
36
+ }
37
+
38
+ return `${count} unread`;
39
+ }
40
+
29
41
  /**
30
42
  * Every folder in the mailbox's one order, as the sidebar, rail, dock and
31
43
  * folder pickers list them: Inbox first, then system and custom folders
@@ -39,6 +51,6 @@ export function orderedFolders(folders: readonly MailFolder[]) {
39
51
  export function folderAfterMailboxSwitch(
40
52
  folder: Folder,
41
53
  targetFolders: MailFolder[] | undefined
42
- ): Folder {
54
+ ) {
43
55
  return targetFolders?.some((item) => item.id === folder) ? folder : "inbox";
44
56
  }
@@ -139,12 +139,18 @@
139
139
  border-top-color: var(--primary);
140
140
  }
141
141
 
142
+ :is([data-composer-editor-content], .composer-message-body) :is(th, td) {
143
+ border: 1px solid var(--border);
144
+ padding: 0.25rem 0.5rem;
145
+ }
146
+
142
147
  /*
143
148
  Outgoing composer HTML lives in the app document after a strict allowlist
144
149
  sanitizer. These rules restore editor semantics without accepting inline CSS.
145
150
  */
146
151
  .composer-message-body {
147
152
  overflow-wrap: anywhere;
153
+ overflow-x: auto;
148
154
 
149
155
  p {
150
156
  margin: 0;
@@ -234,3 +240,17 @@
234
240
  .mail-body {
235
241
  overflow-wrap: anywhere;
236
242
  }
243
+
244
+ /* Toasts (Undo among them) sit above the dock, not over its folders; the
245
+ dock shows below 64rem. */
246
+ @media (width < 64rem) {
247
+ body:has([data-mail-dock]) [data-sonner-toaster][data-y-position="bottom"] {
248
+ bottom: calc(4.75rem + env(safe-area-inset-bottom)) !important;
249
+ }
250
+ }
251
+
252
+ @media (40rem <= width < 64rem) {
253
+ body:has([data-mail-dock]) [data-sonner-toaster][data-y-position="bottom"] {
254
+ bottom: 9.25rem !important;
255
+ }
256
+ }
@@ -8,19 +8,18 @@ import {
8
8
  } from "@open-workspace/core/ui";
9
9
  import { useQueryClient } from "@tanstack/react-query";
10
10
  import { Check, ChevronsUpDown, X } from "lucide-react";
11
+ import { useQueryState } from "nuqs";
11
12
  import { useEffect } from "react";
12
- import { useLocation, useNavigate } from "react-router";
13
- import { z } from "zod";
14
13
 
15
- import { folderAfterMailboxSwitch } from "./mail-folders";
16
14
  import { MailboxGlyph } from "./mail-nav";
17
15
  import { CountPill } from "./mail-primitives";
18
- import { conversationsQuery, foldersQuery } from "./mail-queries";
16
+ import { prefetchMailboxSwitch } from "./mail-queries";
17
+ import { mailSearchParams } from "./mail-search-params";
19
18
  import type { Mailbox } from "./types";
20
19
  import type { MailController } from "./use-mail-controller";
21
20
 
22
21
  /** What names a mailbox in tight spots: the address for a person's own, the name for a shared one. */
23
- export function mailboxCaption(mailbox: Mailbox) {
22
+ function mailboxCaption(mailbox: Mailbox) {
24
23
  return mailbox.kind === "shared" ? mailbox.displayName : mailbox.address;
25
24
  }
26
25
 
@@ -41,7 +40,8 @@ export function MailboxCaption({ mail }: { mail: MailController }) {
41
40
  * nothing to switch to, so there is no button.
42
41
  */
43
42
  export function DockMailboxSwitcher({ mail }: { mail: MailController }) {
44
- const sheet = useMailboxSheet();
43
+ const [sheet, setSheet] = useQueryState("sheet", mailSearchParams.sheet);
44
+ const open = sheet === "mailboxes";
45
45
  const { mailbox, mailboxes } = mail;
46
46
 
47
47
  if (!mailbox || mailboxes.length < 2) return null;
@@ -55,13 +55,13 @@ export function DockMailboxSwitcher({ mail }: { mail: MailController }) {
55
55
  <button
56
56
  type="button"
57
57
  aria-haspopup="dialog"
58
- aria-expanded={sheet.open}
58
+ aria-expanded={open}
59
59
  aria-label={`Mailbox: ${mailbox.displayName}${unreadElsewhere ? ", unread mail in other mailboxes" : ""}`}
60
60
  title={mailboxCaption(mailbox)}
61
- onClick={sheet.show}
61
+ onClick={() => void setSheet("mailboxes")}
62
62
  className={cn(
63
63
  "text-muted-foreground hover:text-foreground focus-visible:ring-ring flex h-12 shrink-0 items-center gap-0.5 rounded-xl pr-1 pl-2 outline-none focus-visible:ring-2",
64
- sheet.open && "bg-sidebar-accent text-foreground"
64
+ open && "bg-sidebar-accent text-foreground"
65
65
  )}
66
66
  >
67
67
  <span className="relative shrink-0">
@@ -83,7 +83,11 @@ export function DockMailboxSwitcher({ mail }: { mail: MailController }) {
83
83
  strokeWidth={2}
84
84
  />
85
85
  </button>
86
- <MailboxSheet mail={mail} open={sheet.open} onClose={sheet.close} />
86
+ <MailboxSheet
87
+ mail={mail}
88
+ open={open}
89
+ onClose={() => void setSheet(null)}
90
+ />
87
91
  </>
88
92
  );
89
93
  }
@@ -102,7 +106,7 @@ function MailboxSheet({
102
106
  onClose: () => void;
103
107
  }) {
104
108
  const queryClient = useQueryClient();
105
- const { folder, debouncedSearch, unreadOnly } = mail;
109
+ const { folder } = mail;
106
110
 
107
111
  // While the sheet is open, the other mailboxes' folders and the list a
108
112
  // switch would land on load, so picking one swaps the screen in a frame.
@@ -115,38 +119,21 @@ function MailboxSheet({
115
119
  if (!open) return;
116
120
 
117
121
  for (const id of otherIds.split(" ").filter(Boolean)) {
118
- void queryClient
119
- .fetchQuery({ ...foldersQuery(id), staleTime: 30_000 })
120
- .then(
121
- (data) => {
122
- const target = folderAfterMailboxSwitch(folder, data.folders);
123
- void queryClient.prefetchInfiniteQuery({
124
- ...conversationsQuery(id, target, debouncedSearch, unreadOnly),
125
- staleTime: 30_000,
126
- });
127
- },
128
- () => undefined
129
- );
122
+ void prefetchMailboxSwitch(queryClient, id, folder).catch(
123
+ () => undefined
124
+ );
130
125
  }
131
- }, [open, otherIds, folder, debouncedSearch, unreadOnly, queryClient]);
126
+ }, [open, otherIds, folder, queryClient]);
132
127
 
133
- async function pick(mailbox: Mailbox) {
128
+ function pick(mailbox: Mailbox) {
134
129
  if (mailbox.id === mail.mailbox?.id) {
135
130
  onClose();
136
131
 
137
132
  return;
138
133
  }
139
134
 
140
- const data = await queryClient
141
- .ensureQueryData(foldersQuery(mailbox.id))
142
- .catch(() => undefined);
143
-
144
135
  // Replaces the sheet's history entry, so Back returns to the mailbox before.
145
- mail.openFolder(
146
- mailbox.id,
147
- folderAfterMailboxSwitch(folder, data?.folders),
148
- true
149
- );
136
+ void mail.switchMailbox(mailbox.id, true);
150
137
  }
151
138
 
152
139
  return (
@@ -188,7 +175,7 @@ function MailboxSheet({
188
175
  <button
189
176
  type="button"
190
177
  aria-current={current ? "true" : undefined}
191
- onClick={() => void pick(item)}
178
+ onClick={() => pick(item)}
192
179
  className={cn(
193
180
  // No color transition: the highlight moves at once, as in the folder lists.
194
181
  "flex h-15 w-full items-center gap-3 rounded-xl px-3 text-left outline-none",
@@ -239,37 +226,3 @@ function MailboxSheet({
239
226
  </Sheet>
240
227
  );
241
228
  }
242
-
243
- /** The history entry the mailbox sheet opened (see `show`). */
244
- const sheetState = z.object({ mailboxSheet: z.literal(true) });
245
-
246
- /** React Router's history state: the entry's position in this tab's history. */
247
- const historyState = z.object({ idx: z.number() });
248
-
249
- /**
250
- * The mailbox sheet is a history entry (location state), so the system Back
251
- * button closes it instead of leaving the folder.
252
- */
253
- function useMailboxSheet() {
254
- const location = useLocation();
255
- const navigate = useNavigate();
256
-
257
- const open = sheetState.safeParse(location.state).success;
258
-
259
- const here = { pathname: location.pathname, search: location.search };
260
-
261
- return {
262
- open,
263
- show() {
264
- if (!open) navigate(here, { state: { mailboxSheet: true } });
265
- },
266
- close() {
267
- // After a reload the sheet's entry may be the first one; then it is replaced.
268
- const history = historyState.safeParse(window.history.state);
269
- const index = history.success ? history.data.idx : 0;
270
-
271
- if (index > 0) navigate(-1);
272
- else navigate(here, { replace: true, state: null });
273
- },
274
- };
275
- }