@open-workspace/email 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/README.md +23 -20
  2. package/alchemy/index.ts +273 -0
  3. package/drizzle/mailbox/0000_puzzling_dracula.sql +149 -0
  4. package/drizzle/mailbox/0001_mute_jack_flag.sql +12 -0
  5. package/drizzle/mailbox/meta/0000_snapshot.json +1002 -0
  6. package/drizzle/mailbox/meta/0001_snapshot.json +1002 -0
  7. package/drizzle/mailbox/meta/_journal.json +20 -0
  8. package/drizzle/mailbox/migrations.js +12 -0
  9. package/index.ts +3 -1
  10. package/migrations/0000_dry_moon_knight.sql +77 -0
  11. package/migrations/meta/0000_snapshot.json +248 -106
  12. package/migrations/meta/_journal.json +2 -2
  13. package/package.json +74 -68
  14. package/shared/attachment-preview.ts +37 -27
  15. package/shared/folder-order.ts +106 -0
  16. package/shared/mail-authentication.ts +8 -3
  17. package/shared/mail-feedback.ts +18 -25
  18. package/shared/mail-headers.ts +114 -39
  19. package/shared/mail-import.ts +38 -0
  20. package/shared/mail-path.ts +42 -0
  21. package/shared/mail-received.ts +174 -31
  22. package/shared/mail-remote.ts +59 -2
  23. package/shared/mail-sender-intel.ts +22 -4
  24. package/shared/mail.ts +78 -26
  25. package/shared/module.ts +33 -0
  26. package/shared/office-preview.ts +14 -2
  27. package/shared/pdfjs-assets.ts +35 -0
  28. package/shared/permissions.ts +73 -0
  29. package/shared/webhooks.ts +41 -0
  30. package/src/admin/blocked-senders.tsx +189 -0
  31. package/src/client.tsx +97 -0
  32. package/src/lib/mail-api.ts +9 -0
  33. package/src/mail/attachment-preview-dialog.tsx +161 -0
  34. package/src/mail/blocked-senders.tsx +138 -0
  35. package/src/mail/compose-window-chrome.tsx +194 -0
  36. package/src/mail/compose-window.tsx +486 -0
  37. package/src/mail/composer-asset-bookmarks.ts +409 -0
  38. package/src/mail/composer-asset.tsx +229 -0
  39. package/src/mail/composer-attachment-list.tsx +138 -0
  40. package/src/mail/composer-editor-document.ts +65 -0
  41. package/src/mail/composer-editor.tsx +284 -0
  42. package/src/mail/composer-linked-attachment-text.ts +12 -0
  43. package/src/mail/composer-recipient-fields.tsx +165 -0
  44. package/src/mail/composer-recipients.ts +208 -0
  45. package/src/mail/composer-session.ts +562 -0
  46. package/src/mail/composer-toolbar.tsx +303 -0
  47. package/src/mail/composer-upload-client.ts +105 -0
  48. package/src/mail/composer-upload-progress.ts +53 -0
  49. package/src/mail/conversation-list.tsx +550 -0
  50. package/src/mail/conversation-loading-skeleton.tsx +119 -0
  51. package/src/mail/conversation-message.tsx +346 -0
  52. package/src/mail/conversation-reply.tsx +470 -0
  53. package/src/mail/conversation-selection-toolbar.tsx +322 -0
  54. package/src/mail/conversation-view.tsx +437 -0
  55. package/src/mail/delivery-indicator.tsx +272 -0
  56. package/src/mail/email-html-body.tsx +203 -0
  57. package/src/mail/folder-glyph.tsx +46 -0
  58. package/src/mail/folder-manager.tsx +532 -0
  59. package/src/mail/format-bytes.ts +7 -0
  60. package/src/mail/mail-app-bar.tsx +253 -0
  61. package/src/mail/mail-background.tsx +12 -0
  62. package/src/mail/mail-dock.tsx +137 -0
  63. package/src/mail/mail-folders.ts +44 -0
  64. package/src/mail/mail-layout.css +236 -0
  65. package/src/mail/mail-location.ts +73 -0
  66. package/src/mail/mail-mailbox-sheet.tsx +275 -0
  67. package/src/mail/mail-nav-rail.tsx +129 -0
  68. package/src/mail/mail-nav.tsx +324 -0
  69. package/src/mail/mail-prefetch.ts +59 -0
  70. package/src/mail/mail-primitives.tsx +66 -0
  71. package/src/mail/mail-queries.ts +209 -0
  72. package/src/mail/mail-query-cache.ts +486 -0
  73. package/src/mail/mail-seed.ts +47 -0
  74. package/src/mail/mail-shell.tsx +126 -0
  75. package/src/mail/mailbox-ai-settings.tsx +185 -0
  76. package/src/mail/mailbox-realtime.tsx +251 -0
  77. package/src/mail/mailbox-route.tsx +15 -0
  78. package/src/mail/message-actions.tsx +353 -0
  79. package/src/mail/message-attachments.tsx +200 -0
  80. package/src/mail/message-format.ts +75 -0
  81. package/src/mail/message-header.tsx +260 -0
  82. package/src/mail/message-translation.tsx +225 -0
  83. package/src/mail/original-message-sheet.tsx +619 -0
  84. package/src/mail/original-message.ts +191 -0
  85. package/src/mail/outbound-notification.ts +53 -0
  86. package/src/mail/pane-splitter.tsx +117 -0
  87. package/src/mail/pdf-preview-toolbar.tsx +152 -0
  88. package/src/mail/pdf-preview.css +44 -0
  89. package/src/mail/pdf-preview.tsx +156 -0
  90. package/src/mail/pdf-translation-layout.ts +95 -0
  91. package/src/mail/print-message.ts +92 -0
  92. package/src/mail/reader-pane.tsx +535 -0
  93. package/src/mail/recipient-combobox.tsx +335 -0
  94. package/src/mail/recipient-field-row.tsx +34 -0
  95. package/src/mail/reply-to-warning.tsx +50 -0
  96. package/src/mail/sanitize-email-html.ts +430 -0
  97. package/src/mail/sender-actions.tsx +149 -0
  98. package/src/mail/sender-authentication.tsx +485 -0
  99. package/src/mail/sender-dialogs.tsx +384 -0
  100. package/src/mail/sender-security.tsx +545 -0
  101. package/src/mail/toolbar-tooltip.tsx +29 -0
  102. package/src/mail/translation-html.ts +49 -0
  103. package/src/mail/translation-language.ts +21 -0
  104. package/src/mail/types.ts +53 -0
  105. package/src/mail/unread-document-indicator.tsx +60 -0
  106. package/src/mail/use-compose-submission.ts +208 -0
  107. package/src/mail/use-composer-attachment-preflight.ts +184 -0
  108. package/src/mail/use-composer-submission.ts +117 -0
  109. package/src/mail/use-conversation-selection.ts +186 -0
  110. package/src/mail/use-mail-controller.ts +427 -0
  111. package/src/mail/use-mail-data.ts +279 -0
  112. package/src/mail/use-mail-safety.ts +155 -0
  113. package/src/mail/use-mail-send.ts +142 -0
  114. package/src/mail/use-pdf-translation-overlay.ts +156 -0
  115. package/src/mail/use-pdf-translation.ts +100 -0
  116. package/src/mail/use-pdf-viewer.ts +215 -0
  117. package/src/mail/use-reply-submission.ts +114 -0
  118. package/src/mail/use-sanitized-email-html.ts +20 -0
  119. package/src/mail/use-visible-message-read.ts +138 -0
  120. package/src/pwa/push-subscription.ts +151 -0
  121. package/src/settings/mail-apps-page.tsx +235 -0
  122. package/src/settings/notifications-page.tsx +291 -0
  123. package/worker/admin/blocked-sender-routes.ts +166 -0
  124. package/worker/admin/schemas.ts +11 -0
  125. package/worker/bindings.d.ts +14 -10
  126. package/worker/db/schema.ts +90 -34
  127. package/worker/jmap/eventsource.ts +169 -0
  128. package/worker/jmap/methods.ts +1716 -361
  129. package/worker/jmap/push-types.ts +27 -0
  130. package/worker/jmap/push.ts +207 -0
  131. package/worker/jmap/routes.ts +448 -86
  132. package/worker/mail/access.ts +258 -21
  133. package/worker/mail/ai-classification.ts +36 -20
  134. package/worker/mail/ai-translation.ts +13 -6
  135. package/worker/mail/auth-headers.ts +395 -137
  136. package/worker/mail/bimi.ts +200 -73
  137. package/worker/mail/bootstrap.ts +79 -0
  138. package/worker/mail/capped-body.ts +36 -0
  139. package/worker/mail/classification-signals.ts +35 -25
  140. package/worker/mail/conversation-cursor.ts +30 -19
  141. package/worker/mail/delivery-events.ts +88 -62
  142. package/worker/mail/delivery-facts.ts +46 -10
  143. package/worker/mail/demo-routes.ts +34 -10
  144. package/worker/mail/doh.ts +62 -23
  145. package/worker/mail/downloads.ts +75 -40
  146. package/worker/mail/edge-cache.ts +155 -0
  147. package/worker/mail/header-metadata.ts +84 -52
  148. package/worker/mail/impersonation.ts +160 -38
  149. package/worker/mail/import-routes.ts +313 -0
  150. package/worker/mail/inbound-delivery.ts +19 -9
  151. package/worker/mail/inbound-threading.ts +18 -8
  152. package/worker/mail/inbound.ts +82 -40
  153. package/worker/mail/ip-intel.ts +110 -27
  154. package/worker/mail/isolate-cache.ts +35 -0
  155. package/worker/mail/link-domains.ts +29 -7
  156. package/worker/mail/mailbox-deletion.ts +10 -4
  157. package/worker/mail/mailbox-directory.ts +16 -6
  158. package/worker/mail/mailing-list.ts +94 -39
  159. package/worker/mail/message-security.ts +90 -15
  160. package/worker/mail/message-view.ts +18 -6
  161. package/worker/mail/office-conversion.ts +31 -9
  162. package/worker/mail/office-preview-container.ts +40 -13
  163. package/worker/mail/office-preview-queue.ts +76 -32
  164. package/worker/mail/org-domain.ts +8 -1
  165. package/worker/mail/outbound-content.ts +71 -26
  166. package/worker/mail/outbound-delivery.ts +31 -17
  167. package/worker/mail/outbound-service.ts +48 -30
  168. package/worker/mail/outbound-threading.ts +30 -17
  169. package/worker/mail/outbound.ts +97 -70
  170. package/worker/mail/outgoing-context.ts +25 -15
  171. package/worker/mail/participants.ts +44 -29
  172. package/worker/mail/push-notifications.ts +283 -171
  173. package/worker/mail/quote-parser.ts +21 -10
  174. package/worker/mail/r2-presigned-urls.ts +31 -25
  175. package/worker/mail/receive.ts +23 -11
  176. package/worker/mail/recipients.ts +6 -1
  177. package/worker/mail/remote-proxy.ts +187 -31
  178. package/worker/mail/remote-routes.ts +87 -0
  179. package/worker/mail/remote-token.ts +104 -0
  180. package/worker/mail/repeat.ts +19 -0
  181. package/worker/mail/reply-plan.ts +62 -33
  182. package/worker/mail/rfc.ts +32 -7
  183. package/worker/mail/routes.ts +871 -542
  184. package/worker/mail/safety-routes.ts +329 -202
  185. package/worker/mail/schemas.ts +84 -105
  186. package/worker/mail/search.ts +1 -0
  187. package/worker/mail/security-settings.ts +41 -9
  188. package/worker/mail/sender-intel.ts +206 -51
  189. package/worker/mail/spamhaus.ts +92 -45
  190. package/worker/mail/unsubscribe.ts +76 -18
  191. package/worker/mail/uploads.ts +153 -91
  192. package/worker/mail/webhook-source.ts +35 -12
  193. package/worker/mail/workspace-safety.ts +97 -38
  194. package/worker/mailbox/demo-html.ts +7 -7
  195. package/worker/mailbox/demo-seed.ts +10 -44
  196. package/worker/mailbox/demo.ts +597 -227
  197. package/worker/mailbox/email-index.ts +53 -0
  198. package/worker/mailbox/folder-model.ts +53 -17
  199. package/worker/mailbox/import-placement.ts +88 -0
  200. package/worker/mailbox/inbox-counts.ts +106 -0
  201. package/worker/mailbox/index.ts +1761 -737
  202. package/worker/mailbox/jmap-store.ts +139 -35
  203. package/worker/mailbox/model.ts +7 -14
  204. package/worker/mailbox/office-preview-jobs.ts +56 -25
  205. package/worker/mailbox/schema.ts +87 -66
  206. package/worker/mailbox/senders.ts +176 -70
  207. package/worker/mcp/mail-action-tools.ts +128 -87
  208. package/worker/mcp/mail-compose-tools.ts +133 -82
  209. package/worker/mcp/mail-query-tools.ts +120 -71
  210. package/worker/mcp/mail-safety-tools.ts +321 -248
  211. package/worker/mcp/schemas.ts +43 -0
  212. package/worker/mcp/tools.ts +13 -10
  213. package/worker/module.ts +43 -18
  214. package/worker/sql.d.ts +8 -0
  215. package/alchemy.ts +0 -126
  216. package/containers/office-preview/Dockerfile +0 -10
  217. package/migrations/0000_email.sql +0 -53
  218. package/shared/mail-rules.ts +0 -156
  219. package/worker/admin/report-routes.ts +0 -164
  220. package/worker/mail/reported-messages.ts +0 -68
  221. package/worker/mailbox/legacy-migrations.ts +0 -41
  222. package/worker/mailbox/migrations.ts +0 -10
  223. package/worker/mailbox/rules.ts +0 -110
@@ -0,0 +1,253 @@
1
+ import { avatarSrc } from "@open-workspace/core/shared";
2
+ import {
3
+ useAuth,
4
+ Avatar,
5
+ AvatarFallback,
6
+ AvatarImage,
7
+ Badge,
8
+ AppearanceMenuRow,
9
+ DropdownMenu,
10
+ DropdownMenuContent,
11
+ DropdownMenuItem,
12
+ DropdownMenuSeparator,
13
+ DropdownMenuTrigger,
14
+ cn,
15
+ initials,
16
+ AppSwitcher,
17
+ useWorkspaceBrand,
18
+ WorkspaceLogo,
19
+ } from "@open-workspace/core/ui";
20
+ import { LogOut, Search, Settings, ShieldCheck, X } from "lucide-react";
21
+ import { useEffect, useRef } from "react";
22
+
23
+ import { EMAIL_MODULE } from "../../shared/module";
24
+ import type { MailController } from "./use-mail-controller";
25
+
26
+ /** The workspace's logo and name, then the app switcher (the app's name). */
27
+ function ProductMark() {
28
+ const brand = useWorkspaceBrand();
29
+
30
+ return (
31
+ <span className="flex min-w-0 items-center gap-2.5">
32
+ <WorkspaceLogo src={brand.logoUrl} flat />
33
+ <span className="flex min-w-0 items-center gap-2 text-[14px] leading-none tracking-[-0.015em]">
34
+ <span className="truncate font-semibold">{brand.name}</span>
35
+ <span className="bg-border h-3.5 w-px shrink-0" />
36
+ <AppSwitcher current={EMAIL_MODULE} />
37
+ </span>
38
+ </span>
39
+ );
40
+ }
41
+
42
+ /** Where the header has no room for the workspace's name: its logo, then the app switcher. */
43
+ function CompactAppSwitcher({ className }: { className?: string }) {
44
+ const brand = useWorkspaceBrand();
45
+
46
+ return (
47
+ <AppSwitcher
48
+ current={EMAIL_MODULE}
49
+ logo={<WorkspaceLogo src={brand.logoUrl} flat />}
50
+ className={className}
51
+ />
52
+ );
53
+ }
54
+
55
+ function isTypingTarget(target: EventTarget | null) {
56
+ return (
57
+ target instanceof HTMLElement &&
58
+ (target.isContentEditable ||
59
+ /^(INPUT|TEXTAREA|SELECT)$/u.test(target.tagName))
60
+ );
61
+ }
62
+
63
+ /** Search input; with `shortcut`, "/" focuses it from anywhere outside a text field. */
64
+ export function SearchField({
65
+ mail,
66
+ className,
67
+ shortcut = false,
68
+ }: {
69
+ mail: MailController;
70
+ className?: string;
71
+ shortcut?: boolean;
72
+ }) {
73
+ const inputRef = useRef<HTMLInputElement>(null);
74
+ useEffect(() => {
75
+ if (!shortcut) return;
76
+
77
+ function onKeyDown(event: KeyboardEvent) {
78
+ if (
79
+ event.key !== "/" ||
80
+ event.metaKey ||
81
+ event.ctrlKey ||
82
+ isTypingTarget(event.target)
83
+ ) {
84
+ return;
85
+ }
86
+
87
+ const input = inputRef.current;
88
+
89
+ if (!input || input.offsetParent === null) return;
90
+ event.preventDefault();
91
+ input.focus();
92
+ }
93
+
94
+ window.addEventListener("keydown", onKeyDown);
95
+
96
+ return () => window.removeEventListener("keydown", onKeyDown);
97
+ }, [shortcut]);
98
+
99
+ return (
100
+ <label
101
+ className={cn(
102
+ "border-border bg-surface flex min-w-0 items-center gap-2 rounded-lg border pr-1.5 pl-3 shadow-[var(--pane-shadow)] transition-[border-color,box-shadow]",
103
+ "hover:border-input focus-within:border-ring focus-within:ring-ring/20 focus-within:ring-3",
104
+ className
105
+ )}
106
+ >
107
+ <span className="sr-only">Search in {mail.folderName}</span>
108
+ <Search
109
+ aria-hidden="true"
110
+ className="text-muted-foreground size-3.5 shrink-0"
111
+ />
112
+ <input
113
+ ref={inputRef}
114
+ type="search"
115
+ value={mail.search}
116
+ placeholder={`Search ${mail.folderName.toLowerCase() === "inbox" ? "mail" : `in ${mail.folderName}`}`}
117
+ onChange={(event) => mail.setSearch(event.target.value)}
118
+ onKeyDown={(event) => {
119
+ if (event.key === "Escape") {
120
+ event.stopPropagation();
121
+
122
+ if (mail.search) mail.setSearch("");
123
+ else event.currentTarget.blur();
124
+ }
125
+ }}
126
+ className="text-foreground placeholder:text-muted-foreground h-full min-w-0 flex-1 bg-transparent text-[13px] outline-none [&::-webkit-search-cancel-button]:hidden"
127
+ />
128
+ {mail.search ? (
129
+ <button
130
+ type="button"
131
+ aria-label="Clear search"
132
+ onClick={() => {
133
+ mail.setSearch("");
134
+ inputRef.current?.focus();
135
+ }}
136
+ className="text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:ring-ring/50 grid size-6 shrink-0 place-items-center rounded-md outline-none focus-visible:ring-2"
137
+ >
138
+ <X className="size-3.5" />
139
+ </button>
140
+ ) : shortcut ? (
141
+ <kbd className="border-border bg-surface-sunken text-muted-foreground hidden h-5 min-w-5 shrink-0 place-items-center rounded-[5px] border px-1.5 text-[11px] md:grid">
142
+ /
143
+ </kbd>
144
+ ) : null}
145
+ </label>
146
+ );
147
+ }
148
+
149
+ function AccountMenu({ mail }: { mail: MailController }) {
150
+ const auth = useAuth();
151
+ const { user } = auth;
152
+ const fallback = initials(user?.name ?? "?");
153
+
154
+ return (
155
+ <DropdownMenu>
156
+ <DropdownMenuTrigger
157
+ aria-label={`Account: ${user?.name ?? "signed in"}`}
158
+ className={cn(
159
+ "flex h-9 shrink-0 items-center gap-2 rounded-[calc(var(--radius-lg)+2px)] p-0.5 transition-colors outline-none",
160
+ "hover:bg-foreground/[0.05] focus-visible:ring-ring aria-expanded:bg-foreground/[0.05] focus-visible:ring-2 xl:pr-3"
161
+ )}
162
+ >
163
+ <Avatar className="size-8">
164
+ <AvatarImage src={avatarSrc(user)} />
165
+ <AvatarFallback className="bg-primary/12 text-primary text-[11px] font-semibold">
166
+ {fallback}
167
+ </AvatarFallback>
168
+ </Avatar>
169
+ <span className="hidden max-w-36 truncate text-[13px] font-medium xl:block">
170
+ {user?.name}
171
+ </span>
172
+ </DropdownMenuTrigger>
173
+ <DropdownMenuContent align="end" sideOffset={8} className="w-68">
174
+ <div className="flex items-center gap-3 px-2 py-2.5">
175
+ <Avatar className="size-10">
176
+ <AvatarImage src={avatarSrc(user)} />
177
+ <AvatarFallback className="bg-primary/12 text-primary text-xs font-semibold">
178
+ {fallback}
179
+ </AvatarFallback>
180
+ </Avatar>
181
+ <div className="min-w-0">
182
+ <div className="flex h-5 min-w-0 items-center gap-1.5">
183
+ <p className="truncate text-[13px] leading-5 font-semibold">
184
+ {user?.name}
185
+ </p>
186
+ {user?.role === "admin" ? (
187
+ <Badge
188
+ variant="outline"
189
+ className="h-4.5 px-1.5 text-[0.625rem]"
190
+ >
191
+ Admin
192
+ </Badge>
193
+ ) : null}
194
+ </div>
195
+ <p className="text-muted-foreground mt-0.5 truncate text-xs leading-4">
196
+ {mail.mailbox?.address}
197
+ </p>
198
+ </div>
199
+ </div>
200
+ <DropdownMenuSeparator />
201
+ <AppearanceMenuRow />
202
+ <DropdownMenuSeparator />
203
+ <DropdownMenuItem onClick={mail.openSettings}>
204
+ <Settings />
205
+ Settings
206
+ </DropdownMenuItem>
207
+ {Boolean(user?.permissions.length) && (
208
+ <DropdownMenuItem onClick={mail.openAdministration}>
209
+ <ShieldCheck />
210
+ Administration
211
+ </DropdownMenuItem>
212
+ )}
213
+ <DropdownMenuSeparator />
214
+ <DropdownMenuItem
215
+ variant="destructive"
216
+ onClick={() => void auth.logout()}
217
+ >
218
+ <LogOut />
219
+ Sign out
220
+ </DropdownMenuItem>
221
+ </DropdownMenuContent>
222
+ </DropdownMenu>
223
+ );
224
+ }
225
+
226
+ /**
227
+ * Top app bar on the canvas: brand aligned over the navigation pane, central
228
+ * search, account. Compose lives in the navigation pane (and the mobile dock);
229
+ * where you are (folder, mailbox) heads the conversation list. Below xl the
230
+ * brand is the workspace's logo and the app's name, still the app switcher.
231
+ */
232
+ export function AppBar({ mail }: { mail: MailController }) {
233
+ return (
234
+ <header className="grid h-12 shrink-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2 px-1 md:grid-cols-[auto_minmax(0,1fr)_auto] lg:gap-3 lg:px-0 xl:grid-cols-[15rem_minmax(0,1fr)_15rem]">
235
+ <div className="flex min-w-0 items-center lg:pl-3.5 xl:pl-2.5">
236
+ <CompactAppSwitcher className="xl:hidden" />
237
+ <span className="hidden min-w-0 xl:flex">
238
+ <ProductMark />
239
+ </span>
240
+ </div>
241
+
242
+ <SearchField
243
+ mail={mail}
244
+ shortcut
245
+ className="mx-auto hidden h-9 w-full max-w-2xl md:flex"
246
+ />
247
+
248
+ <div className="flex items-center justify-end md:col-start-3">
249
+ <AccountMenu mail={mail} />
250
+ </div>
251
+ </header>
252
+ );
253
+ }
@@ -0,0 +1,12 @@
1
+ import { MailboxRealtimeConnections } from "./mailbox-realtime";
2
+ import { UnreadDocumentIndicator } from "./unread-document-indicator";
3
+
4
+ /** Mounted while someone is signed in: realtime updates and the unread count in the tab. */
5
+ export function MailBackground() {
6
+ return (
7
+ <>
8
+ <MailboxRealtimeConnections />
9
+ <UnreadDocumentIndicator />
10
+ </>
11
+ );
12
+ }
@@ -0,0 +1,137 @@
1
+ import {
2
+ Tooltip,
3
+ TooltipContent,
4
+ TooltipTrigger,
5
+ useActiveInView,
6
+ useEdgeFade,
7
+ cn,
8
+ } from "@open-workspace/core/ui";
9
+ import { FolderCog, PenLine } from "lucide-react";
10
+ import { useRef } from "react";
11
+
12
+ import { FolderGlyph } from "./folder-glyph";
13
+ import { orderedFolders, unreadOf } from "./mail-folders";
14
+ import { DockMailboxSwitcher } from "./mail-mailbox-sheet";
15
+ import type { MailController } from "./use-mail-controller";
16
+
17
+ /**
18
+ * Mobile bottom dock, read left to right: the mailbox (when there are
19
+ * several to switch between), then every folder of it in one scrolling row
20
+ * with a gear for folder settings at its end, and compose beside it.
21
+ */
22
+ export function MobileDock({
23
+ mail,
24
+ onManageFolders,
25
+ }: {
26
+ mail: MailController;
27
+ onManageFolders: () => void;
28
+ }) {
29
+ const folders = orderedFolders(mail.folders ?? []);
30
+ const scroller = useRef<HTMLDivElement>(null);
31
+ const fade = useEdgeFade(scroller);
32
+ useActiveInView(scroller, `${mail.folder} ${folders.length}`);
33
+
34
+ const tabClass =
35
+ "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
+
37
+ 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">
39
+ <nav
40
+ aria-label="Mailbox and folders"
41
+ 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)]"
42
+ >
43
+ {mail.mailboxes.length > 1 && (
44
+ <div className="flex shrink-0 items-center py-1 pl-1">
45
+ <DockMailboxSwitcher mail={mail} />
46
+ <span aria-hidden="true" className="bg-border ml-1 h-7 w-px" />
47
+ </div>
48
+ )}
49
+ <div
50
+ ref={scroller}
51
+ data-dock-scroller
52
+ style={fade}
53
+ className="relative flex min-w-0 flex-1 snap-x snap-proximity scroll-px-5 [scrollbar-width:none] items-center gap-0.5 overflow-x-auto overscroll-x-contain p-1 [&::-webkit-scrollbar]:hidden"
54
+ >
55
+ {folders.map((item) => {
56
+ const active = item.id === mail.folder;
57
+ const unread = unreadOf(item);
58
+
59
+ return (
60
+ <button
61
+ key={item.id}
62
+ type="button"
63
+ data-active={active || undefined}
64
+ aria-current={active ? "page" : undefined}
65
+ aria-label={`${item.name}${unread ? `, ${unread} unread` : ""}`}
66
+ title={item.kind === "custom" ? item.name : undefined}
67
+ onClick={() => mail.selectFolder(item.id)}
68
+ className={cn(
69
+ tabClass,
70
+ // System folders sit at one width; a long name of your own truncates.
71
+ item.kind === "system" ? "w-16" : "max-w-28 min-w-16",
72
+ active
73
+ ? "bg-sidebar-accent text-sidebar-accent-foreground"
74
+ : "text-muted-foreground hover:text-foreground"
75
+ )}
76
+ >
77
+ <FolderGlyph
78
+ folder={item}
79
+ className={cn(
80
+ "size-[18px] shrink-0",
81
+ active && "text-sidebar-primary"
82
+ )}
83
+ strokeWidth={active ? 2.1 : 1.8}
84
+ />
85
+ <span className="max-w-full truncate">{item.name}</span>
86
+ {unread > 0 && (
87
+ <span
88
+ aria-hidden="true"
89
+ className="bg-primary text-primary-foreground absolute top-1 left-[calc(50%+4px)] min-w-4 rounded-full px-1 text-center text-[9px] leading-4 font-bold tabular-nums"
90
+ >
91
+ {unread > 99 ? "99+" : unread}
92
+ </span>
93
+ )}
94
+ </button>
95
+ );
96
+ })}
97
+ {folders.length > 0 && (
98
+ <>
99
+ <span
100
+ aria-hidden="true"
101
+ className="bg-border mx-0.5 h-7 w-px shrink-0"
102
+ />
103
+ <Tooltip>
104
+ <TooltipTrigger
105
+ render={
106
+ <button
107
+ type="button"
108
+ aria-haspopup="dialog"
109
+ aria-label="Manage folders and AI sorting"
110
+ onClick={onManageFolders}
111
+ className={cn(
112
+ tabClass,
113
+ "text-muted-foreground hover:text-foreground w-11"
114
+ )}
115
+ />
116
+ }
117
+ >
118
+ <FolderCog className="size-[18px]" strokeWidth={1.8} />
119
+ </TooltipTrigger>
120
+ <TooltipContent>Manage folders</TooltipContent>
121
+ </Tooltip>
122
+ </>
123
+ )}
124
+ </div>
125
+ </nav>
126
+ <button
127
+ type="button"
128
+ aria-label="New message"
129
+ disabled={!mail.mailbox?.canSend}
130
+ onClick={mail.openCompose}
131
+ 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"
132
+ >
133
+ <PenLine className="size-5" />
134
+ </button>
135
+ </div>
136
+ );
137
+ }
@@ -0,0 +1,44 @@
1
+ import { sortFolders } from "../../shared/folder-order";
2
+ import type { Folder, MailFolder } from "./types";
3
+
4
+ const systemFolderLabels = new Map([
5
+ ["inbox", "Inbox"],
6
+ ["sent", "Sent"],
7
+ ["archive", "Archive"],
8
+ ["spam", "Spam"],
9
+ ["trash", "Trash"],
10
+ ]);
11
+
12
+ export function folderDisplayName(folder: Folder, folders?: MailFolder[]) {
13
+ return (
14
+ folders?.find((item) => item.id === folder)?.name ??
15
+ systemFolderLabels.get(folder) ??
16
+ folder
17
+ );
18
+ }
19
+
20
+ export function folderShowsUnreadCount(folder: MailFolder | undefined) {
21
+ return folder?.kind === "custom" || folder?.systemType === "inbox";
22
+ }
23
+
24
+ /** The unread count a folder shows: Inbox and custom folders only. */
25
+ export function unreadOf(folder: MailFolder) {
26
+ return folderShowsUnreadCount(folder) ? folder.unreadCount : 0;
27
+ }
28
+
29
+ /**
30
+ * Every folder in the mailbox's one order, as the sidebar, rail, dock and
31
+ * folder pickers list them: Inbox first, then system and custom folders
32
+ * wherever they were placed.
33
+ */
34
+ export function orderedFolders(folders: readonly MailFolder[]) {
35
+ return sortFolders(folders);
36
+ }
37
+
38
+ /** Where switching to another mailbox lands: the same folder if it has one, otherwise Inbox. */
39
+ export function folderAfterMailboxSwitch(
40
+ folder: Folder,
41
+ targetFolders: MailFolder[] | undefined
42
+ ): Folder {
43
+ return targetFolders?.some((item) => item.id === folder) ? folder : "inbox";
44
+ }
@@ -0,0 +1,236 @@
1
+ /* Mail workspace layout: solid panes on a tinted canvas, dense conversation rows. */
2
+
3
+ /* Conversation table. */
4
+ :root {
5
+ --rule: oklch(0.935 0.005 262);
6
+ --row-hover: oklch(0.975 0.005 262);
7
+ --row-active: oklch(0.955 0.02 268);
8
+ --row-selected: oklch(0.945 0.03 268);
9
+ --pane-shadow:
10
+ 0 1px 2px oklch(0.25 0.04 266 / 0.05),
11
+ 0 0 0 0.5px oklch(0.25 0.04 266 / 0.03);
12
+ }
13
+
14
+ .dark {
15
+ --rule: oklch(1 0 0 / 0.055);
16
+ --row-hover: oklch(1 0 0 / 0.035);
17
+ --row-active: oklch(0.25 0.025 268);
18
+ --row-selected: oklch(0.27 0.04 268);
19
+ --pane-shadow: 0 1px 2px oklch(0 0 0 / 0.35);
20
+ }
21
+
22
+ /* Each region is a solid card on the tinted canvas. */
23
+ .mail-pane {
24
+ background: var(--surface);
25
+ border: 1px solid var(--border);
26
+ border-radius: 0.875rem;
27
+ box-shadow: var(--pane-shadow);
28
+ }
29
+
30
+ /* Initials tiles tinted by a per-name hue (set inline as --monogram-hue). */
31
+ .monogram {
32
+ background: oklch(0.93 0.04 var(--monogram-hue));
33
+ color: oklch(0.4 0.1 var(--monogram-hue));
34
+ }
35
+ .dark .monogram {
36
+ background: oklch(0.32 0.05 var(--monogram-hue));
37
+ color: oklch(0.9 0.05 var(--monogram-hue));
38
+ }
39
+
40
+ /* Conversation rows: two lines in a narrow pane, one dense line when wide. */
41
+ .mail-row {
42
+ display: grid;
43
+ grid-template-columns: 2rem minmax(0, 1fr) auto;
44
+ grid-template-areas:
45
+ "check from date"
46
+ "check subject subject";
47
+ column-gap: 0.5rem;
48
+ row-gap: 0.125rem;
49
+ align-items: center;
50
+ padding: 0.5rem 0.75rem 0.5625rem 0.375rem;
51
+ }
52
+
53
+ .mail-columns {
54
+ display: grid;
55
+ grid-template-columns: 2rem minmax(0, 1fr) auto;
56
+ grid-template-areas: "check from date";
57
+ column-gap: 0.5rem;
58
+ align-items: center;
59
+ padding: 0 0.75rem 0 0.375rem;
60
+ }
61
+
62
+ .mail-columns [data-col="subject"] {
63
+ display: none;
64
+ }
65
+
66
+ @container mail-list (min-width: 36rem) {
67
+ .mail-row,
68
+ .mail-columns {
69
+ grid-template-columns: 2rem minmax(0, 9.5rem) minmax(0, 1fr) 4.5rem;
70
+ grid-template-areas: "check from subject date";
71
+ column-gap: 0.75rem;
72
+ }
73
+ .mail-row {
74
+ padding-block: 0;
75
+ min-height: 2.375rem;
76
+ }
77
+ .mail-columns [data-col="subject"] {
78
+ display: block;
79
+ }
80
+ .mail-columns [data-col="from-narrow"] {
81
+ display: none;
82
+ }
83
+ }
84
+
85
+ @container mail-list (max-width: calc(36rem - 0.02px)) {
86
+ .mail-columns [data-col="from-wide"] {
87
+ display: none;
88
+ }
89
+ }
90
+
91
+ /* Phones list conversations without the column headings. */
92
+ @media (width < 64rem) {
93
+ .mail-columns {
94
+ display: none;
95
+ }
96
+ }
97
+
98
+ /* Narrow rows give the preview its own line; wide rows run it after the subject. */
99
+ .mail-subject {
100
+ white-space: normal;
101
+ overflow: visible;
102
+ }
103
+ .mail-subject > span {
104
+ display: block;
105
+ overflow: hidden;
106
+ text-overflow: ellipsis;
107
+ white-space: nowrap;
108
+ }
109
+ .mail-dash {
110
+ display: none;
111
+ }
112
+
113
+ @container mail-list (min-width: 36rem) {
114
+ .mail-subject {
115
+ overflow: hidden;
116
+ text-overflow: ellipsis;
117
+ white-space: nowrap;
118
+ }
119
+ .mail-subject > span {
120
+ display: inline;
121
+ }
122
+ .mail-dash {
123
+ display: inline;
124
+ }
125
+ }
126
+
127
+ /* Attachment type badges share the monogram treatment, tinted per file kind. */
128
+ .file-tile-icon {
129
+ background: oklch(0.95 0.035 var(--file-hue));
130
+ color: oklch(0.5 0.13 var(--file-hue));
131
+ }
132
+ .dark .file-tile-icon {
133
+ background: oklch(0.3 0.05 var(--file-hue));
134
+ color: oklch(0.85 0.09 var(--file-hue));
135
+ }
136
+
137
+ /* Tiptap's default gap cursor is black, so theme it for the dark composer. */
138
+ .ProseMirror-gapcursor::after {
139
+ border-top-color: var(--primary);
140
+ }
141
+
142
+ /*
143
+ Outgoing composer HTML lives in the app document after a strict allowlist
144
+ sanitizer. These rules restore editor semantics without accepting inline CSS.
145
+ */
146
+ .composer-message-body {
147
+ overflow-wrap: anywhere;
148
+
149
+ p {
150
+ margin: 0;
151
+ }
152
+
153
+ p + p {
154
+ margin-top: 0.75rem;
155
+ }
156
+
157
+ ul,
158
+ ol {
159
+ margin: 0.5rem 0;
160
+ padding-left: 1.5rem;
161
+ }
162
+
163
+ ul {
164
+ list-style: disc;
165
+ }
166
+
167
+ ol {
168
+ list-style: decimal;
169
+ }
170
+
171
+ blockquote {
172
+ margin: 0.75rem 0;
173
+ border-left: 2px solid color-mix(in oklab, currentColor 20%, transparent);
174
+ padding-left: 0.75rem;
175
+ color: color-mix(in oklab, currentColor 68%, transparent);
176
+ }
177
+
178
+ a {
179
+ color: var(--info);
180
+ text-decoration: underline;
181
+ text-underline-offset: 2px;
182
+ }
183
+
184
+ img {
185
+ display: block;
186
+ width: auto;
187
+ max-width: 100%;
188
+ max-height: 24rem;
189
+ margin: 0.75rem 0;
190
+ object-fit: contain;
191
+ border-radius: var(--radius);
192
+ }
193
+
194
+ pre {
195
+ max-width: 100%;
196
+ overflow: auto;
197
+ white-space: pre-wrap;
198
+ }
199
+
200
+ [data-linked-attachment-card] {
201
+ margin: 0.75rem 0;
202
+ border-block: 1px solid color-mix(in oklab, currentColor 14%, transparent);
203
+ padding: 0.625rem 0;
204
+ }
205
+
206
+ [data-linked-attachment-card] > a {
207
+ display: flex;
208
+ max-width: 100%;
209
+ flex-wrap: wrap;
210
+ align-items: baseline;
211
+ gap: 0.25rem 0.5rem;
212
+ color: inherit;
213
+ text-decoration: none;
214
+ }
215
+
216
+ [data-linked-attachment-card] strong {
217
+ min-width: 0;
218
+ overflow-wrap: anywhere;
219
+ }
220
+
221
+ [data-linked-attachment-card] span {
222
+ color: color-mix(in oklab, currentColor 60%, transparent);
223
+ font-size: 0.75rem;
224
+ }
225
+
226
+ [data-forwarded-message] {
227
+ display: block;
228
+ margin-top: 1rem;
229
+ border-top: 1px solid color-mix(in oklab, currentColor 14%, transparent);
230
+ padding-top: 0.75rem;
231
+ }
232
+ }
233
+
234
+ .mail-body {
235
+ overflow-wrap: anywhere;
236
+ }