@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.
- package/README.md +23 -20
- 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_dry_moon_knight.sql +77 -0
- package/migrations/meta/0000_snapshot.json +248 -106
- 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 +78 -26
- 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 +90 -34
- package/worker/jmap/eventsource.ts +169 -0
- package/worker/jmap/methods.ts +1716 -361
- package/worker/jmap/push-types.ts +27 -0
- package/worker/jmap/push.ts +207 -0
- package/worker/jmap/routes.ts +448 -86
- 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 +84 -52
- 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 +283 -171
- 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 +871 -542
- package/worker/mail/safety-routes.ts +329 -202
- 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 +153 -91
- 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 +597 -227
- 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 +1761 -737
- package/worker/mailbox/jmap-store.ts +139 -35
- package/worker/mailbox/model.ts +7 -14
- 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 -126
- package/containers/office-preview/Dockerfile +0 -10
- package/migrations/0000_email.sql +0 -53
- 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/legacy-migrations.ts +0 -41
- package/worker/mailbox/migrations.ts +0 -10
- package/worker/mailbox/rules.ts +0 -110
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AlertDialog,
|
|
3
|
+
AlertDialogAction,
|
|
4
|
+
AlertDialogCancel,
|
|
5
|
+
AlertDialogContent,
|
|
6
|
+
AlertDialogDescription,
|
|
7
|
+
AlertDialogFooter,
|
|
8
|
+
AlertDialogHeader,
|
|
9
|
+
AlertDialogTitle,
|
|
10
|
+
Button,
|
|
11
|
+
DropdownMenu,
|
|
12
|
+
DropdownMenuContent,
|
|
13
|
+
DropdownMenuGroup,
|
|
14
|
+
DropdownMenuItem,
|
|
15
|
+
DropdownMenuLabel,
|
|
16
|
+
DropdownMenuSeparator,
|
|
17
|
+
DropdownMenuTrigger,
|
|
18
|
+
TooltipProvider,
|
|
19
|
+
cn,
|
|
20
|
+
} from "@open-workspace/core/ui";
|
|
21
|
+
import {
|
|
22
|
+
Archive,
|
|
23
|
+
ArrowLeft,
|
|
24
|
+
ChevronDown,
|
|
25
|
+
ChevronUp,
|
|
26
|
+
Ellipsis,
|
|
27
|
+
FolderInput,
|
|
28
|
+
Inbox,
|
|
29
|
+
Mail,
|
|
30
|
+
MailOpen,
|
|
31
|
+
OctagonAlert,
|
|
32
|
+
ShieldBan,
|
|
33
|
+
ShieldCheck,
|
|
34
|
+
Trash2,
|
|
35
|
+
X,
|
|
36
|
+
} from "lucide-react";
|
|
37
|
+
import { useState } from "react";
|
|
38
|
+
import type { ReactNode } from "react";
|
|
39
|
+
|
|
40
|
+
import { ConversationView } from "./conversation-view";
|
|
41
|
+
import { folderShowsUnreadCount, orderedFolders } from "./mail-folders";
|
|
42
|
+
import { useSenderActions } from "./sender-actions";
|
|
43
|
+
import type { SenderActions } from "./sender-actions";
|
|
44
|
+
import { ToolbarTooltip } from "./toolbar-tooltip";
|
|
45
|
+
import type { MailController } from "./use-mail-controller";
|
|
46
|
+
import { useSenderIntelFill } from "./use-mail-data";
|
|
47
|
+
|
|
48
|
+
function CommandButton({
|
|
49
|
+
label,
|
|
50
|
+
shortLabel,
|
|
51
|
+
icon,
|
|
52
|
+
disabled,
|
|
53
|
+
destructive = false,
|
|
54
|
+
onClick,
|
|
55
|
+
}: {
|
|
56
|
+
label: string;
|
|
57
|
+
shortLabel: string;
|
|
58
|
+
icon: ReactNode;
|
|
59
|
+
disabled?: boolean;
|
|
60
|
+
destructive?: boolean;
|
|
61
|
+
onClick: () => void;
|
|
62
|
+
}) {
|
|
63
|
+
return (
|
|
64
|
+
<ToolbarTooltip label={label} side="bottom">
|
|
65
|
+
<Button
|
|
66
|
+
variant="ghost"
|
|
67
|
+
size="sm"
|
|
68
|
+
aria-label={label}
|
|
69
|
+
disabled={disabled}
|
|
70
|
+
onClick={onClick}
|
|
71
|
+
className={cn(
|
|
72
|
+
"text-foreground/80 h-8 gap-1.5 px-2 text-[13px] font-medium",
|
|
73
|
+
destructive && "hover:bg-destructive/10 hover:text-destructive"
|
|
74
|
+
)}
|
|
75
|
+
>
|
|
76
|
+
{icon}
|
|
77
|
+
<span className="hidden @lg/reader:inline">{shortLabel}</span>
|
|
78
|
+
</Button>
|
|
79
|
+
</ToolbarTooltip>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function MoveMenu({ mail }: { mail: MailController }) {
|
|
84
|
+
const { folder, folders, conversation } = mail;
|
|
85
|
+
|
|
86
|
+
// Where the conversation can move: Inbox (id null) and custom folders.
|
|
87
|
+
const targets: { id: string | null; name: string }[] = [
|
|
88
|
+
...(folder === "inbox" ? [] : [{ id: null, name: "Inbox" }]),
|
|
89
|
+
...orderedFolders(folders ?? []).flatMap((item) =>
|
|
90
|
+
item.kind === "custom" && item.id !== folder
|
|
91
|
+
? [{ id: item.id, name: item.name }]
|
|
92
|
+
: []
|
|
93
|
+
),
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
const disabled =
|
|
97
|
+
!conversation?.hasIncoming || mail.sharedActionPending || !targets.length;
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<DropdownMenu>
|
|
101
|
+
<ToolbarTooltip label="Move to folder" side="bottom">
|
|
102
|
+
<DropdownMenuTrigger
|
|
103
|
+
render={
|
|
104
|
+
<Button
|
|
105
|
+
variant="ghost"
|
|
106
|
+
size="sm"
|
|
107
|
+
aria-label="Move to folder"
|
|
108
|
+
disabled={disabled}
|
|
109
|
+
className="text-foreground/80 h-8 gap-1.5 px-2 text-[13px] font-medium"
|
|
110
|
+
/>
|
|
111
|
+
}
|
|
112
|
+
>
|
|
113
|
+
<FolderInput />
|
|
114
|
+
<span className="hidden @lg/reader:inline">Move</span>
|
|
115
|
+
<ChevronDown className="size-3 opacity-60" />
|
|
116
|
+
</DropdownMenuTrigger>
|
|
117
|
+
</ToolbarTooltip>
|
|
118
|
+
<DropdownMenuContent align="start" className="w-56">
|
|
119
|
+
<DropdownMenuGroup>
|
|
120
|
+
<DropdownMenuLabel>Move to</DropdownMenuLabel>
|
|
121
|
+
{targets.map((target) => (
|
|
122
|
+
<DropdownMenuItem
|
|
123
|
+
key={target.id ?? "inbox"}
|
|
124
|
+
onClick={() => mail.moveToFolder(target)}
|
|
125
|
+
>
|
|
126
|
+
{target.id ? <FolderInput /> : <Inbox />}
|
|
127
|
+
{target.name}
|
|
128
|
+
</DropdownMenuItem>
|
|
129
|
+
))}
|
|
130
|
+
</DropdownMenuGroup>
|
|
131
|
+
</DropdownMenuContent>
|
|
132
|
+
</DropdownMenu>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function latestIncoming(mail: MailController) {
|
|
137
|
+
return [...mail.conversationMessages]
|
|
138
|
+
.reverse()
|
|
139
|
+
.find((message) => message.direction === "incoming");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Less frequent actions, mirroring what the list's selection toolbar offers. */
|
|
143
|
+
function MoreMenu({
|
|
144
|
+
mail,
|
|
145
|
+
actions,
|
|
146
|
+
}: {
|
|
147
|
+
mail: MailController;
|
|
148
|
+
actions: SenderActions;
|
|
149
|
+
}) {
|
|
150
|
+
const message = latestIncoming(mail);
|
|
151
|
+
const reportable = mail.canReport;
|
|
152
|
+
|
|
153
|
+
if (!message || (!reportable && message.sender?.block?.workspace)) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const block = message.sender?.block;
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<DropdownMenu>
|
|
161
|
+
<ToolbarTooltip label="More actions" side="bottom">
|
|
162
|
+
<DropdownMenuTrigger
|
|
163
|
+
render={
|
|
164
|
+
<Button
|
|
165
|
+
variant="ghost"
|
|
166
|
+
size="icon-sm"
|
|
167
|
+
aria-label="More conversation actions"
|
|
168
|
+
disabled={mail.sharedActionPending}
|
|
169
|
+
className="text-foreground/80"
|
|
170
|
+
/>
|
|
171
|
+
}
|
|
172
|
+
>
|
|
173
|
+
<Ellipsis />
|
|
174
|
+
</DropdownMenuTrigger>
|
|
175
|
+
</ToolbarTooltip>
|
|
176
|
+
<DropdownMenuContent align="start" className="w-60">
|
|
177
|
+
{reportable && (
|
|
178
|
+
<DropdownMenuGroup>
|
|
179
|
+
<DropdownMenuItem onClick={() => actions.reportSpam(message)}>
|
|
180
|
+
<OctagonAlert /> Report spam
|
|
181
|
+
</DropdownMenuItem>
|
|
182
|
+
</DropdownMenuGroup>
|
|
183
|
+
)}
|
|
184
|
+
{reportable && !block?.workspace && <DropdownMenuSeparator />}
|
|
185
|
+
{block && !block.workspace ? (
|
|
186
|
+
<DropdownMenuItem onClick={() => actions.unblockSender(message)}>
|
|
187
|
+
<ShieldCheck />{" "}
|
|
188
|
+
<span className="truncate">Unblock “{block.pattern}”</span>
|
|
189
|
+
</DropdownMenuItem>
|
|
190
|
+
) : block ? null : (
|
|
191
|
+
<DropdownMenuItem onClick={() => actions.open("block", message)}>
|
|
192
|
+
<ShieldBan />{" "}
|
|
193
|
+
<span className="truncate">
|
|
194
|
+
Block “{message.fromName || message.fromAddress}”
|
|
195
|
+
</span>
|
|
196
|
+
</DropdownMenuItem>
|
|
197
|
+
)}
|
|
198
|
+
</DropdownMenuContent>
|
|
199
|
+
</DropdownMenu>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function DeleteForeverButton({
|
|
204
|
+
mail,
|
|
205
|
+
onDelete,
|
|
206
|
+
}: {
|
|
207
|
+
mail: MailController;
|
|
208
|
+
onDelete: () => void;
|
|
209
|
+
}) {
|
|
210
|
+
const [open, setOpen] = useState(false);
|
|
211
|
+
|
|
212
|
+
return (
|
|
213
|
+
<>
|
|
214
|
+
<CommandButton
|
|
215
|
+
label="Delete conversation permanently"
|
|
216
|
+
shortLabel="Delete forever"
|
|
217
|
+
icon={<Trash2 />}
|
|
218
|
+
destructive
|
|
219
|
+
disabled={mail.sharedActionPending}
|
|
220
|
+
onClick={() => setOpen(true)}
|
|
221
|
+
/>
|
|
222
|
+
<AlertDialog open={open} onOpenChange={setOpen}>
|
|
223
|
+
<AlertDialogContent>
|
|
224
|
+
<AlertDialogHeader>
|
|
225
|
+
<AlertDialogTitle>Delete permanently?</AlertDialogTitle>
|
|
226
|
+
<AlertDialogDescription>
|
|
227
|
+
This conversation and all its attachments will be deleted for
|
|
228
|
+
everyone. This cannot be undone.
|
|
229
|
+
</AlertDialogDescription>
|
|
230
|
+
</AlertDialogHeader>
|
|
231
|
+
<AlertDialogFooter>
|
|
232
|
+
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
233
|
+
<AlertDialogAction
|
|
234
|
+
type="button"
|
|
235
|
+
variant="destructive"
|
|
236
|
+
onClick={() => {
|
|
237
|
+
setOpen(false);
|
|
238
|
+
onDelete();
|
|
239
|
+
}}
|
|
240
|
+
>
|
|
241
|
+
Delete permanently
|
|
242
|
+
</AlertDialogAction>
|
|
243
|
+
</AlertDialogFooter>
|
|
244
|
+
</AlertDialogContent>
|
|
245
|
+
</AlertDialog>
|
|
246
|
+
</>
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function CommandBar({
|
|
251
|
+
mail,
|
|
252
|
+
actions,
|
|
253
|
+
}: {
|
|
254
|
+
mail: MailController;
|
|
255
|
+
actions: SenderActions;
|
|
256
|
+
}) {
|
|
257
|
+
const {
|
|
258
|
+
conversation,
|
|
259
|
+
conversations,
|
|
260
|
+
conversationId,
|
|
261
|
+
sharedActionPending: pending,
|
|
262
|
+
} = mail;
|
|
263
|
+
|
|
264
|
+
const state = conversation?.mailboxState ?? "active";
|
|
265
|
+
|
|
266
|
+
const index = conversations.findIndex(
|
|
267
|
+
(item) => item.conversationId === conversationId
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
const previous = index > 0 ? conversations[index - 1] : undefined;
|
|
271
|
+
const next = index === -1 ? undefined : conversations[index + 1];
|
|
272
|
+
|
|
273
|
+
return (
|
|
274
|
+
<TooltipProvider delay={300}>
|
|
275
|
+
<div
|
|
276
|
+
role="toolbar"
|
|
277
|
+
aria-label="Conversation actions"
|
|
278
|
+
className="border-border bg-surface flex h-12 shrink-0 items-center gap-0.5 border-b px-1.5 sm:px-2.5"
|
|
279
|
+
>
|
|
280
|
+
<Button
|
|
281
|
+
variant="ghost"
|
|
282
|
+
size="icon-sm"
|
|
283
|
+
className="mr-1 lg:hidden"
|
|
284
|
+
aria-label="Back to list"
|
|
285
|
+
onClick={mail.closeConversation}
|
|
286
|
+
>
|
|
287
|
+
<ArrowLeft />
|
|
288
|
+
</Button>
|
|
289
|
+
{state === "active" ? (
|
|
290
|
+
<CommandButton
|
|
291
|
+
label="Archive conversation"
|
|
292
|
+
shortLabel="Archive"
|
|
293
|
+
icon={<Archive />}
|
|
294
|
+
disabled={pending}
|
|
295
|
+
onClick={mail.archive}
|
|
296
|
+
/>
|
|
297
|
+
) : (
|
|
298
|
+
<CommandButton
|
|
299
|
+
label={
|
|
300
|
+
state === "spam" ? "Mark as not spam" : "Restore conversation"
|
|
301
|
+
}
|
|
302
|
+
shortLabel={state === "spam" ? "Not spam" : "Restore"}
|
|
303
|
+
icon={<Inbox />}
|
|
304
|
+
disabled={pending || actions.pending}
|
|
305
|
+
onClick={() => {
|
|
306
|
+
const message =
|
|
307
|
+
state === "spam" ? latestIncoming(mail) : undefined;
|
|
308
|
+
|
|
309
|
+
// "Not spam" also trusts the sender and teaches the classifier.
|
|
310
|
+
if (message) actions.markNotSpam(message);
|
|
311
|
+
else mail.restore();
|
|
312
|
+
}}
|
|
313
|
+
/>
|
|
314
|
+
)}
|
|
315
|
+
{state === "trash" ? (
|
|
316
|
+
mail.deletePermanently ? (
|
|
317
|
+
<DeleteForeverButton
|
|
318
|
+
mail={mail}
|
|
319
|
+
onDelete={mail.deletePermanently}
|
|
320
|
+
/>
|
|
321
|
+
) : null
|
|
322
|
+
) : (
|
|
323
|
+
<CommandButton
|
|
324
|
+
label="Move conversation to trash"
|
|
325
|
+
shortLabel="Delete"
|
|
326
|
+
icon={<Trash2 />}
|
|
327
|
+
destructive
|
|
328
|
+
disabled={pending}
|
|
329
|
+
onClick={mail.trash}
|
|
330
|
+
/>
|
|
331
|
+
)}
|
|
332
|
+
<span aria-hidden="true" className="bg-border mx-1 h-4.5 w-px" />
|
|
333
|
+
{mail.markRead ? (
|
|
334
|
+
<CommandButton
|
|
335
|
+
label="Mark conversation as read"
|
|
336
|
+
shortLabel="Mark read"
|
|
337
|
+
icon={<MailOpen />}
|
|
338
|
+
disabled={pending}
|
|
339
|
+
onClick={mail.markRead}
|
|
340
|
+
/>
|
|
341
|
+
) : mail.markUnread ? (
|
|
342
|
+
<CommandButton
|
|
343
|
+
label="Mark conversation as unread"
|
|
344
|
+
shortLabel="Mark unread"
|
|
345
|
+
icon={<Mail />}
|
|
346
|
+
disabled={pending}
|
|
347
|
+
onClick={mail.markUnread}
|
|
348
|
+
/>
|
|
349
|
+
) : null}
|
|
350
|
+
<MoveMenu mail={mail} />
|
|
351
|
+
<MoreMenu mail={mail} actions={actions} />
|
|
352
|
+
|
|
353
|
+
<div className="ml-auto flex items-center gap-0.5 pl-2">
|
|
354
|
+
{index !== -1 && (
|
|
355
|
+
<span className="text-muted-foreground mr-1.5 hidden text-xs whitespace-nowrap tabular-nums @2xl/reader:inline">
|
|
356
|
+
{index + 1} of {mail.displayedConversationCount}
|
|
357
|
+
</span>
|
|
358
|
+
)}
|
|
359
|
+
<ToolbarTooltip label="Previous conversation" side="bottom">
|
|
360
|
+
<Button
|
|
361
|
+
variant="ghost"
|
|
362
|
+
size="icon-sm"
|
|
363
|
+
className="size-7"
|
|
364
|
+
aria-label="Previous conversation"
|
|
365
|
+
disabled={!previous}
|
|
366
|
+
onClick={() =>
|
|
367
|
+
previous && mail.openConversation(previous.conversationId)
|
|
368
|
+
}
|
|
369
|
+
>
|
|
370
|
+
<ChevronUp />
|
|
371
|
+
</Button>
|
|
372
|
+
</ToolbarTooltip>
|
|
373
|
+
<ToolbarTooltip label="Next conversation" side="bottom">
|
|
374
|
+
<Button
|
|
375
|
+
variant="ghost"
|
|
376
|
+
size="icon-sm"
|
|
377
|
+
className="size-7"
|
|
378
|
+
aria-label="Next conversation"
|
|
379
|
+
disabled={!next}
|
|
380
|
+
onClick={() => next && mail.openConversation(next.conversationId)}
|
|
381
|
+
>
|
|
382
|
+
<ChevronDown />
|
|
383
|
+
</Button>
|
|
384
|
+
</ToolbarTooltip>
|
|
385
|
+
<span
|
|
386
|
+
aria-hidden="true"
|
|
387
|
+
className="bg-border mx-1 hidden h-4.5 w-px lg:block"
|
|
388
|
+
/>
|
|
389
|
+
<ToolbarTooltip label="Close reading pane" side="bottom">
|
|
390
|
+
<Button
|
|
391
|
+
variant="ghost"
|
|
392
|
+
size="icon-sm"
|
|
393
|
+
className="hidden size-7 lg:inline-flex"
|
|
394
|
+
aria-label="Close reading pane"
|
|
395
|
+
onClick={mail.closeConversation}
|
|
396
|
+
>
|
|
397
|
+
<X />
|
|
398
|
+
</Button>
|
|
399
|
+
</ToolbarTooltip>
|
|
400
|
+
</div>
|
|
401
|
+
</div>
|
|
402
|
+
</TooltipProvider>
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function ReaderPlaceholder({ mail }: { mail: MailController }) {
|
|
407
|
+
const unread = folderShowsUnreadCount(mail.activeFolder)
|
|
408
|
+
? (mail.activeFolder?.unreadCount ?? 0)
|
|
409
|
+
: 0;
|
|
410
|
+
|
|
411
|
+
return (
|
|
412
|
+
<div className="grid flex-1 place-items-center p-8 text-center">
|
|
413
|
+
<div className="max-w-xs">
|
|
414
|
+
<svg
|
|
415
|
+
aria-hidden="true"
|
|
416
|
+
viewBox="0 0 120 84"
|
|
417
|
+
className="text-border mx-auto h-20"
|
|
418
|
+
fill="none"
|
|
419
|
+
>
|
|
420
|
+
<rect
|
|
421
|
+
x="8"
|
|
422
|
+
y="10"
|
|
423
|
+
width="104"
|
|
424
|
+
height="66"
|
|
425
|
+
rx="8"
|
|
426
|
+
fill="var(--surface-sunken)"
|
|
427
|
+
stroke="currentColor"
|
|
428
|
+
/>
|
|
429
|
+
<path d="M8 26h104" stroke="currentColor" />
|
|
430
|
+
<rect
|
|
431
|
+
x="18"
|
|
432
|
+
y="35"
|
|
433
|
+
width="30"
|
|
434
|
+
height="5"
|
|
435
|
+
rx="2.5"
|
|
436
|
+
fill="var(--primary)"
|
|
437
|
+
opacity="0.55"
|
|
438
|
+
/>
|
|
439
|
+
<rect
|
|
440
|
+
x="18"
|
|
441
|
+
y="46"
|
|
442
|
+
width="78"
|
|
443
|
+
height="4"
|
|
444
|
+
rx="2"
|
|
445
|
+
fill="currentColor"
|
|
446
|
+
/>
|
|
447
|
+
<rect
|
|
448
|
+
x="18"
|
|
449
|
+
y="55"
|
|
450
|
+
width="62"
|
|
451
|
+
height="4"
|
|
452
|
+
rx="2"
|
|
453
|
+
fill="currentColor"
|
|
454
|
+
/>
|
|
455
|
+
<rect
|
|
456
|
+
x="18"
|
|
457
|
+
y="64"
|
|
458
|
+
width="40"
|
|
459
|
+
height="4"
|
|
460
|
+
rx="2"
|
|
461
|
+
fill="currentColor"
|
|
462
|
+
/>
|
|
463
|
+
<circle cx="18" cy="18" r="2.5" fill="currentColor" />
|
|
464
|
+
<circle cx="26" cy="18" r="2.5" fill="currentColor" />
|
|
465
|
+
<circle cx="34" cy="18" r="2.5" fill="currentColor" />
|
|
466
|
+
</svg>
|
|
467
|
+
<p className="mt-4 text-[14px] font-semibold">
|
|
468
|
+
Select a conversation to read
|
|
469
|
+
</p>
|
|
470
|
+
<p className="text-muted-foreground mt-1 text-[13px] leading-5">
|
|
471
|
+
{unread > 0
|
|
472
|
+
? `${unread} unread in ${mail.folderName}. Pick one from the list to open it here.`
|
|
473
|
+
: "Messages open here, beside the list, so you can triage without losing your place."}
|
|
474
|
+
</p>
|
|
475
|
+
</div>
|
|
476
|
+
</div>
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
export function ReaderPane({ mail }: { mail: MailController }) {
|
|
481
|
+
const {
|
|
482
|
+
conversationId,
|
|
483
|
+
conversationQuery,
|
|
484
|
+
conversation,
|
|
485
|
+
conversationMessages,
|
|
486
|
+
mailbox,
|
|
487
|
+
} = mail;
|
|
488
|
+
|
|
489
|
+
const senderActions = useSenderActions({
|
|
490
|
+
mailbox,
|
|
491
|
+
onLeaveConversation: mail.closeConversation,
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
useSenderIntelFill(mailbox?.id, conversationId, conversationMessages);
|
|
495
|
+
|
|
496
|
+
if (!conversationId) return <ReaderPlaceholder mail={mail} />;
|
|
497
|
+
const pages = conversationQuery.data?.pages;
|
|
498
|
+
|
|
499
|
+
return (
|
|
500
|
+
<div className="@container/reader flex min-h-0 flex-1 flex-col">
|
|
501
|
+
<CommandBar mail={mail} actions={senderActions} />
|
|
502
|
+
<div className="min-h-0 flex-1 overflow-y-auto">
|
|
503
|
+
<ConversationView
|
|
504
|
+
messages={conversationMessages}
|
|
505
|
+
messageCount={
|
|
506
|
+
conversation?.messageCount ?? conversationMessages.length
|
|
507
|
+
}
|
|
508
|
+
hasOlderMessages={Boolean(pages?.at(-1)?.nextCursor)}
|
|
509
|
+
loadingOlder={conversationQuery.isFetchingNextPage}
|
|
510
|
+
olderMessagesError={conversationQuery.isFetchNextPageError}
|
|
511
|
+
// The mailbox list confirms the URL's mailbox; until then a failed
|
|
512
|
+
// request may just be a stale link about to be redirected.
|
|
513
|
+
loading={!mailbox || (!pages?.length && conversationQuery.isPending)}
|
|
514
|
+
error={
|
|
515
|
+
pages?.length || !mailbox
|
|
516
|
+
? undefined
|
|
517
|
+
: conversationQuery.error?.message
|
|
518
|
+
}
|
|
519
|
+
summary={mail.conversations.find(
|
|
520
|
+
(item) => item.conversationId === conversationId
|
|
521
|
+
)}
|
|
522
|
+
mailbox={mailbox}
|
|
523
|
+
folderName={mail.folderName}
|
|
524
|
+
onRetry={() => void conversationQuery.refetch()}
|
|
525
|
+
onLoadOlder={() => void conversationQuery.fetchNextPage()}
|
|
526
|
+
onForward={mail.openForward}
|
|
527
|
+
onOpenConversation={(id) => mail.openConversation(id, "sent")}
|
|
528
|
+
senderActions={senderActions}
|
|
529
|
+
reportable={mail.canReport}
|
|
530
|
+
/>
|
|
531
|
+
</div>
|
|
532
|
+
{senderActions.dialogs}
|
|
533
|
+
</div>
|
|
534
|
+
);
|
|
535
|
+
}
|