@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
package/src/client.tsx CHANGED
@@ -1,15 +1,36 @@
1
1
  import { preloadable } from "@open-workspace/core/ui";
2
- import type { ClientModule } from "@open-workspace/core/ui";
3
- import { Bell, Mail, MonitorSmartphone, ShieldBan } from "lucide-react";
4
- import { lazy } from "react";
2
+ import type {
3
+ ClientModule,
4
+ TeamAddress,
5
+ UserAddress,
6
+ } from "@open-workspace/core/ui";
7
+ import {
8
+ Archive,
9
+ Bell,
10
+ Mail,
11
+ MonitorSmartphone,
12
+ PenLine,
13
+ Plane,
14
+ ShieldBan,
15
+ } from "lucide-react";
16
+ import { lazy, Suspense } from "react";
5
17
 
6
18
  import { MAIL_ROUTE } from "../shared/mail-path";
7
19
  import { EMAIL_MODULE } from "../shared/module";
8
20
  import { MANAGE_BLOCKED_SENDERS } from "../shared/permissions";
9
21
  import { emailWebhookEvents } from "../shared/webhooks";
22
+ import { ForwardDestinations } from "./admin/forward-destinations";
10
23
  import { prefetchMail } from "./mail/mail-prefetch";
11
- import { loadSanitizer } from "./mail/mail-queries";
24
+ import { loadSanitizer, mailboxesQuery } from "./mail/mail-queries";
12
25
  import { seedMail } from "./mail/mail-seed";
26
+ import {
27
+ adminBlockedSendersQuery,
28
+ autoReplyMailboxesQuery,
29
+ mailArchiveQuery,
30
+ notificationPreferencesQuery,
31
+ pushConfigQuery,
32
+ signatureQuery,
33
+ } from "./settings/settings-queries";
13
34
 
14
35
  import "./mail/mail-layout.css";
15
36
 
@@ -25,6 +46,39 @@ const mailBackground = preloadable(() =>
25
46
 
26
47
  const MailboxRoute = mailboxRoute.Component;
27
48
 
49
+ const TeamSignature = lazy(() =>
50
+ import("./admin/team-signature").then((module) => ({
51
+ default: module.TeamSignature,
52
+ }))
53
+ );
54
+
55
+ // Core renders team address sections without a Suspense boundary of their own.
56
+ function TeamSignatureSection({ address }: { address: TeamAddress }) {
57
+ return (
58
+ <Suspense fallback={null}>
59
+ <TeamSignature address={address} />
60
+ </Suspense>
61
+ );
62
+ }
63
+
64
+ const AddressAutoReply = lazy(() =>
65
+ import("./admin/address-auto-reply").then((module) => ({
66
+ default: module.AddressAutoReply,
67
+ }))
68
+ );
69
+
70
+ function AddressAutoReplySection({
71
+ address,
72
+ }: {
73
+ address: TeamAddress | UserAddress;
74
+ }) {
75
+ return (
76
+ <Suspense fallback={null}>
77
+ <AddressAutoReply address={address} />
78
+ </Suspense>
79
+ );
80
+ }
81
+
28
82
  const mail: ClientModule = {
29
83
  name: EMAIL_MODULE,
30
84
  home: { label: "mail", Component: MailboxRoute },
@@ -36,22 +90,56 @@ const mail: ClientModule = {
36
90
  label: "Notifications",
37
91
  description: "New mail alerts for this device and your mailboxes.",
38
92
  Icon: Bell,
39
- Component: lazy(() =>
40
- import("./settings/notifications-page").then((module) => ({
41
- default: module.NotificationsSettings,
42
- }))
93
+ ...preloadable(() =>
94
+ import("./settings/notifications-page").then(
95
+ (module) => module.NotificationsSettings
96
+ )
97
+ ),
98
+ prefetch: (queryClient) => {
99
+ void queryClient.prefetchQuery(pushConfigQuery);
100
+ void queryClient.prefetchQuery(notificationPreferencesQuery);
101
+ },
102
+ },
103
+ {
104
+ id: "signature",
105
+ label: "Signature",
106
+ description: "Added to messages you send from your own mailboxes.",
107
+ Icon: PenLine,
108
+ ...preloadable(() =>
109
+ import("./settings/signature-page").then(
110
+ (module) => module.SignatureSettings
111
+ )
43
112
  ),
113
+ prefetch: (queryClient) => {
114
+ void queryClient.prefetchQuery(signatureQuery);
115
+ void queryClient.prefetchQuery(mailboxesQuery());
116
+ },
117
+ },
118
+ {
119
+ id: "auto-reply",
120
+ label: "Auto-reply",
121
+ description: "Answer incoming mail automatically while you're away.",
122
+ Icon: Plane,
123
+ ...preloadable(() =>
124
+ import("./settings/auto-reply-page").then(
125
+ (module) => module.AutoReplySettings
126
+ )
127
+ ),
128
+ prefetch: (queryClient) =>
129
+ void queryClient.prefetchQuery(autoReplyMailboxesQuery),
44
130
  },
45
131
  {
46
132
  id: "mail-apps",
47
133
  label: "Mail apps",
48
134
  description: "Connect a JMAP mail app with your account.",
49
135
  Icon: MonitorSmartphone,
50
- Component: lazy(() =>
51
- import("./settings/mail-apps-page").then((module) => ({
52
- default: module.MailAppsSettings,
53
- }))
136
+ ...preloadable(() =>
137
+ import("./settings/mail-apps-page").then(
138
+ (module) => module.MailAppsSettings
139
+ )
54
140
  ),
141
+ prefetch: (queryClient) =>
142
+ void queryClient.prefetchQuery(mailboxesQuery()),
55
143
  },
56
144
  ],
57
145
  admin: [
@@ -63,12 +151,38 @@ const mail: ClientModule = {
63
151
  title: "Blocked senders",
64
152
  description:
65
153
  "Addresses and domains blocked for every mailbox in the workspace.",
66
- Component: lazy(() =>
67
- import("./admin/blocked-senders").then((module) => ({
68
- default: module.BlockedSenders,
69
- }))
154
+ ...preloadable(() =>
155
+ import("./admin/blocked-senders").then(
156
+ (module) => module.BlockedSenders
157
+ )
70
158
  ),
159
+ prefetch: (queryClient) =>
160
+ void queryClient.prefetchQuery(adminBlockedSendersQuery),
71
161
  },
162
+ {
163
+ id: "mail-archive",
164
+ label: "Mail archive",
165
+ Icon: Archive,
166
+ // Administrators only, like Backups.
167
+ title: "Mail archive",
168
+ description:
169
+ "A write-once copy of every message the workspace receives and sends.",
170
+ ...preloadable(() =>
171
+ import("./admin/mail-archive").then((module) => module.MailArchive)
172
+ ),
173
+ prefetch: (queryClient) =>
174
+ void queryClient.prefetchQuery(mailArchiveQuery),
175
+ },
176
+ ],
177
+ teamAddress: [
178
+ { id: "signature", Component: TeamSignatureSection },
179
+ { id: "auto-reply", Component: AddressAutoReplySection },
180
+ // A forward's destinations, Confirmed or Waiting, in both address editors.
181
+ { id: "forward-destinations", Component: ForwardDestinations },
182
+ ],
183
+ userAddress: [
184
+ { id: "auto-reply", Component: AddressAutoReplySection },
185
+ { id: "forward-destinations", Component: ForwardDestinations },
72
186
  ],
73
187
  webhookEvents: emailWebhookEvents,
74
188
  background: mailBackground.Component,
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  buttonVariants,
3
+ DelayedFallback,
3
4
  DialogContent,
4
5
  DialogDescription,
5
6
  DialogTitle,
7
+ useDelayedPending,
6
8
  } from "@open-workspace/core/ui";
7
9
  import { Download, LoaderCircle } from "lucide-react";
8
10
  import { lazy, Suspense, useState } from "react";
@@ -80,6 +82,8 @@ function AttachmentPreviewContent({
80
82
  }) {
81
83
  const [loading, setLoading] = useState(true);
82
84
  const [failed, setFailed] = useState(false);
85
+ // Over the preview as it loads: gone the moment it shows, held no longer.
86
+ const spinner = useDelayedPending(loading, { min: 0 });
83
87
  const unavailable = failed || status === "failed";
84
88
 
85
89
  if (status === "pending") {
@@ -98,10 +102,14 @@ function AttachmentPreviewContent({
98
102
  return (
99
103
  <Suspense
100
104
  fallback={
101
- <div role="status" className="grid flex-1 place-items-center">
102
- <LoaderCircle className="size-6 animate-spin" />
103
- <span className="sr-only">Loading PDF</span>
104
- </div>
105
+ <DelayedFallback
106
+ fallback={
107
+ <div role="status" className="grid flex-1 place-items-center">
108
+ <LoaderCircle className="size-6 animate-spin" />
109
+ <span className="sr-only">Loading PDF</span>
110
+ </div>
111
+ }
112
+ />
105
113
  }
106
114
  >
107
115
  <PdfPreview
@@ -126,7 +134,7 @@ function AttachmentPreviewContent({
126
134
  </p>
127
135
  ) : (
128
136
  <>
129
- {loading && (
137
+ {loading && spinner && (
130
138
  <div
131
139
  role="status"
132
140
  className="pointer-events-none absolute inset-0 grid place-items-center"
@@ -0,0 +1,61 @@
1
+ import { Button, responseJson } from "@open-workspace/core/ui";
2
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
3
+ import { LoaderCircle, Plane } from "lucide-react";
4
+ import { Link } from "react-router";
5
+ import { toast } from "sonner";
6
+
7
+ import { mailApi } from "../lib/mail-api";
8
+ import { autoReplyQuery } from "../settings/settings-queries";
9
+ import type { Mailbox } from "./types";
10
+
11
+ /** Shown while one of your own mailboxes answers mail automatically, with a quick way out. */
12
+ export function AutoReplyBanner({ mailbox }: { mailbox: Mailbox }) {
13
+ const client = useQueryClient();
14
+
15
+ const query = useQuery({
16
+ ...autoReplyQuery(mailbox.id),
17
+ staleTime: 60_000,
18
+ });
19
+
20
+ const turnOff = useMutation({
21
+ mutationFn: async (mailboxId: string) =>
22
+ responseJson(
23
+ await mailApi.api.mail.mailboxes[":id"]["auto-reply"].$patch({
24
+ param: { id: mailboxId },
25
+ json: { enabled: false },
26
+ })
27
+ ),
28
+ onSuccess: (result, mailboxId) => {
29
+ client.setQueryData(autoReplyQuery(mailboxId).queryKey, result);
30
+ toast.success("Auto-reply turned off");
31
+ },
32
+ onError: (error) => toast.error(error.message),
33
+ });
34
+
35
+ if (query.data?.status !== "active") return null;
36
+
37
+ return (
38
+ <div className="border-border bg-primary/10 flex shrink-0 flex-wrap items-center gap-x-3 gap-y-2 rounded-lg border px-3.5 py-2 text-sm">
39
+ <Plane className="text-primary size-4 shrink-0" />
40
+ <span className="min-w-0 flex-1">
41
+ Automatic replies are on for {mailbox.address}.{" "}
42
+ <Link
43
+ to="/settings/auto-reply"
44
+ className="underline underline-offset-2"
45
+ >
46
+ Edit
47
+ </Link>
48
+ </span>
49
+ <Button
50
+ type="button"
51
+ size="sm"
52
+ variant="outline"
53
+ disabled={turnOff.isPending}
54
+ onClick={() => turnOff.mutate(mailbox.id)}
55
+ >
56
+ {turnOff.isPending && <LoaderCircle className="animate-spin" />}
57
+ Turn off
58
+ </Button>
59
+ </div>
60
+ );
61
+ }
@@ -1,7 +1,11 @@
1
- import { Button, Input, Skeleton } from "@open-workspace/core/ui";
1
+ import {
2
+ Button,
3
+ DelayedFallback,
4
+ Input,
5
+ Skeleton,
6
+ } from "@open-workspace/core/ui";
2
7
  import { Building2, LoaderCircle, ShieldBan } from "lucide-react";
3
- import { useState } from "react";
4
- import type { FormEvent } from "react";
8
+ import { useForm, useWatch } from "react-hook-form";
5
9
  import { toast } from "sonner";
6
10
 
7
11
  import { normalizeBlockPattern } from "../../shared/mail-feedback";
@@ -15,123 +19,152 @@ import {
15
19
  export function BlockedSendersManager({
16
20
  mailboxId,
17
21
  active,
22
+ canOrganize,
18
23
  }: {
19
24
  mailboxId: string;
20
25
  active: boolean;
26
+ canOrganize: boolean;
21
27
  }) {
22
28
  const blocked = useBlockedSenders(mailboxId, active);
23
29
  const block = useBlockSender();
24
30
  const unblock = useUnblockSender();
25
- const [value, setValue] = useState("");
26
- const pattern = normalizeBlockPattern(value);
27
31
 
28
- function submit(event: FormEvent) {
29
- event.preventDefault();
32
+ const { control, handleSubmit, register, reset } = useForm({
33
+ defaultValues: { value: "" },
34
+ });
35
+
36
+ const pattern = normalizeBlockPattern(useWatch({ control, name: "value" }));
30
37
 
38
+ const submit = handleSubmit(() => {
31
39
  if (!pattern) return;
32
40
  block.mutate(
33
41
  { mailboxId, pattern, moveExisting: false },
34
42
  {
35
43
  onSuccess: (result) => {
36
- setValue("");
44
+ reset();
37
45
  toast.success(`Blocked ${result.block.pattern}`);
38
46
  },
39
47
  onError: (error) => toast.error(error.message),
40
48
  }
41
49
  );
42
- }
50
+ });
43
51
 
44
52
  const items = blocked.data?.blocked ?? [];
45
53
  const workspace = blocked.data?.workspace ?? [];
46
54
 
47
55
  return (
48
56
  <div className="space-y-3">
49
- <form className="flex gap-2" onSubmit={submit}>
50
- <Input
51
- aria-label="Address or domain to block"
52
- placeholder="name@example.com or example.com"
53
- value={value}
54
- onChange={(event) => setValue(event.target.value)}
55
- />
56
- <Button
57
- type="submit"
58
- variant="outline"
59
- disabled={!pattern || block.isPending}
60
- >
61
- {block.isPending ? (
62
- <LoaderCircle className="animate-spin" />
63
- ) : (
64
- <ShieldBan />
65
- )}
66
- Block
67
- </Button>
68
- </form>
57
+ {canOrganize && (
58
+ <form className="flex gap-2" onSubmit={submit}>
59
+ <Input
60
+ aria-label="Address or domain to block"
61
+ placeholder="name@example.com or example.com"
62
+ {...register("value")}
63
+ />
64
+ <Button
65
+ type="submit"
66
+ variant="outline"
67
+ disabled={!pattern || block.isPending}
68
+ >
69
+ {block.isPending ? (
70
+ <LoaderCircle className="animate-spin" />
71
+ ) : (
72
+ <ShieldBan />
73
+ )}
74
+ Block
75
+ </Button>
76
+ </form>
77
+ )}
69
78
  <div className="border-border/70 max-h-[min(23rem,50vh)] overflow-y-auto border-y">
70
- {blocked.isLoading ? (
71
- <div className="space-y-2 py-3">
72
- <Skeleton className="h-10" />
73
- <Skeleton className="h-10" />
74
- </div>
75
- ) : items.length || workspace.length ? (
76
- <ul aria-label="Blocked senders">
77
- {items.map((item) => (
78
- <li
79
- key={item.pattern}
80
- className="border-border/60 flex min-h-12 items-center gap-3 border-b px-2 py-2 last:border-b-0"
79
+ <DelayedFallback
80
+ pending={blocked.isLoading}
81
+ fallback={
82
+ <div className="space-y-2 py-3">
83
+ <Skeleton className="h-10" />
84
+ <Skeleton className="h-10" />
85
+ </div>
86
+ }
87
+ >
88
+ {blocked.isError ? (
89
+ <div className="grid min-h-28 place-items-center gap-2 px-6 py-4 text-center text-sm">
90
+ <p className="text-destructive">
91
+ Blocked senders couldn't be loaded.
92
+ </p>
93
+ <Button
94
+ type="button"
95
+ variant="outline"
96
+ size="sm"
97
+ onClick={() => void blocked.refetch()}
81
98
  >
82
- <ShieldBan className="text-muted-foreground size-4 shrink-0" />
83
- <div className="min-w-0 flex-1">
84
- <p className="truncate text-sm font-medium">{item.pattern}</p>
85
- <p className="text-muted-foreground text-xs">
86
- {item.scope === "domain" ? "Whole domain" : "Address"} ·
87
- blocked{" "}
88
- {new Date(item.blockedAt).toLocaleDateString("en", {
89
- dateStyle: "medium",
90
- })}
91
- </p>
92
- </div>
93
- <Button
94
- type="button"
95
- variant="ghost"
96
- size="sm"
97
- aria-label={`Unblock ${item.pattern}`}
98
- disabled={unblock.isPending}
99
- onClick={() =>
100
- unblock.mutate(
101
- { mailboxId, pattern: item.pattern },
102
- {
103
- onSuccess: () =>
104
- toast.success(`Unblocked ${item.pattern}`),
105
- onError: (error) => toast.error(error.message),
99
+ Retry
100
+ </Button>
101
+ </div>
102
+ ) : items.length || workspace.length ? (
103
+ <ul aria-label="Blocked senders">
104
+ {items.map((item) => (
105
+ <li
106
+ key={item.pattern}
107
+ className="border-border/60 flex min-h-12 items-center gap-3 border-b px-2 py-2 last:border-b-0"
108
+ >
109
+ <ShieldBan className="text-muted-foreground size-4 shrink-0" />
110
+ <div className="min-w-0 flex-1">
111
+ <p className="truncate text-sm font-medium">
112
+ {item.pattern}
113
+ </p>
114
+ <p className="text-muted-foreground text-xs">
115
+ {item.scope === "domain" ? "Whole domain" : "Address"} ·
116
+ blocked{" "}
117
+ {new Date(item.blockedAt).toLocaleDateString("en", {
118
+ dateStyle: "medium",
119
+ })}
120
+ </p>
121
+ </div>
122
+ {canOrganize && (
123
+ <Button
124
+ type="button"
125
+ variant="ghost"
126
+ size="sm"
127
+ aria-label={`Unblock ${item.pattern}`}
128
+ disabled={unblock.isPending}
129
+ onClick={() =>
130
+ unblock.mutate(
131
+ { mailboxId, pattern: item.pattern },
132
+ {
133
+ onSuccess: () =>
134
+ toast.success(`Unblocked ${item.pattern}`),
135
+ onError: (error) => toast.error(error.message),
136
+ }
137
+ )
106
138
  }
107
- )
108
- }
139
+ >
140
+ Unblock
141
+ </Button>
142
+ )}
143
+ </li>
144
+ ))}
145
+ {workspace.map((item) => (
146
+ <li
147
+ key={`workspace-${item.pattern}`}
148
+ className="border-border/60 flex min-h-12 items-center gap-3 border-b px-2 py-2 last:border-b-0"
109
149
  >
110
- Unblock
111
- </Button>
112
- </li>
113
- ))}
114
- {workspace.map((item) => (
115
- <li
116
- key={`workspace-${item.pattern}`}
117
- className="border-border/60 flex min-h-12 items-center gap-3 border-b px-2 py-2 last:border-b-0"
118
- >
119
- <Building2 className="text-muted-foreground size-4 shrink-0" />
120
- <div className="min-w-0 flex-1">
121
- <p className="truncate text-sm font-medium">{item.pattern}</p>
122
- <p className="text-muted-foreground text-xs">
123
- Blocked for everyone by an administrator
124
- </p>
125
- </div>
126
- </li>
127
- ))}
128
- </ul>
129
- ) : (
130
- <div className="text-muted-foreground grid min-h-28 place-items-center px-6 text-center text-sm">
131
- Blocked senders go straight to Spam. Block one from a message's More
132
- menu, or add it here.
133
- </div>
134
- )}
150
+ <Building2 className="text-muted-foreground size-4 shrink-0" />
151
+ <div className="min-w-0 flex-1">
152
+ <p className="truncate text-sm font-medium">
153
+ {item.pattern}
154
+ </p>
155
+ <p className="text-muted-foreground text-xs">
156
+ Blocked for everyone by an administrator
157
+ </p>
158
+ </div>
159
+ </li>
160
+ ))}
161
+ </ul>
162
+ ) : (
163
+ <div className="text-muted-foreground grid min-h-28 place-items-center px-6 text-center text-sm">
164
+ No blocked senders.
165
+ </div>
166
+ )}
167
+ </DelayedFallback>
135
168
  </div>
136
169
  </div>
137
170
  );
@@ -6,11 +6,11 @@ import {
6
6
  Minus,
7
7
  Paperclip,
8
8
  Send,
9
+ Trash2,
9
10
  X,
10
11
  } from "lucide-react";
11
12
  import type { Ref, RefObject } from "react";
12
13
 
13
- import type { ComposerAsset } from "./composer-session";
14
14
  import { formatBytes } from "./format-bytes";
15
15
  import type { MessageDetail } from "./types";
16
16
 
@@ -54,11 +54,13 @@ export function ComposeWindowHeader({
54
54
  from,
55
55
  minimizeRef,
56
56
  onMinimize,
57
+ onDiscard,
57
58
  onClose,
58
59
  }: {
59
60
  from: string;
60
61
  minimizeRef?: Ref<HTMLButtonElement>;
61
62
  onMinimize: () => void;
63
+ onDiscard: () => void;
62
64
  onClose: () => void;
63
65
  }) {
64
66
  return (
@@ -69,6 +71,16 @@ export function ComposeWindowHeader({
69
71
  From {from}
70
72
  </p>
71
73
  </div>
74
+ <Button
75
+ type="button"
76
+ variant="ghost"
77
+ size="icon-sm"
78
+ title="Discard draft"
79
+ onClick={onDiscard}
80
+ >
81
+ <Trash2 />
82
+ <span className="sr-only">Discard draft</span>
83
+ </Button>
72
84
  <Button
73
85
  ref={minimizeRef}
74
86
  className="hidden sm:inline-flex"
@@ -111,7 +123,7 @@ export function ForwardedMessageNotice({
111
123
  export function ComposeWindowFooter({
112
124
  fileInput,
113
125
  inlineFileInput,
114
- uploads,
126
+ files,
115
127
  error,
116
128
  sending,
117
129
  sendDisabled,
@@ -120,7 +132,7 @@ export function ComposeWindowFooter({
120
132
  }: {
121
133
  fileInput: RefObject<HTMLInputElement | null>;
122
134
  inlineFileInput: RefObject<HTMLInputElement | null>;
123
- uploads: readonly ComposerAsset[];
135
+ files: readonly { size: number }[];
124
136
  error: string | null;
125
137
  sending: boolean;
126
138
  sendDisabled: boolean;
@@ -178,14 +190,14 @@ export function ComposeWindowFooter({
178
190
  </Button>
179
191
  <span
180
192
  className={cn(
181
- "text-muted-foreground min-w-0 flex-1 truncate text-[11px]",
182
- error && "text-destructive"
193
+ "text-muted-foreground min-w-0 flex-1 text-[11px]",
194
+ error ? "text-destructive" : "truncate"
183
195
  )}
184
196
  >
185
197
  {error ||
186
- (uploads.length
187
- ? `${uploads.length} files · ${formatBytes(
188
- uploads.reduce((total, upload) => total + upload.size, 0)
198
+ (files.length
199
+ ? `${files.length} file${files.length === 1 ? "" : "s"} · ${formatBytes(
200
+ files.reduce((total, upload) => total + upload.size, 0)
189
201
  )}`
190
202
  : "Drop files into message · up to 500 MB")}
191
203
  </span>