@open-workspace/email 0.3.0 → 0.4.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.
- package/README.md +22 -22
- package/alchemy/index.ts +273 -0
- package/drizzle/mailbox/0000_puzzling_dracula.sql +149 -0
- package/drizzle/mailbox/0001_mute_jack_flag.sql +12 -0
- package/drizzle/mailbox/meta/0000_snapshot.json +1002 -0
- package/drizzle/mailbox/meta/0001_snapshot.json +1002 -0
- package/drizzle/mailbox/meta/_journal.json +20 -0
- package/drizzle/mailbox/migrations.js +12 -0
- package/index.ts +3 -1
- package/migrations/{0000_email.sql → 0000_dry_moon_knight.sql} +26 -20
- package/migrations/meta/0000_snapshot.json +125 -109
- package/migrations/meta/_journal.json +2 -2
- package/package.json +74 -68
- package/shared/attachment-preview.ts +37 -27
- package/shared/folder-order.ts +106 -0
- package/shared/mail-authentication.ts +8 -3
- package/shared/mail-feedback.ts +18 -25
- package/shared/mail-headers.ts +114 -39
- package/shared/mail-import.ts +38 -0
- package/shared/mail-path.ts +42 -0
- package/shared/mail-received.ts +174 -31
- package/shared/mail-remote.ts +59 -2
- package/shared/mail-sender-intel.ts +22 -4
- package/shared/mail.ts +77 -28
- package/shared/module.ts +33 -0
- package/shared/office-preview.ts +14 -2
- package/shared/pdfjs-assets.ts +35 -0
- package/shared/permissions.ts +73 -0
- package/shared/webhooks.ts +41 -0
- package/src/admin/blocked-senders.tsx +189 -0
- package/src/client.tsx +97 -0
- package/src/lib/mail-api.ts +9 -0
- package/src/mail/attachment-preview-dialog.tsx +161 -0
- package/src/mail/blocked-senders.tsx +138 -0
- package/src/mail/compose-window-chrome.tsx +194 -0
- package/src/mail/compose-window.tsx +486 -0
- package/src/mail/composer-asset-bookmarks.ts +409 -0
- package/src/mail/composer-asset.tsx +229 -0
- package/src/mail/composer-attachment-list.tsx +138 -0
- package/src/mail/composer-editor-document.ts +65 -0
- package/src/mail/composer-editor.tsx +284 -0
- package/src/mail/composer-linked-attachment-text.ts +12 -0
- package/src/mail/composer-recipient-fields.tsx +165 -0
- package/src/mail/composer-recipients.ts +208 -0
- package/src/mail/composer-session.ts +562 -0
- package/src/mail/composer-toolbar.tsx +303 -0
- package/src/mail/composer-upload-client.ts +105 -0
- package/src/mail/composer-upload-progress.ts +53 -0
- package/src/mail/conversation-list.tsx +550 -0
- package/src/mail/conversation-loading-skeleton.tsx +119 -0
- package/src/mail/conversation-message.tsx +346 -0
- package/src/mail/conversation-reply.tsx +470 -0
- package/src/mail/conversation-selection-toolbar.tsx +322 -0
- package/src/mail/conversation-view.tsx +437 -0
- package/src/mail/delivery-indicator.tsx +272 -0
- package/src/mail/email-html-body.tsx +203 -0
- package/src/mail/folder-glyph.tsx +46 -0
- package/src/mail/folder-manager.tsx +532 -0
- package/src/mail/format-bytes.ts +7 -0
- package/src/mail/mail-app-bar.tsx +253 -0
- package/src/mail/mail-background.tsx +12 -0
- package/src/mail/mail-dock.tsx +137 -0
- package/src/mail/mail-folders.ts +44 -0
- package/src/mail/mail-layout.css +236 -0
- package/src/mail/mail-location.ts +73 -0
- package/src/mail/mail-mailbox-sheet.tsx +275 -0
- package/src/mail/mail-nav-rail.tsx +129 -0
- package/src/mail/mail-nav.tsx +324 -0
- package/src/mail/mail-prefetch.ts +59 -0
- package/src/mail/mail-primitives.tsx +66 -0
- package/src/mail/mail-queries.ts +209 -0
- package/src/mail/mail-query-cache.ts +486 -0
- package/src/mail/mail-seed.ts +47 -0
- package/src/mail/mail-shell.tsx +126 -0
- package/src/mail/mailbox-ai-settings.tsx +185 -0
- package/src/mail/mailbox-realtime.tsx +251 -0
- package/src/mail/mailbox-route.tsx +15 -0
- package/src/mail/message-actions.tsx +353 -0
- package/src/mail/message-attachments.tsx +200 -0
- package/src/mail/message-format.ts +75 -0
- package/src/mail/message-header.tsx +260 -0
- package/src/mail/message-translation.tsx +225 -0
- package/src/mail/original-message-sheet.tsx +619 -0
- package/src/mail/original-message.ts +191 -0
- package/src/mail/outbound-notification.ts +53 -0
- package/src/mail/pane-splitter.tsx +117 -0
- package/src/mail/pdf-preview-toolbar.tsx +152 -0
- package/src/mail/pdf-preview.css +44 -0
- package/src/mail/pdf-preview.tsx +156 -0
- package/src/mail/pdf-translation-layout.ts +95 -0
- package/src/mail/print-message.ts +92 -0
- package/src/mail/reader-pane.tsx +535 -0
- package/src/mail/recipient-combobox.tsx +335 -0
- package/src/mail/recipient-field-row.tsx +34 -0
- package/src/mail/reply-to-warning.tsx +50 -0
- package/src/mail/sanitize-email-html.ts +430 -0
- package/src/mail/sender-actions.tsx +149 -0
- package/src/mail/sender-authentication.tsx +485 -0
- package/src/mail/sender-dialogs.tsx +384 -0
- package/src/mail/sender-security.tsx +545 -0
- package/src/mail/toolbar-tooltip.tsx +29 -0
- package/src/mail/translation-html.ts +49 -0
- package/src/mail/translation-language.ts +21 -0
- package/src/mail/types.ts +53 -0
- package/src/mail/unread-document-indicator.tsx +60 -0
- package/src/mail/use-compose-submission.ts +208 -0
- package/src/mail/use-composer-attachment-preflight.ts +184 -0
- package/src/mail/use-composer-submission.ts +117 -0
- package/src/mail/use-conversation-selection.ts +186 -0
- package/src/mail/use-mail-controller.ts +427 -0
- package/src/mail/use-mail-data.ts +279 -0
- package/src/mail/use-mail-safety.ts +155 -0
- package/src/mail/use-mail-send.ts +142 -0
- package/src/mail/use-pdf-translation-overlay.ts +156 -0
- package/src/mail/use-pdf-translation.ts +100 -0
- package/src/mail/use-pdf-viewer.ts +215 -0
- package/src/mail/use-reply-submission.ts +114 -0
- package/src/mail/use-sanitized-email-html.ts +20 -0
- package/src/mail/use-visible-message-read.ts +138 -0
- package/src/pwa/push-subscription.ts +151 -0
- package/src/settings/mail-apps-page.tsx +235 -0
- package/src/settings/notifications-page.tsx +291 -0
- package/worker/admin/blocked-sender-routes.ts +166 -0
- package/worker/admin/schemas.ts +11 -0
- package/worker/bindings.d.ts +14 -10
- package/worker/db/schema.ts +63 -40
- package/worker/jmap/eventsource.ts +84 -16
- package/worker/jmap/methods.ts +1630 -524
- package/worker/jmap/push-types.ts +27 -0
- package/worker/jmap/push.ts +140 -56
- package/worker/jmap/routes.ts +366 -105
- package/worker/mail/access.ts +258 -21
- package/worker/mail/ai-classification.ts +36 -20
- package/worker/mail/ai-translation.ts +13 -6
- package/worker/mail/auth-headers.ts +395 -137
- package/worker/mail/bimi.ts +200 -73
- package/worker/mail/bootstrap.ts +79 -0
- package/worker/mail/capped-body.ts +36 -0
- package/worker/mail/classification-signals.ts +35 -25
- package/worker/mail/conversation-cursor.ts +30 -19
- package/worker/mail/delivery-events.ts +88 -62
- package/worker/mail/delivery-facts.ts +46 -10
- package/worker/mail/demo-routes.ts +34 -10
- package/worker/mail/doh.ts +62 -23
- package/worker/mail/downloads.ts +75 -40
- package/worker/mail/edge-cache.ts +155 -0
- package/worker/mail/header-metadata.ts +88 -22
- package/worker/mail/impersonation.ts +160 -38
- package/worker/mail/import-routes.ts +313 -0
- package/worker/mail/inbound-delivery.ts +19 -9
- package/worker/mail/inbound-threading.ts +18 -8
- package/worker/mail/inbound.ts +82 -40
- package/worker/mail/ip-intel.ts +110 -27
- package/worker/mail/isolate-cache.ts +35 -0
- package/worker/mail/link-domains.ts +29 -7
- package/worker/mail/mailbox-deletion.ts +10 -4
- package/worker/mail/mailbox-directory.ts +16 -6
- package/worker/mail/mailing-list.ts +94 -39
- package/worker/mail/message-security.ts +90 -15
- package/worker/mail/message-view.ts +18 -6
- package/worker/mail/office-conversion.ts +31 -9
- package/worker/mail/office-preview-container.ts +40 -13
- package/worker/mail/office-preview-queue.ts +76 -32
- package/worker/mail/org-domain.ts +8 -1
- package/worker/mail/outbound-content.ts +71 -26
- package/worker/mail/outbound-delivery.ts +31 -17
- package/worker/mail/outbound-service.ts +48 -30
- package/worker/mail/outbound-threading.ts +30 -17
- package/worker/mail/outbound.ts +97 -70
- package/worker/mail/outgoing-context.ts +25 -15
- package/worker/mail/participants.ts +44 -29
- package/worker/mail/push-notifications.ts +271 -173
- package/worker/mail/quote-parser.ts +21 -10
- package/worker/mail/r2-presigned-urls.ts +31 -25
- package/worker/mail/receive.ts +23 -11
- package/worker/mail/recipients.ts +6 -1
- package/worker/mail/remote-proxy.ts +187 -31
- package/worker/mail/remote-routes.ts +87 -0
- package/worker/mail/remote-token.ts +104 -0
- package/worker/mail/repeat.ts +19 -0
- package/worker/mail/reply-plan.ts +62 -33
- package/worker/mail/rfc.ts +32 -7
- package/worker/mail/routes.ts +870 -541
- package/worker/mail/safety-routes.ts +328 -200
- package/worker/mail/schemas.ts +84 -105
- package/worker/mail/search.ts +1 -0
- package/worker/mail/security-settings.ts +41 -9
- package/worker/mail/sender-intel.ts +206 -51
- package/worker/mail/spamhaus.ts +92 -45
- package/worker/mail/unsubscribe.ts +76 -18
- package/worker/mail/uploads.ts +126 -93
- package/worker/mail/webhook-source.ts +35 -12
- package/worker/mail/workspace-safety.ts +97 -38
- package/worker/mailbox/demo-html.ts +7 -7
- package/worker/mailbox/demo-seed.ts +10 -44
- package/worker/mailbox/demo.ts +595 -225
- package/worker/mailbox/email-index.ts +53 -0
- package/worker/mailbox/folder-model.ts +53 -17
- package/worker/mailbox/import-placement.ts +88 -0
- package/worker/mailbox/inbox-counts.ts +106 -0
- package/worker/mailbox/index.ts +1734 -721
- package/worker/mailbox/jmap-store.ts +139 -35
- package/worker/mailbox/model.ts +8 -6
- package/worker/mailbox/office-preview-jobs.ts +56 -25
- package/worker/mailbox/schema.ts +87 -66
- package/worker/mailbox/senders.ts +176 -70
- package/worker/mcp/mail-action-tools.ts +128 -87
- package/worker/mcp/mail-compose-tools.ts +133 -82
- package/worker/mcp/mail-query-tools.ts +120 -71
- package/worker/mcp/mail-safety-tools.ts +321 -248
- package/worker/mcp/schemas.ts +43 -0
- package/worker/mcp/tools.ts +13 -10
- package/worker/module.ts +43 -18
- package/worker/sql.d.ts +8 -0
- package/alchemy.ts +0 -142
- package/containers/office-preview/Dockerfile +0 -10
- package/shared/mail-rules.ts +0 -156
- package/worker/admin/report-routes.ts +0 -164
- package/worker/mail/reported-messages.ts +0 -68
- package/worker/mailbox/migrations.ts +0 -10
- package/worker/mailbox/rules.ts +0 -110
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
Checkbox,
|
|
4
|
+
Skeleton,
|
|
5
|
+
ToggleGroup,
|
|
6
|
+
ToggleGroupItem,
|
|
7
|
+
TooltipProvider,
|
|
8
|
+
cn,
|
|
9
|
+
} from "@open-workspace/core/ui";
|
|
10
|
+
import { format, isThisYear, isToday, isYesterday } from "date-fns";
|
|
11
|
+
import {
|
|
12
|
+
CircleAlert,
|
|
13
|
+
ListChecks,
|
|
14
|
+
LoaderCircle,
|
|
15
|
+
MailOpen,
|
|
16
|
+
RotateCw,
|
|
17
|
+
SearchX,
|
|
18
|
+
} from "lucide-react";
|
|
19
|
+
import { useEffect, useRef } from "react";
|
|
20
|
+
import type { ReactNode } from "react";
|
|
21
|
+
|
|
22
|
+
import { ConversationSelectionToolbar } from "./conversation-selection-toolbar";
|
|
23
|
+
import { SearchField } from "./mail-app-bar";
|
|
24
|
+
import { folderShowsUnreadCount } from "./mail-folders";
|
|
25
|
+
import { MailboxCaption } from "./mail-mailbox-sheet";
|
|
26
|
+
import { ToolbarTooltip } from "./toolbar-tooltip";
|
|
27
|
+
import type { ConversationSummary } from "./types";
|
|
28
|
+
import type { MailController } from "./use-mail-controller";
|
|
29
|
+
|
|
30
|
+
function listDate(value: string) {
|
|
31
|
+
const date = new Date(value);
|
|
32
|
+
|
|
33
|
+
if (isToday(date)) return format(date, "HH:mm");
|
|
34
|
+
|
|
35
|
+
if (isYesterday(date)) return "Yesterday";
|
|
36
|
+
|
|
37
|
+
if (isThisYear(date)) return format(date, "MMM d");
|
|
38
|
+
|
|
39
|
+
return format(date, "dd.MM.yy");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function SegmentedFilter({
|
|
43
|
+
unreadOnly,
|
|
44
|
+
onToggle,
|
|
45
|
+
}: {
|
|
46
|
+
unreadOnly: boolean;
|
|
47
|
+
onToggle: () => void;
|
|
48
|
+
}) {
|
|
49
|
+
return (
|
|
50
|
+
<ToggleGroup
|
|
51
|
+
aria-label="Filter conversations"
|
|
52
|
+
variant="segmented"
|
|
53
|
+
required
|
|
54
|
+
value={[unreadOnly ? "unread" : "all"]}
|
|
55
|
+
onValueChange={([value]) => {
|
|
56
|
+
if ((value === "unread") !== unreadOnly) onToggle();
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
<ToggleGroupItem value="all">All</ToggleGroupItem>
|
|
60
|
+
<ToggleGroupItem value="unread">Unread</ToggleGroupItem>
|
|
61
|
+
</ToggleGroup>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function StatePanel({
|
|
66
|
+
icon,
|
|
67
|
+
title,
|
|
68
|
+
description,
|
|
69
|
+
children,
|
|
70
|
+
}: {
|
|
71
|
+
icon: ReactNode;
|
|
72
|
+
title: string;
|
|
73
|
+
description?: string;
|
|
74
|
+
children?: ReactNode;
|
|
75
|
+
}) {
|
|
76
|
+
return (
|
|
77
|
+
<div className="grid place-items-center px-6 py-20 text-center">
|
|
78
|
+
<div className="animate-fade-in">
|
|
79
|
+
<span className="border-border bg-surface-sunken text-muted-foreground mx-auto grid size-10 place-items-center rounded-lg border [&_svg]:size-5">
|
|
80
|
+
{icon}
|
|
81
|
+
</span>
|
|
82
|
+
<p className="mt-3.5 text-[14px] font-semibold">{title}</p>
|
|
83
|
+
{description && (
|
|
84
|
+
<p className="text-muted-foreground mx-auto mt-1 max-w-xs text-[13px] leading-5">
|
|
85
|
+
{description}
|
|
86
|
+
</p>
|
|
87
|
+
)}
|
|
88
|
+
{children && <div className="mt-4">{children}</div>}
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** How long the pointer rests on a row before its conversation starts loading. */
|
|
95
|
+
const CONVERSATION_INTENT_MS = 80;
|
|
96
|
+
|
|
97
|
+
function ConversationRow({
|
|
98
|
+
conversation,
|
|
99
|
+
active,
|
|
100
|
+
selected,
|
|
101
|
+
selecting,
|
|
102
|
+
disabled,
|
|
103
|
+
onOpen,
|
|
104
|
+
onToggle,
|
|
105
|
+
onIntent,
|
|
106
|
+
}: {
|
|
107
|
+
conversation: ConversationSummary;
|
|
108
|
+
active: boolean;
|
|
109
|
+
selected: boolean;
|
|
110
|
+
selecting: boolean;
|
|
111
|
+
disabled: boolean;
|
|
112
|
+
onOpen: () => void;
|
|
113
|
+
onToggle: () => void;
|
|
114
|
+
/** The person is likely to open this row: `soon` after a short rest, at once on press; null when they moved on. */
|
|
115
|
+
onIntent: (when: "soon" | "now" | null) => void;
|
|
116
|
+
}) {
|
|
117
|
+
const unread = conversation.isUnread;
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<li
|
|
121
|
+
className={cn(
|
|
122
|
+
"mail-row group relative border-b border-(--rule) transition-colors duration-100",
|
|
123
|
+
"before:bg-primary before:absolute before:inset-y-0 before:left-0 before:w-[3px] before:opacity-0",
|
|
124
|
+
unread && "before:opacity-100",
|
|
125
|
+
selected
|
|
126
|
+
? "bg-(--row-selected)"
|
|
127
|
+
: active
|
|
128
|
+
? "bg-(--row-active)"
|
|
129
|
+
: "hover:bg-(--row-hover)",
|
|
130
|
+
active && "before:opacity-100"
|
|
131
|
+
)}
|
|
132
|
+
>
|
|
133
|
+
<button
|
|
134
|
+
type="button"
|
|
135
|
+
disabled={disabled}
|
|
136
|
+
aria-current={active ? "true" : undefined}
|
|
137
|
+
aria-label={
|
|
138
|
+
selecting
|
|
139
|
+
? `${selected ? "Deselect" : "Select"} ${conversation.subject}`
|
|
140
|
+
: `Open ${conversation.subject} from ${conversation.conversationLabel}`
|
|
141
|
+
}
|
|
142
|
+
onClick={selecting ? onToggle : onOpen}
|
|
143
|
+
onPointerEnter={selecting ? undefined : () => onIntent("soon")}
|
|
144
|
+
onPointerLeave={() => onIntent(null)}
|
|
145
|
+
onPointerDown={selecting ? undefined : () => onIntent("now")}
|
|
146
|
+
onFocus={selecting ? undefined : () => onIntent("soon")}
|
|
147
|
+
onBlur={() => onIntent(null)}
|
|
148
|
+
className="focus-visible:ring-ring absolute inset-0 z-0 outline-none focus-visible:ring-2 focus-visible:ring-inset"
|
|
149
|
+
/>
|
|
150
|
+
|
|
151
|
+
<span className="relative z-10 grid h-full place-items-center [grid-area:check]">
|
|
152
|
+
<Checkbox
|
|
153
|
+
aria-label={`Select ${conversation.subject}`}
|
|
154
|
+
checked={selected}
|
|
155
|
+
disabled={disabled}
|
|
156
|
+
onCheckedChange={onToggle}
|
|
157
|
+
className={cn(
|
|
158
|
+
"size-4 rounded-[4px] transition-opacity",
|
|
159
|
+
selecting || selected
|
|
160
|
+
? "opacity-100"
|
|
161
|
+
: "opacity-0 group-hover:opacity-100 focus-visible:opacity-100"
|
|
162
|
+
)}
|
|
163
|
+
/>
|
|
164
|
+
{unread && !selecting && !selected && (
|
|
165
|
+
<span
|
|
166
|
+
role="img"
|
|
167
|
+
aria-label={`${conversation.unreadCount} unread messages`}
|
|
168
|
+
className="bg-primary pointer-events-none absolute size-[7px] rounded-full group-hover:opacity-0 group-has-[:focus-visible]:opacity-0"
|
|
169
|
+
/>
|
|
170
|
+
)}
|
|
171
|
+
</span>
|
|
172
|
+
|
|
173
|
+
<span className="pointer-events-none flex min-w-0 items-center gap-1.5 [grid-area:from]">
|
|
174
|
+
{conversation.senderLogoUrl && (
|
|
175
|
+
<img
|
|
176
|
+
src={conversation.senderLogoUrl}
|
|
177
|
+
alt=""
|
|
178
|
+
aria-hidden="true"
|
|
179
|
+
draggable={false}
|
|
180
|
+
onError={(event) => {
|
|
181
|
+
event.currentTarget.hidden = true;
|
|
182
|
+
}}
|
|
183
|
+
className="ring-border size-4 shrink-0 rounded-full object-cover ring-1"
|
|
184
|
+
/>
|
|
185
|
+
)}
|
|
186
|
+
<span
|
|
187
|
+
className={cn(
|
|
188
|
+
"truncate text-[13px] leading-5",
|
|
189
|
+
unread
|
|
190
|
+
? "text-foreground font-semibold"
|
|
191
|
+
: "text-foreground/85 font-medium"
|
|
192
|
+
)}
|
|
193
|
+
>
|
|
194
|
+
{conversation.conversationLabel}
|
|
195
|
+
</span>
|
|
196
|
+
{conversation.messageCount > 1 && (
|
|
197
|
+
<span className="bg-foreground/[0.06] text-muted-foreground shrink-0 rounded-[4px] px-1 py-px text-[10.5px] font-semibold tabular-nums">
|
|
198
|
+
{conversation.messageCount}
|
|
199
|
+
</span>
|
|
200
|
+
)}
|
|
201
|
+
</span>
|
|
202
|
+
|
|
203
|
+
<span className="mail-subject pointer-events-none min-w-0 truncate text-[13px] leading-5 [grid-area:subject]">
|
|
204
|
+
<span
|
|
205
|
+
className={
|
|
206
|
+
unread ? "text-foreground font-semibold" : "text-foreground/90"
|
|
207
|
+
}
|
|
208
|
+
>
|
|
209
|
+
{conversation.subject || "(no subject)"}
|
|
210
|
+
</span>
|
|
211
|
+
<span className="mail-preview text-muted-foreground">
|
|
212
|
+
<span aria-hidden="true" className="mail-dash text-border px-1.5">
|
|
213
|
+
—
|
|
214
|
+
</span>
|
|
215
|
+
{conversation.preview || "No text preview"}
|
|
216
|
+
</span>
|
|
217
|
+
</span>
|
|
218
|
+
|
|
219
|
+
<time
|
|
220
|
+
dateTime={conversation.timelineAt}
|
|
221
|
+
className={cn(
|
|
222
|
+
"pointer-events-none text-right text-xs tabular-nums [grid-area:date]",
|
|
223
|
+
unread ? "text-primary font-semibold" : "text-muted-foreground"
|
|
224
|
+
)}
|
|
225
|
+
>
|
|
226
|
+
{listDate(conversation.timelineAt)}
|
|
227
|
+
</time>
|
|
228
|
+
</li>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** What an empty folder is for, so it reads as a place rather than a dead end. */
|
|
233
|
+
function emptyFolderHint(systemType: string | null | undefined) {
|
|
234
|
+
switch (systemType) {
|
|
235
|
+
case "sent": {
|
|
236
|
+
return "Messages you send from this mailbox appear here.";
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
case "archive": {
|
|
240
|
+
return "Archive conversations to clear them from the Inbox without deleting them.";
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
case "spam": {
|
|
244
|
+
return "Mail that looks like spam lands here instead of the Inbox.";
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
case "trash": {
|
|
248
|
+
return "Deleted conversations wait here until you delete them permanently.";
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
default: {
|
|
252
|
+
return "New conversations will appear here as soon as they arrive.";
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function ConversationList({ mail }: { mail: MailController }) {
|
|
258
|
+
const {
|
|
259
|
+
mailbox,
|
|
260
|
+
folder,
|
|
261
|
+
folders,
|
|
262
|
+
folderName,
|
|
263
|
+
activeFolder,
|
|
264
|
+
conversations,
|
|
265
|
+
conversationsQuery,
|
|
266
|
+
conversationId,
|
|
267
|
+
selection,
|
|
268
|
+
debouncedSearch,
|
|
269
|
+
unreadOnly,
|
|
270
|
+
displayedConversationCount,
|
|
271
|
+
} = mail;
|
|
272
|
+
|
|
273
|
+
const unreadInFolder =
|
|
274
|
+
!debouncedSearch && folderShowsUnreadCount(activeFolder)
|
|
275
|
+
? (activeFolder?.unreadCount ?? 0)
|
|
276
|
+
: 0;
|
|
277
|
+
|
|
278
|
+
const hasConversations = conversations.length > 0;
|
|
279
|
+
|
|
280
|
+
// Resting on a row (pointer or keyboard focus) starts loading it, so a
|
|
281
|
+
// click usually finds the conversation already there.
|
|
282
|
+
const intentTimer = useRef<ReturnType<typeof setTimeout> | undefined>(
|
|
283
|
+
undefined
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
useEffect(() => () => clearTimeout(intentTimer.current), []);
|
|
287
|
+
|
|
288
|
+
function intent(targetId: string, when: "soon" | "now" | null) {
|
|
289
|
+
clearTimeout(intentTimer.current);
|
|
290
|
+
|
|
291
|
+
if (when === "now") mail.prefetchConversation(targetId);
|
|
292
|
+
else if (when === "soon") {
|
|
293
|
+
intentTimer.current = setTimeout(
|
|
294
|
+
() => mail.prefetchConversation(targetId),
|
|
295
|
+
CONVERSATION_INTENT_MS
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const loadMore = conversationsQuery.hasNextPage ? (
|
|
301
|
+
<Button
|
|
302
|
+
variant="outline"
|
|
303
|
+
size="sm"
|
|
304
|
+
disabled={conversationsQuery.isFetchingNextPage}
|
|
305
|
+
onClick={() => void conversationsQuery.fetchNextPage()}
|
|
306
|
+
>
|
|
307
|
+
{conversationsQuery.isFetchingNextPage && (
|
|
308
|
+
<LoaderCircle className="animate-spin" />
|
|
309
|
+
)}
|
|
310
|
+
Load older conversations
|
|
311
|
+
</Button>
|
|
312
|
+
) : null;
|
|
313
|
+
|
|
314
|
+
let body: ReactNode;
|
|
315
|
+
|
|
316
|
+
if (mail.listLoading) {
|
|
317
|
+
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>
|
|
331
|
+
);
|
|
332
|
+
} else if (mail.listError) {
|
|
333
|
+
body = (
|
|
334
|
+
<StatePanel
|
|
335
|
+
icon={<CircleAlert />}
|
|
336
|
+
title="Could not load conversations"
|
|
337
|
+
description={mail.listError}
|
|
338
|
+
>
|
|
339
|
+
<Button variant="outline" size="sm" onClick={mail.retryList}>
|
|
340
|
+
<RotateCw /> Retry
|
|
341
|
+
</Button>
|
|
342
|
+
</StatePanel>
|
|
343
|
+
);
|
|
344
|
+
} else if (hasConversations) {
|
|
345
|
+
body = (
|
|
346
|
+
<>
|
|
347
|
+
<ul aria-label={`${folderName} conversations`}>
|
|
348
|
+
{conversations.map((item) => (
|
|
349
|
+
<ConversationRow
|
|
350
|
+
key={item.id}
|
|
351
|
+
conversation={item}
|
|
352
|
+
active={item.conversationId === conversationId}
|
|
353
|
+
selected={selection.selectedIds.has(item.conversationId)}
|
|
354
|
+
selecting={selection.active}
|
|
355
|
+
disabled={selection.pending}
|
|
356
|
+
onOpen={() => mail.openConversation(item.conversationId)}
|
|
357
|
+
onToggle={() => selection.toggle(item.conversationId)}
|
|
358
|
+
onIntent={(when) => intent(item.conversationId, when)}
|
|
359
|
+
/>
|
|
360
|
+
))}
|
|
361
|
+
</ul>
|
|
362
|
+
{loadMore && (
|
|
363
|
+
<div className="flex justify-center px-4 pt-4">{loadMore}</div>
|
|
364
|
+
)}
|
|
365
|
+
</>
|
|
366
|
+
);
|
|
367
|
+
} else {
|
|
368
|
+
body = (
|
|
369
|
+
<StatePanel
|
|
370
|
+
icon={debouncedSearch ? <SearchX /> : <MailOpen />}
|
|
371
|
+
title={
|
|
372
|
+
debouncedSearch
|
|
373
|
+
? `No${unreadOnly ? " unread" : ""} matches in ${folderName}`
|
|
374
|
+
: unreadOnly
|
|
375
|
+
? `No unread conversations in ${folderName}`
|
|
376
|
+
: `${folderName} is empty`
|
|
377
|
+
}
|
|
378
|
+
description={
|
|
379
|
+
debouncedSearch
|
|
380
|
+
? "Try a different name, address, subject, or phrase."
|
|
381
|
+
: unreadOnly
|
|
382
|
+
? "Everything here has been read."
|
|
383
|
+
: emptyFolderHint(activeFolder?.systemType)
|
|
384
|
+
}
|
|
385
|
+
>
|
|
386
|
+
{loadMore}
|
|
387
|
+
</StatePanel>
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return (
|
|
392
|
+
// oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- Escape anywhere in the list leaves selection mode
|
|
393
|
+
<div
|
|
394
|
+
className="flex min-h-0 flex-1 flex-col"
|
|
395
|
+
onKeyDown={(event) => {
|
|
396
|
+
if (selection.active && !selection.pending && event.key === "Escape") {
|
|
397
|
+
selection.exit();
|
|
398
|
+
}
|
|
399
|
+
}}
|
|
400
|
+
>
|
|
401
|
+
<div className="border-border @container/list-head shrink-0 border-b px-3.5 sm:px-4">
|
|
402
|
+
{/* Phones title the list with where you are, the mailbox over its folder; desktops name the folder in the row below. */}
|
|
403
|
+
<div className="min-w-0 pt-3 lg:hidden">
|
|
404
|
+
<MailboxCaption mail={mail} />
|
|
405
|
+
<h1 className="truncate text-[20px] leading-6 font-semibold tracking-[-0.02em]">
|
|
406
|
+
{folderName}
|
|
407
|
+
</h1>
|
|
408
|
+
</div>
|
|
409
|
+
<div className="flex h-12 items-center justify-between gap-3">
|
|
410
|
+
{selection.active && mailbox ? (
|
|
411
|
+
<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">
|
|
413
|
+
<ConversationSelectionToolbar
|
|
414
|
+
sharedMailboxName={
|
|
415
|
+
mailbox.kind === "shared" ? mailbox.displayName : undefined
|
|
416
|
+
}
|
|
417
|
+
canDeletePermanently={mailbox.canSend}
|
|
418
|
+
folder={folder}
|
|
419
|
+
folders={folders ?? []}
|
|
420
|
+
selectedCount={selection.selectedConversations.length}
|
|
421
|
+
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}
|
|
429
|
+
onToggleAll={selection.toggleAllLoaded}
|
|
430
|
+
onAction={selection.run}
|
|
431
|
+
onReport={selection.report}
|
|
432
|
+
onExit={selection.exit}
|
|
433
|
+
/>
|
|
434
|
+
</div>
|
|
435
|
+
</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 && " · "}
|
|
464
|
+
</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">
|
|
476
|
+
<SegmentedFilter
|
|
477
|
+
unreadOnly={unreadOnly}
|
|
478
|
+
onToggle={mail.toggleUnreadOnly}
|
|
479
|
+
/>
|
|
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>
|
|
498
|
+
<Button
|
|
499
|
+
variant="ghost"
|
|
500
|
+
size="sm"
|
|
501
|
+
className="h-7 px-2 text-xs"
|
|
502
|
+
disabled={selection.pending || !hasConversations}
|
|
503
|
+
onClick={selection.start}
|
|
504
|
+
>
|
|
505
|
+
<ListChecks /> Select
|
|
506
|
+
</Button>
|
|
507
|
+
</div>
|
|
508
|
+
</>
|
|
509
|
+
)}
|
|
510
|
+
</div>
|
|
511
|
+
<SearchField mail={mail} className="mb-2.5 h-9 md:hidden" />
|
|
512
|
+
</div>
|
|
513
|
+
|
|
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>
|
|
545
|
+
)}
|
|
546
|
+
{body}
|
|
547
|
+
</div>
|
|
548
|
+
</div>
|
|
549
|
+
);
|
|
550
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Skeleton } from "@open-workspace/core/ui";
|
|
2
|
+
import { format, isThisYear, isToday } from "date-fns";
|
|
3
|
+
|
|
4
|
+
import { messageTextClassName } from "./email-html-body";
|
|
5
|
+
import { SenderAvatar } from "./sender-security";
|
|
6
|
+
import type { ConversationSummary } from "./types";
|
|
7
|
+
|
|
8
|
+
function previewDate(value: string) {
|
|
9
|
+
const date = new Date(value);
|
|
10
|
+
|
|
11
|
+
if (isToday(date)) return format(date, "HH:mm");
|
|
12
|
+
|
|
13
|
+
if (isThisYear(date)) return format(date, "MMM d, HH:mm");
|
|
14
|
+
|
|
15
|
+
return format(date, "MMM d, yyyy");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* What the list already knows about a conversation that is loading: its
|
|
20
|
+
* subject, latest sender, date and text preview, laid out like the reader,
|
|
21
|
+
* with the body still to come.
|
|
22
|
+
*/
|
|
23
|
+
function ConversationPreview({ summary }: { summary: ConversationSummary }) {
|
|
24
|
+
const sender = summary.fromName || summary.fromAddress;
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<section
|
|
28
|
+
aria-label="Loading conversation"
|
|
29
|
+
aria-busy="true"
|
|
30
|
+
data-testid="conversation-preview"
|
|
31
|
+
className="mx-auto w-full max-w-[60rem] pb-10"
|
|
32
|
+
>
|
|
33
|
+
<header className="px-4 pt-5 pb-4 sm:px-6 sm:pt-6">
|
|
34
|
+
<h1 className="text-[1.3125rem] leading-[1.3] font-semibold tracking-[-0.018em] text-balance [overflow-wrap:anywhere]">
|
|
35
|
+
{summary.subject || "(no subject)"}
|
|
36
|
+
</h1>
|
|
37
|
+
{summary.messageCount > 1 && (
|
|
38
|
+
<p className="text-muted-foreground mt-1 text-xs">
|
|
39
|
+
{summary.messageCount} messages
|
|
40
|
+
</p>
|
|
41
|
+
)}
|
|
42
|
+
</header>
|
|
43
|
+
<div className="border-border border-y px-4 pt-4 pb-5 sm:px-6">
|
|
44
|
+
<div className="flex items-start gap-3">
|
|
45
|
+
<SenderAvatar
|
|
46
|
+
name={sender}
|
|
47
|
+
logoUrl={summary.senderLogoUrl}
|
|
48
|
+
className="mt-0.5 size-9 rounded-full text-[12px]"
|
|
49
|
+
/>
|
|
50
|
+
<div className="flex min-h-7 min-w-0 flex-1 items-center gap-2">
|
|
51
|
+
<span className="min-w-0 flex-1 truncate text-[13px] font-semibold">
|
|
52
|
+
{sender}
|
|
53
|
+
</span>
|
|
54
|
+
<time
|
|
55
|
+
dateTime={summary.timelineAt}
|
|
56
|
+
className="text-muted-foreground shrink-0 text-xs tabular-nums"
|
|
57
|
+
>
|
|
58
|
+
{previewDate(summary.timelineAt)}
|
|
59
|
+
</time>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
<div className="mt-4 min-w-0 @lg/reader:pl-12">
|
|
63
|
+
{summary.preview && (
|
|
64
|
+
<p className={`${messageTextClassName} text-muted-foreground`}>
|
|
65
|
+
{summary.preview}
|
|
66
|
+
</p>
|
|
67
|
+
)}
|
|
68
|
+
<div aria-hidden="true" className="mt-3 max-w-[72ch] space-y-2.5">
|
|
69
|
+
<Skeleton className="h-3.5 w-11/12" />
|
|
70
|
+
<Skeleton className="h-3.5 w-4/5" />
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
</section>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Mirrors the reader layout: subject, meta line, then a collapsed and an open message. */
|
|
79
|
+
export function ConversationLoadingSkeleton({
|
|
80
|
+
summary,
|
|
81
|
+
}: { summary?: ConversationSummary } = {}) {
|
|
82
|
+
if (summary) return <ConversationPreview summary={summary} />;
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<section
|
|
86
|
+
aria-label="Loading conversation"
|
|
87
|
+
aria-busy="true"
|
|
88
|
+
className="mx-auto w-full max-w-[60rem] pb-10"
|
|
89
|
+
>
|
|
90
|
+
<div className="px-4 pt-6 pb-4 sm:px-6">
|
|
91
|
+
<Skeleton className="h-6 w-3/5 max-w-md" />
|
|
92
|
+
<Skeleton className="mt-2.5 h-3 w-48" />
|
|
93
|
+
</div>
|
|
94
|
+
<div className="border-border border-y">
|
|
95
|
+
<div className="flex items-center gap-3 px-4 py-2.5 sm:px-6">
|
|
96
|
+
<Skeleton className="size-7 shrink-0 rounded-full" />
|
|
97
|
+
<Skeleton className="h-3 w-28" />
|
|
98
|
+
<Skeleton className="h-3 flex-1" />
|
|
99
|
+
<Skeleton className="h-3 w-12" />
|
|
100
|
+
</div>
|
|
101
|
+
<div className="border-border border-t px-4 pt-4 pb-6 sm:px-6">
|
|
102
|
+
<div className="flex items-start gap-3">
|
|
103
|
+
<Skeleton className="size-9 shrink-0 rounded-full" />
|
|
104
|
+
<div className="flex-1 pt-1">
|
|
105
|
+
<Skeleton className="h-3.5 w-40" />
|
|
106
|
+
<Skeleton className="mt-2 h-3 w-56" />
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
<div className="mt-5 max-w-[72ch] space-y-2.5 @lg/reader:pl-12">
|
|
110
|
+
<Skeleton className="h-3.5 w-11/12" />
|
|
111
|
+
<Skeleton className="h-3.5 w-full" />
|
|
112
|
+
<Skeleton className="h-3.5 w-4/5" />
|
|
113
|
+
<Skeleton className="h-3.5 w-2/5" />
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
</section>
|
|
118
|
+
);
|
|
119
|
+
}
|