@open-workspace/email 0.4.2 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. package/README.md +9 -4
  2. package/alchemy/index.ts +130 -2
  3. package/drizzle/mailbox/0003_after_0_4_2.sql +180 -0
  4. package/drizzle/mailbox/meta/0003_snapshot.json +1507 -0
  5. package/drizzle/mailbox/meta/_journal.json +7 -0
  6. package/drizzle/mailbox/migrations.js +3 -1
  7. package/migrations/0002_after_0_4_2.sql +35 -0
  8. package/migrations/meta/0002_snapshot.json +807 -0
  9. package/migrations/meta/_journal.json +7 -0
  10. package/package.json +23 -7
  11. package/shared/attachment-preview.ts +18 -8
  12. package/shared/folder-order.ts +31 -6
  13. package/shared/mail-headers.ts +3 -3
  14. package/shared/mail-html.ts +25 -0
  15. package/shared/mail-import.ts +0 -7
  16. package/shared/mail-received.ts +4 -4
  17. package/shared/mail-rule-actions.ts +47 -0
  18. package/shared/mail-sender-intel.ts +5 -1
  19. package/shared/mail.ts +70 -4
  20. package/shared/office-preview.ts +0 -4
  21. package/shared/pdfjs-assets.ts +1 -3
  22. package/shared/rich-content.ts +35 -0
  23. package/shared/signature.ts +15 -0
  24. package/src/admin/address-auto-reply.tsx +52 -0
  25. package/src/admin/blocked-senders.tsx +86 -66
  26. package/src/admin/forward-destinations.tsx +140 -0
  27. package/src/admin/mail-archive.tsx +134 -0
  28. package/src/admin/team-signature.tsx +90 -0
  29. package/src/client.tsx +130 -16
  30. package/src/mail/attachment-preview-dialog.tsx +13 -5
  31. package/src/mail/auto-reply-banner.tsx +61 -0
  32. package/src/mail/blocked-senders.tsx +124 -91
  33. package/src/mail/compose-window-chrome.tsx +20 -8
  34. package/src/mail/compose-window.tsx +391 -365
  35. package/src/mail/composer-asset-bookmarks.ts +47 -12
  36. package/src/mail/composer-attachment-list.tsx +42 -17
  37. package/src/mail/composer-editor-document.ts +54 -10
  38. package/src/mail/composer-editor.tsx +44 -44
  39. package/src/mail/composer-link-text.ts +42 -0
  40. package/src/mail/composer-recipient-fields.tsx +25 -16
  41. package/src/mail/composer-recipients.ts +62 -16
  42. package/src/mail/composer-session.ts +107 -23
  43. package/src/mail/composer-toolbar.tsx +15 -1
  44. package/src/mail/composer-upload-client.ts +29 -1
  45. package/src/mail/composer-upload-progress.ts +2 -2
  46. package/src/mail/conversation-actions-model.ts +56 -0
  47. package/src/mail/conversation-list.tsx +263 -128
  48. package/src/mail/conversation-loading-skeleton.tsx +165 -90
  49. package/src/mail/conversation-message.tsx +257 -102
  50. package/src/mail/conversation-order.ts +12 -0
  51. package/src/mail/conversation-reply.tsx +313 -189
  52. package/src/mail/conversation-selection-toolbar.tsx +188 -143
  53. package/src/mail/conversation-view.tsx +315 -85
  54. package/src/mail/delivery-indicator.tsx +33 -12
  55. package/src/mail/draft-attachments.ts +194 -0
  56. package/src/mail/email-html-body.tsx +97 -53
  57. package/src/mail/folder-cleanup-bar.tsx +193 -0
  58. package/src/mail/folder-glyph.tsx +5 -0
  59. package/src/mail/folder-manager.tsx +71 -38
  60. package/src/mail/mail-app-bar.tsx +15 -3
  61. package/src/mail/mail-dock.tsx +19 -3
  62. package/src/mail/mail-focus.ts +48 -0
  63. package/src/mail/mail-folders.ts +14 -2
  64. package/src/mail/mail-layout.css +20 -0
  65. package/src/mail/mail-mailbox-sheet.tsx +22 -69
  66. package/src/mail/mail-nav-rail.tsx +7 -4
  67. package/src/mail/mail-nav.tsx +66 -46
  68. package/src/mail/mail-prefetch.ts +30 -9
  69. package/src/mail/mail-primitives.tsx +6 -4
  70. package/src/mail/mail-queries.ts +122 -20
  71. package/src/mail/mail-query-cache.ts +1085 -173
  72. package/src/mail/mail-search-params.ts +35 -0
  73. package/src/mail/mail-shell.tsx +32 -9
  74. package/src/mail/mailbox-ai-settings.tsx +56 -42
  75. package/src/mail/mailbox-realtime.tsx +4 -12
  76. package/src/mail/mailbox-rules.tsx +898 -0
  77. package/src/mail/message-actions.tsx +38 -26
  78. package/src/mail/message-attachments.tsx +20 -12
  79. package/src/mail/message-body.ts +53 -0
  80. package/src/mail/message-format.ts +8 -2
  81. package/src/mail/message-header.tsx +3 -1
  82. package/src/mail/message-translation.tsx +34 -67
  83. package/src/mail/original-message-sheet.tsx +63 -50
  84. package/src/mail/original-message.ts +6 -6
  85. package/src/mail/pane-splitter.tsx +3 -3
  86. package/src/mail/pdf-preview.tsx +70 -62
  87. package/src/mail/plain-message-text.tsx +28 -0
  88. package/src/mail/print-message.ts +31 -36
  89. package/src/mail/reader-pane.tsx +134 -103
  90. package/src/mail/recipient-combobox.tsx +52 -29
  91. package/src/mail/recipient-field-row.tsx +3 -0
  92. package/src/mail/rich-content.ts +128 -0
  93. package/src/mail/sanitize-email-html.ts +53 -32
  94. package/src/mail/sender-actions.tsx +48 -46
  95. package/src/mail/sender-authentication.tsx +1 -1
  96. package/src/mail/sender-dialogs.tsx +67 -43
  97. package/src/mail/sender-security.tsx +12 -11
  98. package/src/mail/signature.ts +43 -0
  99. package/src/mail/translation-html.ts +3 -3
  100. package/src/mail/types.ts +12 -0
  101. package/src/mail/use-composer-attachment-preflight.ts +23 -60
  102. package/src/mail/use-composer-core.ts +286 -0
  103. package/src/mail/use-composer-navigation.ts +120 -0
  104. package/src/mail/use-composer-submission.ts +154 -19
  105. package/src/mail/use-conversation-actions.ts +292 -0
  106. package/src/mail/use-conversation-position.ts +51 -0
  107. package/src/mail/use-conversation-selection.ts +192 -89
  108. package/src/mail/use-draft-autosave.ts +394 -0
  109. package/src/mail/use-drafts.ts +194 -0
  110. package/src/mail/use-mail-controller.ts +758 -213
  111. package/src/mail/use-mail-data.ts +210 -100
  112. package/src/mail/use-mail-safety.ts +19 -38
  113. package/src/mail/use-mail-send.ts +18 -6
  114. package/src/mail/use-pdf-translation.ts +1 -1
  115. package/src/mail/use-reply-cc.ts +61 -0
  116. package/src/mail/use-visible-message-read.ts +128 -64
  117. package/src/pwa/push-key.ts +18 -0
  118. package/src/pwa/push-subscription.ts +88 -26
  119. package/src/settings/auto-reply-editor.tsx +454 -0
  120. package/src/settings/auto-reply-page.tsx +59 -0
  121. package/src/settings/mail-apps-page.tsx +52 -43
  122. package/src/settings/notifications-page.tsx +82 -67
  123. package/src/settings/rich-content-editor.tsx +182 -0
  124. package/src/settings/settings-queries.ts +57 -0
  125. package/src/settings/signature-editor.tsx +142 -0
  126. package/src/settings/signature-page.tsx +70 -0
  127. package/worker/admin/blocked-sender-routes.ts +10 -16
  128. package/worker/backups/eml.ts +185 -0
  129. package/worker/backups/file-parts.ts +140 -0
  130. package/worker/backups/mail-backup.ts +644 -0
  131. package/worker/backups/settings-backup.ts +866 -0
  132. package/worker/backups/stream-eml.ts +73 -0
  133. package/worker/db/schema.ts +89 -5
  134. package/worker/jmap/attachment-blobs.ts +113 -0
  135. package/worker/jmap/blobs.ts +162 -0
  136. package/worker/jmap/draft-content.ts +42 -0
  137. package/worker/jmap/drafts.ts +70 -0
  138. package/worker/jmap/email-body.ts +152 -0
  139. package/worker/jmap/email-methods.ts +1223 -0
  140. package/worker/jmap/eventsource.ts +9 -8
  141. package/worker/jmap/import-methods.ts +205 -0
  142. package/worker/jmap/mailbox-methods.ts +187 -0
  143. package/worker/jmap/method-core.ts +379 -0
  144. package/worker/jmap/methods.ts +119 -1816
  145. package/worker/jmap/push-subscription-methods.ts +373 -0
  146. package/worker/jmap/push-types.ts +46 -2
  147. package/worker/jmap/push.ts +24 -31
  148. package/worker/jmap/routes.ts +144 -153
  149. package/worker/jmap/submission-methods.ts +395 -0
  150. package/worker/mail/access.ts +35 -12
  151. package/worker/mail/ai-classification.ts +2 -2
  152. package/worker/mail/archive-object.ts +96 -0
  153. package/worker/mail/archive-routes.ts +35 -0
  154. package/worker/mail/archive.ts +700 -0
  155. package/worker/mail/auth-headers.ts +57 -43
  156. package/worker/mail/auto-reply-routes.ts +260 -0
  157. package/worker/mail/auto-reply.ts +243 -0
  158. package/worker/mail/bimi.ts +53 -36
  159. package/worker/mail/bootstrap.ts +11 -3
  160. package/worker/mail/capabilities.ts +69 -0
  161. package/worker/mail/classification-signals.ts +1 -1
  162. package/worker/mail/confusables-data.ts +9 -0
  163. package/worker/mail/conversation-cursor.ts +6 -15
  164. package/worker/mail/delivery-events.ts +9 -7
  165. package/worker/mail/delivery-facts.ts +1 -1
  166. package/worker/mail/demo-routes.ts +3 -3
  167. package/worker/mail/doh.ts +3 -3
  168. package/worker/mail/download-links.ts +153 -0
  169. package/worker/mail/downloads.ts +2 -6
  170. package/worker/mail/draft-routes.ts +473 -0
  171. package/worker/mail/draft-sender.ts +54 -0
  172. package/worker/mail/edge-cache.ts +41 -55
  173. package/worker/mail/email-routing.ts +123 -0
  174. package/worker/mail/forward-destinations.ts +114 -0
  175. package/worker/mail/forward-downloads.ts +115 -0
  176. package/worker/mail/forward-html.ts +85 -0
  177. package/worker/mail/header-metadata.ts +2 -5
  178. package/worker/mail/impersonation.ts +102 -101
  179. package/worker/mail/import-routes.ts +29 -82
  180. package/worker/mail/import.ts +130 -0
  181. package/worker/mail/inbound-delivery.ts +6 -5
  182. package/worker/mail/inbound-threading.ts +15 -2
  183. package/worker/mail/inbound.ts +58 -28
  184. package/worker/mail/ip-intel.ts +8 -17
  185. package/worker/mail/isolate-cache.ts +1 -1
  186. package/worker/mail/mailbox-deletion.ts +33 -12
  187. package/worker/mail/mailbox-directory.ts +39 -65
  188. package/worker/mail/mailing-list.ts +29 -58
  189. package/worker/mail/message-security.ts +19 -8
  190. package/worker/mail/message-view.ts +12 -10
  191. package/worker/mail/office-conversion.ts +3 -5
  192. package/worker/mail/office-preview-container.ts +3 -8
  193. package/worker/mail/outbound-content.ts +139 -65
  194. package/worker/mail/outbound-delivery.ts +20 -17
  195. package/worker/mail/outbound-service.ts +34 -9
  196. package/worker/mail/outbound.ts +146 -75
  197. package/worker/mail/outgoing-context.ts +60 -30
  198. package/worker/mail/participants.ts +10 -15
  199. package/worker/mail/plain-body.ts +39 -0
  200. package/worker/mail/push-endpoint.ts +17 -0
  201. package/worker/mail/push-notifications.ts +53 -62
  202. package/worker/mail/quote-parser.ts +36 -24
  203. package/worker/mail/receive.ts +146 -39
  204. package/worker/mail/recipients.ts +1 -1
  205. package/worker/mail/remote-proxy.ts +3 -3
  206. package/worker/mail/repeat.ts +1 -1
  207. package/worker/mail/reply-plan.ts +124 -26
  208. package/worker/mail/rfc.ts +15 -7
  209. package/worker/mail/rich-content.ts +207 -0
  210. package/worker/mail/routes.ts +698 -304
  211. package/worker/mail/routing.ts +274 -0
  212. package/worker/mail/rules.ts +230 -0
  213. package/worker/mail/safety-routes.ts +88 -86
  214. package/worker/mail/schemas.ts +222 -31
  215. package/worker/mail/search.ts +25 -2
  216. package/worker/mail/security-settings.ts +4 -10
  217. package/worker/mail/send-message.ts +238 -0
  218. package/worker/mail/sender-intel.ts +12 -20
  219. package/worker/mail/signature-routes.ts +206 -0
  220. package/worker/mail/signatures.ts +195 -0
  221. package/worker/mail/spamhaus.ts +28 -16
  222. package/worker/mail/storage-keys.ts +35 -0
  223. package/worker/mail/unsubscribe.ts +19 -41
  224. package/worker/mail/uploads.ts +192 -80
  225. package/worker/mail/webhook-source.ts +3 -2
  226. package/worker/mail/workspace-safety.ts +194 -60
  227. package/worker/mailbox/demo.ts +13 -15
  228. package/worker/mailbox/email-index.ts +65 -35
  229. package/worker/mailbox/folder-model.ts +0 -20
  230. package/worker/mailbox/import-placement.ts +21 -36
  231. package/worker/mailbox/inbound-decision.ts +114 -0
  232. package/worker/mailbox/inbox-counts.ts +45 -25
  233. package/worker/mailbox/index.ts +756 -3201
  234. package/worker/mailbox/jmap-change-log.ts +195 -0
  235. package/worker/mailbox/jmap-email-rows.ts +186 -0
  236. package/worker/mailbox/jmap-mailboxes.ts +116 -0
  237. package/worker/mailbox/jmap-placement.ts +139 -0
  238. package/worker/mailbox/jmap-query-filter.ts +231 -0
  239. package/worker/mailbox/jmap-store.ts +167 -299
  240. package/worker/mailbox/mailbox-auto-reply.ts +316 -0
  241. package/worker/mailbox/mailbox-backup.ts +538 -0
  242. package/worker/mailbox/mailbox-drafts.ts +417 -0
  243. package/worker/mailbox/mailbox-folders.ts +242 -0
  244. package/worker/mailbox/mailbox-import.ts +455 -0
  245. package/worker/mailbox/mailbox-inbound.ts +934 -0
  246. package/worker/mailbox/mailbox-jmap.ts +294 -0
  247. package/worker/mailbox/mailbox-outbound.ts +413 -0
  248. package/worker/mailbox/mailbox-rules.ts +336 -0
  249. package/worker/mailbox/mailbox-senders.ts +294 -0
  250. package/worker/mailbox/mailbox-storage.ts +438 -0
  251. package/worker/mailbox/mailbox-views.ts +891 -0
  252. package/worker/mailbox/model.ts +1 -0
  253. package/worker/mailbox/office-preview-jobs.ts +59 -47
  254. package/worker/mailbox/placement.ts +933 -0
  255. package/worker/mailbox/restore-thread.ts +52 -0
  256. package/worker/mailbox/retention.ts +36 -0
  257. package/worker/mailbox/schema.ts +200 -1
  258. package/worker/mailbox/senders.ts +216 -178
  259. package/worker/mailbox/spam-undo-filing.ts +138 -0
  260. package/worker/mailbox/spam-undo.ts +253 -0
  261. package/worker/mailbox/support.ts +416 -0
  262. package/worker/mcp/mail-action-tools.ts +161 -1
  263. package/worker/mcp/mail-compose-tools.ts +7 -1
  264. package/worker/mcp/mail-safety-tools.ts +4 -4
  265. package/worker/module.ts +23 -4
  266. package/src/mail/use-compose-submission.ts +0 -208
  267. package/src/mail/use-reply-submission.ts +0 -114
  268. package/worker/mail/capped-body.ts +0 -36
@@ -1,7 +1,11 @@
1
1
  import {
2
2
  Button,
3
3
  Checkbox,
4
+ PlaceholderFrame,
5
+ restoreFocus,
4
6
  Skeleton,
7
+ StaleContent,
8
+ useDelayedPending,
5
9
  ToggleGroup,
6
10
  ToggleGroupItem,
7
11
  TooltipProvider,
@@ -16,10 +20,12 @@ import {
16
20
  RotateCw,
17
21
  SearchX,
18
22
  } from "lucide-react";
19
- import { useEffect, useRef } from "react";
23
+ import { useEffect, useLayoutEffect, useRef } from "react";
20
24
  import type { ReactNode } from "react";
21
25
 
26
+ import { DRAFTS_FOLDER_ID } from "../../shared/folder-order";
22
27
  import { ConversationSelectionToolbar } from "./conversation-selection-toolbar";
28
+ import { FolderCleanupBar } from "./folder-cleanup-bar";
23
29
  import { SearchField } from "./mail-app-bar";
24
30
  import { folderShowsUnreadCount } from "./mail-folders";
25
31
  import { MailboxCaption } from "./mail-mailbox-sheet";
@@ -118,6 +124,7 @@ function ConversationRow({
118
124
 
119
125
  return (
120
126
  <li
127
+ data-conversation-id={conversation.conversationId}
121
128
  className={cn(
122
129
  "mail-row group relative border-b border-(--rule) transition-colors duration-100",
123
130
  "before:bg-primary before:absolute before:inset-y-0 before:left-0 before:w-[3px] before:opacity-0",
@@ -158,7 +165,8 @@ function ConversationRow({
158
165
  "size-4 rounded-[4px] transition-opacity",
159
166
  selecting || selected
160
167
  ? "opacity-100"
161
- : "opacity-0 group-hover:opacity-100 focus-visible:opacity-100"
168
+ : // Unseen on a touch screen, it takes no taps from the row.
169
+ "opacity-0 group-hover:opacity-100 focus-visible:opacity-100 pointer-coarse:pointer-events-none"
162
170
  )}
163
171
  />
164
172
  {unread && !selecting && !selected && (
@@ -198,6 +206,11 @@ function ConversationRow({
198
206
  {conversation.messageCount}
199
207
  </span>
200
208
  )}
209
+ {conversation.draft && (
210
+ <span className="text-destructive shrink-0 text-[12px] font-medium">
211
+ Draft
212
+ </span>
213
+ )}
201
214
  </span>
202
215
 
203
216
  <span className="mail-subject pointer-events-none min-w-0 truncate text-[13px] leading-5 [grid-area:subject]">
@@ -212,7 +225,9 @@ function ConversationRow({
212
225
  <span aria-hidden="true" className="mail-dash text-border px-1.5">
213
226
  —
214
227
  </span>
215
- {conversation.preview || "No text preview"}
228
+ {conversation.searchMatch?.snippet ||
229
+ conversation.preview ||
230
+ "No text preview"}
216
231
  </span>
217
232
  </span>
218
233
 
@@ -248,6 +263,10 @@ function emptyFolderHint(systemType: string | null | undefined) {
248
263
  return "Deleted conversations wait here until you delete them permanently.";
249
264
  }
250
265
 
266
+ case "drafts": {
267
+ return "Messages you start writing are saved here until you send them.";
268
+ }
269
+
251
270
  default: {
252
271
  return "New conversations will appear here as soon as they arrive.";
253
272
  }
@@ -277,6 +296,25 @@ export function ConversationList({ mail }: { mail: MailController }) {
277
296
 
278
297
  const hasConversations = conversations.length > 0;
279
298
 
299
+ // What the folder's count says the list holds; a search can't tell.
300
+ const countedRows = debouncedSearch
301
+ ? 0
302
+ : unreadOnly
303
+ ? unreadInFolder
304
+ : (activeFolder?.totalCount ?? 0);
305
+
306
+ // An empty list being read again while the count says it isn't empty
307
+ // (data from before a change) waits for its rows: "is empty" would be
308
+ // wrong for a moment.
309
+ const awaitingRows =
310
+ !hasConversations && conversationsQuery.isFetching && countedRows > 0;
311
+
312
+ const listWaiting = mail.listLoading || awaitingRows;
313
+ // A list seen before stays while the next loads (see useConversations): the
314
+ // skeleton is only for the first, and only if it is slow.
315
+ const listPlaceholder = useDelayedPending(listWaiting);
316
+ const inDrafts = folder === DRAFTS_FOLDER_ID;
317
+
280
318
  // Resting on a row (pointer or keyboard focus) starts loading it, so a
281
319
  // click usually finds the conversation already there.
282
320
  const intentTimer = useRef<ReturnType<typeof setTimeout> | undefined>(
@@ -285,6 +323,19 @@ export function ConversationList({ mail }: { mail: MailController }) {
285
323
 
286
324
  useEffect(() => () => clearTimeout(intentTimer.current), []);
287
325
 
326
+ const selectButton = useRef<HTMLButtonElement>(null);
327
+
328
+ // Which list the rows are: a search, a filter or a folder's results
329
+ // replace the list they were typed over as a list of their own, from the
330
+ // top, not by moving its rows about.
331
+ const listKey = `${folder}\0${debouncedSearch}\0${unreadOnly}`;
332
+
333
+ /** Leaves selection mode; focus, in its toolbar, goes back to Select. */
334
+ function exitSelection() {
335
+ restoreFocus(() => selectButton.current);
336
+ selection.exit();
337
+ }
338
+
288
339
  function intent(targetId: string, when: "soon" | "now" | null) {
289
340
  clearTimeout(intentTimer.current);
290
341
 
@@ -313,21 +364,23 @@ export function ConversationList({ mail }: { mail: MailController }) {
313
364
 
314
365
  let body: ReactNode;
315
366
 
316
- if (mail.listLoading) {
367
+ if (listWaiting || listPlaceholder) {
317
368
  body = (
318
- <ul aria-busy="true" aria-label="Loading conversations">
319
- {Array.from({ length: 12 }, (_, index) => (
320
- <li key={index} className="mail-row border-b border-(--rule)">
321
- <span className="[grid-area:check]" />
322
- <Skeleton className="h-3 w-28 [grid-area:from]" />
323
- <Skeleton
324
- className="h-3 [grid-area:subject]"
325
- style={{ width: `${55 + ((index * 37) % 40)}%` }}
326
- />
327
- <Skeleton className="h-3 w-9 justify-self-end [grid-area:date]" />
328
- </li>
329
- ))}
330
- </ul>
369
+ <PlaceholderFrame shown={listPlaceholder}>
370
+ <ul aria-busy="true" aria-label="Loading conversations">
371
+ {Array.from({ length: 12 }, (_, index) => (
372
+ <li key={index} className="mail-row border-b border-(--rule)">
373
+ <span className="[grid-area:check]" />
374
+ <Skeleton className="h-3 w-28 [grid-area:from]" />
375
+ <Skeleton
376
+ className="h-3 [grid-area:subject]"
377
+ style={{ width: `${55 + ((index * 37) % 40)}%` }}
378
+ />
379
+ <Skeleton className="h-3 w-9 justify-self-end [grid-area:date]" />
380
+ </li>
381
+ ))}
382
+ </ul>
383
+ </PlaceholderFrame>
331
384
  );
332
385
  } else if (mail.listError) {
333
386
  body = (
@@ -354,7 +407,7 @@ export function ConversationList({ mail }: { mail: MailController }) {
354
407
  selecting={selection.active}
355
408
  disabled={selection.pending}
356
409
  onOpen={() => mail.openConversation(item.conversationId)}
357
- onToggle={() => selection.toggle(item.conversationId)}
410
+ onToggle={() => selection.toggle(item)}
358
411
  onIntent={(when) => intent(item.conversationId, when)}
359
412
  />
360
413
  ))}
@@ -394,7 +447,7 @@ export function ConversationList({ mail }: { mail: MailController }) {
394
447
  className="flex min-h-0 flex-1 flex-col"
395
448
  onKeyDown={(event) => {
396
449
  if (selection.active && !selection.pending && event.key === "Escape") {
397
- selection.exit();
450
+ exitSelection();
398
451
  }
399
452
  }}
400
453
  >
@@ -407,144 +460,226 @@ export function ConversationList({ mail }: { mail: MailController }) {
407
460
  </h1>
408
461
  </div>
409
462
  <div className="flex h-12 items-center justify-between gap-3">
410
- {selection.active && mailbox ? (
463
+ {selection.active && mailbox && (
411
464
  <TooltipProvider delay={300}>
412
- <div className="-ml-1.5 min-w-0 flex-1 [&_[data-slot=button]]:shrink-0 lg:[&>div:first-child]:h-8 lg:[&>div:first-child]:border-0 lg:[&>div:first-child]:bg-transparent lg:[&>div:first-child]:px-0">
465
+ {/* Phones fix the toolbar to the bottom; the row keeps its count and filter. */}
466
+ <div className="-ml-1.5 min-w-0 flex-1 max-lg:contents [&_[data-slot=button]]:shrink-0 lg:[&>div:first-child]:h-8 lg:[&>div:first-child]:border-0 lg:[&>div:first-child]:bg-transparent lg:[&>div:first-child]:px-0">
413
467
  <ConversationSelectionToolbar
468
+ onDiscardDrafts={
469
+ folder === DRAFTS_FOLDER_ID
470
+ ? selection.discardDrafts
471
+ : undefined
472
+ }
414
473
  sharedMailboxName={
415
474
  mailbox.kind === "shared" ? mailbox.displayName : undefined
416
475
  }
417
476
  canDeletePermanently={mailbox.canSend}
418
477
  folder={folder}
419
478
  folders={folders ?? []}
420
- selectedCount={selection.selectedConversations.length}
479
+ selected={selection.selectedConversations}
421
480
  allLoadedSelected={selection.allLoadedSelected}
422
- someLoadedSelected={
423
- selection.selectedConversations.length > 0
424
- }
425
- anySelectedUnread={selection.anySelectedUnread}
426
- hasSelectedIncoming={selection.hasSelectedIncoming}
427
- allSelectedHaveIncoming={selection.allSelectedHaveIncoming}
428
- busy={selection.pending}
481
+ busy={selection.pending || mail.listStale}
429
482
  onToggleAll={selection.toggleAllLoaded}
430
483
  onAction={selection.run}
431
484
  onReport={selection.report}
432
- onExit={selection.exit}
485
+ onNotSpam={selection.notSpam}
486
+ onExit={exitSelection}
433
487
  />
434
488
  </div>
435
489
  </TooltipProvider>
436
- ) : (
437
- <>
438
- <div className="flex min-w-0 items-baseline gap-2">
439
- <h1 className="shrink-0 text-[15px] leading-6 font-semibold tracking-[-0.012em] max-lg:hidden">
440
- {folderName}
441
- </h1>
442
- <p className="text-muted-foreground min-w-0 truncate text-xs tabular-nums">
443
- {mail.listLoading ? (
444
- "Loading…"
445
- ) : (
446
- <>
447
- {/* A narrow header keeps the unread count and drops the total. */}
448
- <span
449
- className={
450
- unreadInFolder > 0
451
- ? "hidden @[24rem]/list-head:inline"
452
- : undefined
453
- }
454
- >
455
- {displayedConversationCount}
456
- {/* Phones have room for the word: the folder name sits above the row. */}
457
- <span className="hidden max-lg:inline @[26rem]/list-head:inline">
458
- {" "}
459
- {displayedConversationCount === "1"
460
- ? "conversation"
461
- : "conversations"}
462
- </span>
463
- {unreadInFolder > 0 && " · "}
490
+ )}
491
+ <div
492
+ className={cn(
493
+ "contents",
494
+ selection.active && mailbox && "lg:hidden"
495
+ )}
496
+ >
497
+ <div className="flex min-w-0 items-baseline gap-2">
498
+ <h1 className="shrink-0 text-[15px] leading-6 font-semibold tracking-[-0.012em] max-lg:hidden">
499
+ {folderName}
500
+ </h1>
501
+ <p className="text-muted-foreground min-w-0 truncate text-xs tabular-nums">
502
+ {listPlaceholder ? (
503
+ "Loading…"
504
+ ) : mail.listLoading ? null : (
505
+ <>
506
+ {/* A narrow header keeps the unread count and drops the total. */}
507
+ <span
508
+ className={
509
+ unreadInFolder > 0
510
+ ? "hidden @[24rem]/list-head:inline"
511
+ : undefined
512
+ }
513
+ >
514
+ {displayedConversationCount}
515
+ {/* Phones have room for the word: the folder name sits above the row. */}
516
+ <span className="hidden max-lg:inline @[26rem]/list-head:inline">
517
+ {" "}
518
+ {displayedConversationCount === "1"
519
+ ? "conversation"
520
+ : "conversations"}
464
521
  </span>
465
- {unreadInFolder > 0 && (
466
- <span className="text-primary font-medium">
467
- {unreadInFolder} unread
468
- </span>
469
- )}
470
- {debouncedSearch && <> · matching “{debouncedSearch}”</>}
471
- </>
472
- )}
473
- </p>
474
- </div>
475
- <div className="flex shrink-0 items-center gap-1.5">
522
+ {unreadInFolder > 0 && " · "}
523
+ </span>
524
+ {unreadInFolder > 0 && (
525
+ <span className="text-primary font-medium">
526
+ {unreadInFolder} unread
527
+ </span>
528
+ )}
529
+ {debouncedSearch && <> · matching “{debouncedSearch}”</>}
530
+ </>
531
+ )}
532
+ </p>
533
+ </div>
534
+ <div className="flex shrink-0 items-center gap-1.5">
535
+ {!inDrafts && (
476
536
  <SegmentedFilter
477
537
  unreadOnly={unreadOnly}
478
538
  onToggle={mail.toggleUnreadOnly}
479
539
  />
480
- <ToolbarTooltip label="Refresh">
481
- <Button
482
- variant="ghost"
483
- size="icon-sm"
484
- className="size-7"
485
- aria-label="Refresh"
486
- disabled={conversationsQuery.isFetching}
487
- onClick={() => void conversationsQuery.refetch()}
488
- >
489
- <RotateCw
490
- className={cn(
491
- conversationsQuery.isRefetching &&
492
- !conversationsQuery.isFetchingNextPage &&
493
- "animate-spin"
494
- )}
495
- />
496
- </Button>
497
- </ToolbarTooltip>
540
+ )}
541
+ <ToolbarTooltip label={mail.refreshError ?? "Refresh"}>
498
542
  <Button
499
543
  variant="ghost"
500
- size="sm"
501
- className="h-7 px-2 text-xs"
502
- disabled={selection.pending || !hasConversations}
503
- onClick={selection.start}
544
+ size={mail.refreshError ? "sm" : "icon-sm"}
545
+ className={
546
+ mail.refreshError ? "text-destructive h-7" : "size-7"
547
+ }
548
+ aria-label={mail.refreshError ? "Retry refresh" : "Refresh"}
549
+ disabled={conversationsQuery.isFetching}
550
+ onClick={mail.retryList}
504
551
  >
505
- <ListChecks /> Select
552
+ <RotateCw
553
+ className={cn(
554
+ conversationsQuery.isRefetching &&
555
+ !conversationsQuery.isFetchingNextPage &&
556
+ // Another list loading is not this one refreshing.
557
+ !conversationsQuery.isPlaceholderData &&
558
+ "animate-spin"
559
+ )}
560
+ />
561
+ {mail.refreshError && "Retry"}
506
562
  </Button>
507
- </div>
508
- </>
509
- )}
563
+ </ToolbarTooltip>
564
+ <Button
565
+ ref={selectButton}
566
+ variant="ghost"
567
+ size="sm"
568
+ className="aria-pressed:bg-accent h-7 px-2 text-xs"
569
+ aria-pressed={selection.active}
570
+ disabled={
571
+ selection.pending ||
572
+ mail.listStale ||
573
+ (!hasConversations && !selection.active)
574
+ }
575
+ onClick={selection.active ? exitSelection : selection.start}
576
+ >
577
+ <ListChecks /> Select
578
+ </Button>
579
+ </div>
580
+ </div>
510
581
  </div>
511
582
  <SearchField mail={mail} className="mb-2.5 h-9 md:hidden" />
512
583
  </div>
513
584
 
514
- <div className="@container/mail-list min-h-0 flex-1 overflow-y-auto pb-24">
515
- {hasConversations && !mail.listLoading && !mail.listError && (
516
- <div className="mail-columns border-border bg-surface-sunken text-muted-foreground sticky top-0 z-20 h-8 border-b text-[11px] font-semibold tracking-[0.04em] uppercase">
517
- <span className="grid place-items-center [grid-area:check]">
518
- <Checkbox
519
- aria-label={
520
- selection.allLoadedSelected
521
- ? "Deselect all loaded conversations"
522
- : "Select all loaded conversations"
523
- }
524
- checked={selection.allLoadedSelected}
525
- indeterminate={
526
- !selection.allLoadedSelected &&
527
- selection.selectedConversations.length > 0
528
- }
529
- disabled={selection.pending}
530
- onCheckedChange={selection.toggleAllLoaded}
531
- className="size-4 rounded-[4px]"
532
- />
533
- </span>
534
- <span data-col="from-wide" className="[grid-area:from]">
535
- From
536
- </span>
537
- <span data-col="from-narrow" className="[grid-area:from]">
538
- From · Subject
539
- </span>
540
- <span data-col="subject" className="[grid-area:subject]">
541
- Subject
542
- </span>
543
- <span className="text-right [grid-area:date]">Received</span>
544
- </div>
585
+ {mailbox &&
586
+ (activeFolder?.systemType === "trash" ||
587
+ activeFolder?.systemType === "spam") &&
588
+ activeFolder.totalCount > 0 && (
589
+ <FolderCleanupBar
590
+ mailboxId={mailbox.id}
591
+ folder={activeFolder.systemType}
592
+ folderName={folderName}
593
+ conversationCount={activeFolder.totalCount}
594
+ retentionDays={activeFolder.retentionDays}
595
+ canEmpty={mailbox.canSend}
596
+ follow={mail.followChange}
597
+ />
545
598
  )}
546
- {body}
547
- </div>
599
+
600
+ <ListScroller key={listKey} hidden={Boolean(conversationId)}>
601
+ <StaleContent stale={mail.listStale}>
602
+ {hasConversations &&
603
+ !mail.listLoading &&
604
+ !listPlaceholder &&
605
+ !mail.listError && (
606
+ <div className="mail-columns border-border bg-surface-sunken text-muted-foreground sticky top-0 z-20 h-8 border-b text-[11px] font-semibold tracking-[0.04em] uppercase">
607
+ <span className="grid place-items-center [grid-area:check]">
608
+ <Checkbox
609
+ aria-label={
610
+ selection.allLoadedSelected
611
+ ? "Deselect all loaded conversations"
612
+ : "Select all loaded conversations"
613
+ }
614
+ checked={selection.allLoadedSelected}
615
+ indeterminate={
616
+ !selection.allLoadedSelected &&
617
+ selection.selectedConversations.length > 0
618
+ }
619
+ disabled={selection.pending}
620
+ onCheckedChange={selection.toggleAllLoaded}
621
+ className="size-4 rounded-[4px]"
622
+ />
623
+ </span>
624
+ <span data-col="from-wide" className="[grid-area:from]">
625
+ {inDrafts ? "To" : "From"}
626
+ </span>
627
+ <span data-col="from-narrow" className="[grid-area:from]">
628
+ {inDrafts ? "To" : "From"} · Subject
629
+ </span>
630
+ <span data-col="subject" className="[grid-area:subject]">
631
+ Subject
632
+ </span>
633
+ <span className="text-right [grid-area:date]">
634
+ {inDrafts ? "Saved" : "Received"}
635
+ </span>
636
+ </div>
637
+ )}
638
+ {body}
639
+ </StaleContent>
640
+ </ListScroller>
641
+ </div>
642
+ );
643
+ }
644
+
645
+ /**
646
+ * The list's scroll box, keyed by the list it shows. A phone hides it behind
647
+ * the open conversation, and a hidden box may lose its scroll (Safari): shown
648
+ * again, it goes back exactly where it was.
649
+ */
650
+ function ListScroller({
651
+ hidden,
652
+ children,
653
+ }: {
654
+ hidden: boolean;
655
+ children: ReactNode;
656
+ }) {
657
+ const scroller = useRef<HTMLDivElement>(null);
658
+ const lastScroll = useRef(0);
659
+ const wasHidden = useRef(hidden);
660
+
661
+ useLayoutEffect(() => {
662
+ const element = scroller.current;
663
+
664
+ if (wasHidden.current && !hidden && element && element.clientHeight > 0) {
665
+ element.scrollTop = lastScroll.current;
666
+ }
667
+
668
+ wasHidden.current = hidden;
669
+ });
670
+
671
+ return (
672
+ <div
673
+ ref={scroller}
674
+ onScroll={(event) => {
675
+ // Only while it shows: hiding it can reset its scroll.
676
+ if (event.currentTarget.clientHeight > 0) {
677
+ lastScroll.current = event.currentTarget.scrollTop;
678
+ }
679
+ }}
680
+ className="@container/mail-list min-h-0 flex-1 overflow-y-auto pb-24"
681
+ >
682
+ {children}
548
683
  </div>
549
684
  );
550
685
  }