@open-workspace/email 0.3.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 +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,437 @@
|
|
|
1
|
+
import { Button, useConfirm } from "@open-workspace/core/ui";
|
|
2
|
+
import {
|
|
3
|
+
ChevronUp,
|
|
4
|
+
CircleAlert,
|
|
5
|
+
Forward,
|
|
6
|
+
LoaderCircle,
|
|
7
|
+
RotateCw,
|
|
8
|
+
} from "lucide-react";
|
|
9
|
+
import { useEffect, useRef, useState } from "react";
|
|
10
|
+
import { toast } from "sonner";
|
|
11
|
+
|
|
12
|
+
import { baseSubject } from "../../shared/mail";
|
|
13
|
+
import { ConversationLoadingSkeleton } from "./conversation-loading-skeleton";
|
|
14
|
+
import { ConversationMessage } from "./conversation-message";
|
|
15
|
+
import { ConversationReply, ReplyActionIcon } from "./conversation-reply";
|
|
16
|
+
import type { SentReply } from "./conversation-reply";
|
|
17
|
+
import { actionButtonLabel } from "./message-actions";
|
|
18
|
+
import type { SenderHandlers } from "./message-actions";
|
|
19
|
+
import {
|
|
20
|
+
OriginalMessageSheet,
|
|
21
|
+
originalSourceUrl,
|
|
22
|
+
} from "./original-message-sheet";
|
|
23
|
+
import { notifyOutboundResult } from "./outbound-notification";
|
|
24
|
+
import { canUnsubscribe } from "./sender-actions";
|
|
25
|
+
import type { SenderActions } from "./sender-actions";
|
|
26
|
+
import type {
|
|
27
|
+
ConversationSummary,
|
|
28
|
+
Mailbox,
|
|
29
|
+
MessageDetail,
|
|
30
|
+
ReplyActionMode,
|
|
31
|
+
} from "./types";
|
|
32
|
+
import { useResendMessage, useSetMessageRead } from "./use-mail-data";
|
|
33
|
+
|
|
34
|
+
type ReplySelection = {
|
|
35
|
+
parentId: string;
|
|
36
|
+
mode: ReplyActionMode;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export function ConversationView({
|
|
40
|
+
messages,
|
|
41
|
+
messageCount,
|
|
42
|
+
hasOlderMessages,
|
|
43
|
+
loadingOlder,
|
|
44
|
+
olderMessagesError,
|
|
45
|
+
loading,
|
|
46
|
+
error,
|
|
47
|
+
mailbox,
|
|
48
|
+
onRetry,
|
|
49
|
+
onLoadOlder,
|
|
50
|
+
onForward,
|
|
51
|
+
onOpenConversation,
|
|
52
|
+
senderActions,
|
|
53
|
+
reportable = false,
|
|
54
|
+
summary,
|
|
55
|
+
}: {
|
|
56
|
+
messages: MessageDetail[];
|
|
57
|
+
messageCount: number;
|
|
58
|
+
hasOlderMessages: boolean;
|
|
59
|
+
loadingOlder: boolean;
|
|
60
|
+
olderMessagesError: boolean;
|
|
61
|
+
loading: boolean;
|
|
62
|
+
error?: string;
|
|
63
|
+
mailbox?: Mailbox;
|
|
64
|
+
folderName: string;
|
|
65
|
+
onRetry: () => void;
|
|
66
|
+
onLoadOlder: () => void;
|
|
67
|
+
onForward: (message: MessageDetail) => void;
|
|
68
|
+
onOpenConversation: (conversationId: string) => void;
|
|
69
|
+
/** Unsubscribe, block, report and filter actions with their dialogs. */
|
|
70
|
+
senderActions?: SenderActions;
|
|
71
|
+
/** Reporting moves the conversation to Spam, so it fits received mail outside Spam and Trash. */
|
|
72
|
+
reportable?: boolean;
|
|
73
|
+
/** The list's row for this conversation, shown while it loads. */
|
|
74
|
+
summary?: ConversationSummary;
|
|
75
|
+
}) {
|
|
76
|
+
const [replySelection, setReplySelection] = useState<ReplySelection | null>(
|
|
77
|
+
null
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const [originalMessageId, setOriginalMessageId] = useState<string | null>(
|
|
81
|
+
null
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const replyRegion = useRef<HTMLDivElement>(null);
|
|
85
|
+
|
|
86
|
+
const canShowOriginal = (message: MessageDetail) =>
|
|
87
|
+
Boolean(mailbox && message.hasOriginal);
|
|
88
|
+
|
|
89
|
+
// ⌥⌘U (Ctrl+Alt+U elsewhere) opens the latest original in the thread.
|
|
90
|
+
const shortcutTarget = [...messages].reverse().find(canShowOriginal);
|
|
91
|
+
const shortcutTargetId = shortcutTarget?.id;
|
|
92
|
+
const resendMessage = useResendMessage();
|
|
93
|
+
const setMessageRead = useSetMessageRead();
|
|
94
|
+
|
|
95
|
+
// Bring the composer into view and focus it whenever a reply target is picked.
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
if (!replySelection) return;
|
|
98
|
+
const region = replyRegion.current;
|
|
99
|
+
region?.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
|
100
|
+
region?.querySelector("textarea")?.focus({ preventScroll: true });
|
|
101
|
+
}, [replySelection]);
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (!shortcutTargetId) return;
|
|
105
|
+
|
|
106
|
+
const targetId = shortcutTargetId;
|
|
107
|
+
|
|
108
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
109
|
+
if (
|
|
110
|
+
event.code !== "KeyU" ||
|
|
111
|
+
!event.altKey ||
|
|
112
|
+
!(event.metaKey || event.ctrlKey)
|
|
113
|
+
) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
setOriginalMessageId(targetId);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
window.addEventListener("keydown", onKeyDown);
|
|
122
|
+
|
|
123
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
124
|
+
}, [shortcutTargetId]);
|
|
125
|
+
const { confirm, dialog: confirmDialog } = useConfirm();
|
|
126
|
+
|
|
127
|
+
if (loading) {
|
|
128
|
+
return <ConversationLoadingSkeleton summary={summary} />;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (error) {
|
|
132
|
+
return (
|
|
133
|
+
<section className="grid min-h-80 place-items-center px-6 py-16 text-center">
|
|
134
|
+
<div className="animate-fade-in">
|
|
135
|
+
<span className="bg-destructive/10 text-destructive mx-auto grid size-10 place-items-center rounded-lg">
|
|
136
|
+
<CircleAlert className="size-5" strokeWidth={1.75} />
|
|
137
|
+
</span>
|
|
138
|
+
<p className="mt-3.5 text-[14px] font-semibold">
|
|
139
|
+
Could not load this conversation
|
|
140
|
+
</p>
|
|
141
|
+
<p className="text-muted-foreground mx-auto mt-1 max-w-sm text-[13px] leading-5">
|
|
142
|
+
{error}
|
|
143
|
+
</p>
|
|
144
|
+
<Button
|
|
145
|
+
className="mt-4"
|
|
146
|
+
variant="outline"
|
|
147
|
+
size="sm"
|
|
148
|
+
onClick={onRetry}
|
|
149
|
+
>
|
|
150
|
+
<RotateCw /> Retry
|
|
151
|
+
</Button>
|
|
152
|
+
</div>
|
|
153
|
+
</section>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const latest = messages.at(-1);
|
|
158
|
+
|
|
159
|
+
if (!latest) return null;
|
|
160
|
+
const { conversationId } = latest;
|
|
161
|
+
const conversationSubject = baseSubject(latest.subject) || "(no subject)";
|
|
162
|
+
|
|
163
|
+
const selectedParent =
|
|
164
|
+
messages.find(
|
|
165
|
+
(message) =>
|
|
166
|
+
message.id === replySelection?.parentId &&
|
|
167
|
+
message.replyPlan.actions.length > 0
|
|
168
|
+
) ?? null;
|
|
169
|
+
|
|
170
|
+
const selectedMode =
|
|
171
|
+
selectedParent && replySelection ? replySelection.mode : null;
|
|
172
|
+
|
|
173
|
+
// Reply from the end of the thread answers the latest incoming message when there is one.
|
|
174
|
+
const replyCandidates = [...messages]
|
|
175
|
+
.reverse()
|
|
176
|
+
.filter((message) => message.replyPlan.actions.length > 0);
|
|
177
|
+
|
|
178
|
+
const replyTarget =
|
|
179
|
+
replyCandidates.find((message) => message.direction === "incoming") ??
|
|
180
|
+
replyCandidates[0];
|
|
181
|
+
|
|
182
|
+
function handleSent(result: SentReply) {
|
|
183
|
+
setReplySelection(null);
|
|
184
|
+
|
|
185
|
+
if (result.detached) onOpenConversation(result.conversationId);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function resend(message: MessageDetail) {
|
|
189
|
+
if (!mailbox) return;
|
|
190
|
+
|
|
191
|
+
if (
|
|
192
|
+
message.transportState === "unconfirmed" &&
|
|
193
|
+
!(await confirm({
|
|
194
|
+
title: "Send this message again?",
|
|
195
|
+
description:
|
|
196
|
+
"The first attempt was never confirmed, so it may already have been delivered. Sending again can deliver a duplicate.",
|
|
197
|
+
action: "Send again",
|
|
198
|
+
}))
|
|
199
|
+
) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
resendMessage.mutate(
|
|
204
|
+
{ id: message.id, mailboxId: mailbox.id },
|
|
205
|
+
{
|
|
206
|
+
onSuccess: (result) => notifyOutboundResult(result, "message"),
|
|
207
|
+
onError: (failure) => toast.error(failure.message),
|
|
208
|
+
}
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function markUnread(messageId: string) {
|
|
213
|
+
if (!mailbox) return;
|
|
214
|
+
|
|
215
|
+
try {
|
|
216
|
+
await setMessageRead.mutateAsync({
|
|
217
|
+
id: messageId,
|
|
218
|
+
mailboxId: mailbox.id,
|
|
219
|
+
conversationId,
|
|
220
|
+
isRead: false,
|
|
221
|
+
});
|
|
222
|
+
} catch (failure) {
|
|
223
|
+
toast.error(
|
|
224
|
+
failure instanceof Error ? failure.message : "Could not mark as unread"
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async function markViewed(messageId: string) {
|
|
230
|
+
if (!mailbox) return;
|
|
231
|
+
await setMessageRead.mutateAsync({
|
|
232
|
+
id: messageId,
|
|
233
|
+
mailboxId: mailbox.id,
|
|
234
|
+
conversationId,
|
|
235
|
+
isRead: true,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return (
|
|
240
|
+
<article className="mx-auto w-full max-w-[60rem] pb-10">
|
|
241
|
+
{confirmDialog}
|
|
242
|
+
<header className="px-4 pt-5 pb-4 sm:px-6 sm:pt-6">
|
|
243
|
+
<h1 className="text-[1.3125rem] leading-[1.3] font-semibold tracking-[-0.018em] text-balance [overflow-wrap:anywhere]">
|
|
244
|
+
{conversationSubject}
|
|
245
|
+
</h1>
|
|
246
|
+
{messageCount > 1 && (
|
|
247
|
+
<p className="text-muted-foreground mt-1 text-xs">
|
|
248
|
+
{messageCount} messages
|
|
249
|
+
</p>
|
|
250
|
+
)}
|
|
251
|
+
</header>
|
|
252
|
+
|
|
253
|
+
<div className="border-border border-y">
|
|
254
|
+
{hasOlderMessages ? (
|
|
255
|
+
<div className="border-border flex justify-center border-b py-2">
|
|
256
|
+
<Button
|
|
257
|
+
type="button"
|
|
258
|
+
variant="ghost"
|
|
259
|
+
size="xs"
|
|
260
|
+
className="text-muted-foreground"
|
|
261
|
+
disabled={loadingOlder}
|
|
262
|
+
onClick={onLoadOlder}
|
|
263
|
+
>
|
|
264
|
+
{loadingOlder ? (
|
|
265
|
+
<LoaderCircle className="animate-spin" />
|
|
266
|
+
) : (
|
|
267
|
+
<ChevronUp />
|
|
268
|
+
)}
|
|
269
|
+
{olderMessagesError
|
|
270
|
+
? "Retry earlier messages"
|
|
271
|
+
: "Load earlier messages"}
|
|
272
|
+
</Button>
|
|
273
|
+
</div>
|
|
274
|
+
) : null}
|
|
275
|
+
|
|
276
|
+
{messages.map((message, index) => {
|
|
277
|
+
const previous = messages[index - 1];
|
|
278
|
+
const audience = previous ? audienceChange(previous, message) : null;
|
|
279
|
+
|
|
280
|
+
return (
|
|
281
|
+
<div key={message.id} className="contents">
|
|
282
|
+
{audience && <AudienceChange text={audience} />}
|
|
283
|
+
<ConversationMessage
|
|
284
|
+
message={message}
|
|
285
|
+
mailbox={mailbox}
|
|
286
|
+
defaultExpanded={message === latest || !message.isRead}
|
|
287
|
+
collapsible={messages.length > 1}
|
|
288
|
+
showViewedBy={mailbox?.kind === "shared"}
|
|
289
|
+
resendPending={
|
|
290
|
+
resendMessage.isPending &&
|
|
291
|
+
resendMessage.variables?.id === message.id
|
|
292
|
+
}
|
|
293
|
+
handlers={{
|
|
294
|
+
onViewed: () => markViewed(message.id),
|
|
295
|
+
onReply: (action) =>
|
|
296
|
+
setReplySelection({
|
|
297
|
+
parentId: message.id,
|
|
298
|
+
mode: action.mode,
|
|
299
|
+
}),
|
|
300
|
+
onForward: () => onForward(message),
|
|
301
|
+
onResend: () => resend(message),
|
|
302
|
+
onShowOriginal: canShowOriginal(message)
|
|
303
|
+
? () => setOriginalMessageId(message.id)
|
|
304
|
+
: undefined,
|
|
305
|
+
originalUrl:
|
|
306
|
+
mailbox && message.hasOriginal
|
|
307
|
+
? originalSourceUrl(mailbox.id, message.id)
|
|
308
|
+
: undefined,
|
|
309
|
+
onMarkUnread:
|
|
310
|
+
mailbox &&
|
|
311
|
+
message.direction === "incoming" &&
|
|
312
|
+
message.isRead
|
|
313
|
+
? () => void markUnread(message.id)
|
|
314
|
+
: undefined,
|
|
315
|
+
sender:
|
|
316
|
+
message.direction === "incoming" && senderActions && mailbox
|
|
317
|
+
? senderHandlers(message, senderActions, reportable)
|
|
318
|
+
: undefined,
|
|
319
|
+
}}
|
|
320
|
+
/>
|
|
321
|
+
</div>
|
|
322
|
+
);
|
|
323
|
+
})}
|
|
324
|
+
</div>
|
|
325
|
+
|
|
326
|
+
<div ref={replyRegion} className="scroll-mb-4 px-4 pt-4 sm:px-6">
|
|
327
|
+
{selectedParent && selectedMode ? (
|
|
328
|
+
<ConversationReply
|
|
329
|
+
key={selectedParent.id}
|
|
330
|
+
mailbox={mailbox}
|
|
331
|
+
parent={selectedParent}
|
|
332
|
+
mode={selectedMode}
|
|
333
|
+
onModeChange={(mode) =>
|
|
334
|
+
setReplySelection({
|
|
335
|
+
parentId: selectedParent.id,
|
|
336
|
+
mode,
|
|
337
|
+
})
|
|
338
|
+
}
|
|
339
|
+
onCancel={() => setReplySelection(null)}
|
|
340
|
+
onSent={handleSent}
|
|
341
|
+
/>
|
|
342
|
+
) : mailbox?.canSend ? (
|
|
343
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
344
|
+
{replyTarget?.replyPlan.actions.map((action) => (
|
|
345
|
+
<Button
|
|
346
|
+
key={action.mode}
|
|
347
|
+
type="button"
|
|
348
|
+
variant="outline"
|
|
349
|
+
size="sm"
|
|
350
|
+
onClick={() =>
|
|
351
|
+
setReplySelection({
|
|
352
|
+
parentId: replyTarget.id,
|
|
353
|
+
mode: action.mode,
|
|
354
|
+
})
|
|
355
|
+
}
|
|
356
|
+
>
|
|
357
|
+
<ReplyActionIcon mode={action.mode} />
|
|
358
|
+
{actionButtonLabel(action)}
|
|
359
|
+
</Button>
|
|
360
|
+
))}
|
|
361
|
+
<Button
|
|
362
|
+
type="button"
|
|
363
|
+
variant="outline"
|
|
364
|
+
size="sm"
|
|
365
|
+
onClick={() => onForward(latest)}
|
|
366
|
+
>
|
|
367
|
+
<Forward /> Forward
|
|
368
|
+
</Button>
|
|
369
|
+
</div>
|
|
370
|
+
) : null}
|
|
371
|
+
</div>
|
|
372
|
+
{mailbox && (
|
|
373
|
+
<OriginalMessageSheet
|
|
374
|
+
mailboxId={mailbox.id}
|
|
375
|
+
message={
|
|
376
|
+
messages.find((message) => message.id === originalMessageId) ?? null
|
|
377
|
+
}
|
|
378
|
+
onClose={() => setOriginalMessageId(null)}
|
|
379
|
+
/>
|
|
380
|
+
)}
|
|
381
|
+
</article>
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function senderHandlers(
|
|
386
|
+
message: MessageDetail,
|
|
387
|
+
actions: SenderActions,
|
|
388
|
+
reportable: boolean
|
|
389
|
+
): SenderHandlers {
|
|
390
|
+
return {
|
|
391
|
+
onUnsubscribe: canUnsubscribe(message)
|
|
392
|
+
? () => actions.open("unsubscribe", message)
|
|
393
|
+
: undefined,
|
|
394
|
+
onBlock: () => actions.open("block", message),
|
|
395
|
+
onUnblock: () => actions.unblockSender(message),
|
|
396
|
+
onReportSpam: reportable ? () => actions.reportSpam(message) : undefined,
|
|
397
|
+
onTrust: message.sender?.trustedAt
|
|
398
|
+
? undefined
|
|
399
|
+
: () => actions.trustSender(message),
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function AudienceChange({ text }: { text: string }) {
|
|
404
|
+
return (
|
|
405
|
+
<div className="border-border text-muted-foreground flex items-center gap-3 border-t px-4 py-2 text-[11px] sm:px-6">
|
|
406
|
+
<span className="bg-border h-px flex-1" />
|
|
407
|
+
<span className="font-medium">{text}</span>
|
|
408
|
+
<span className="bg-border h-px flex-1" />
|
|
409
|
+
</div>
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function audienceChange(previous: MessageDetail, current: MessageDetail) {
|
|
414
|
+
const before = new Set(previous.replyPlan.participants);
|
|
415
|
+
const after = new Set(current.replyPlan.participants);
|
|
416
|
+
|
|
417
|
+
if (
|
|
418
|
+
before.size === after.size &&
|
|
419
|
+
[...before].every((participant) => after.has(participant))
|
|
420
|
+
) {
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const added = current.replyPlan.participants.filter(
|
|
425
|
+
(value) => !before.has(value)
|
|
426
|
+
);
|
|
427
|
+
|
|
428
|
+
const removed = previous.replyPlan.participants.filter(
|
|
429
|
+
(value) => !after.has(value)
|
|
430
|
+
);
|
|
431
|
+
|
|
432
|
+
if (added.length && !removed.length) return `${added.join(", ")} joined`;
|
|
433
|
+
|
|
434
|
+
if (removed.length && !added.length) return `${removed.join(", ")} left`;
|
|
435
|
+
|
|
436
|
+
return "Recipients changed";
|
|
437
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DropdownMenu,
|
|
3
|
+
DropdownMenuContent,
|
|
4
|
+
DropdownMenuGroup,
|
|
5
|
+
DropdownMenuLabel,
|
|
6
|
+
DropdownMenuSeparator,
|
|
7
|
+
DropdownMenuTrigger,
|
|
8
|
+
cn,
|
|
9
|
+
} from "@open-workspace/core/ui";
|
|
10
|
+
import { format } from "date-fns";
|
|
11
|
+
import { Check, CheckCheck, CircleAlert, Clock3 } from "lucide-react";
|
|
12
|
+
import type { LucideIcon } from "lucide-react";
|
|
13
|
+
|
|
14
|
+
import type { MessageDetail, RecipientDeliveryStatus } from "./types";
|
|
15
|
+
|
|
16
|
+
type Indicator = {
|
|
17
|
+
Icon: LucideIcon;
|
|
18
|
+
label: string;
|
|
19
|
+
tone: "muted" | "warning" | "danger";
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function recipients(message: MessageDetail) {
|
|
23
|
+
return [
|
|
24
|
+
...new Set(
|
|
25
|
+
[
|
|
26
|
+
...message.toAddresses,
|
|
27
|
+
...message.ccAddresses,
|
|
28
|
+
...message.bccAddresses,
|
|
29
|
+
].map((address) => address.trim().toLocaleLowerCase())
|
|
30
|
+
),
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function deliveryIndicator(
|
|
35
|
+
message: MessageDetail,
|
|
36
|
+
totalRecipients: number
|
|
37
|
+
): Indicator {
|
|
38
|
+
if (message.transportState === "unconfirmed") {
|
|
39
|
+
return { Icon: CircleAlert, label: "Unconfirmed", tone: "warning" };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (message.transportState === "failed") {
|
|
43
|
+
return { Icon: CircleAlert, label: "Not sent", tone: "danger" };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!message.deliveryStatuses.length) {
|
|
47
|
+
return { Icon: Check, label: "Sent", tone: "muted" };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const delivered = message.deliveryStatuses.filter(
|
|
51
|
+
(item) => item.status === "delivered" || item.status === "complained"
|
|
52
|
+
).length;
|
|
53
|
+
|
|
54
|
+
const failed = message.deliveryStatuses.filter((item) =>
|
|
55
|
+
["bounced", "failed", "rejected"].includes(item.status)
|
|
56
|
+
).length;
|
|
57
|
+
|
|
58
|
+
const complained = message.deliveryStatuses.some(
|
|
59
|
+
(item) => item.status === "complained"
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
if (failed > 0 || complained) {
|
|
63
|
+
return {
|
|
64
|
+
Icon: CircleAlert,
|
|
65
|
+
label:
|
|
66
|
+
delivered > 0 && totalRecipients > 1
|
|
67
|
+
? `${delivered}/${totalRecipients} delivered`
|
|
68
|
+
: failed > 0
|
|
69
|
+
? "Not delivered"
|
|
70
|
+
: "Marked as spam",
|
|
71
|
+
tone: delivered > 0 ? "warning" : "danger",
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (totalRecipients > 0 && delivered >= totalRecipients) {
|
|
76
|
+
return { Icon: CheckCheck, label: "Delivered", tone: "muted" };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
Icon: Clock3,
|
|
81
|
+
label:
|
|
82
|
+
delivered > 0 && totalRecipients > 1
|
|
83
|
+
? `${delivered}/${totalRecipients} delivered`
|
|
84
|
+
: "Delivering",
|
|
85
|
+
tone: "muted",
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const recipientStatusIcons: Record<
|
|
90
|
+
RecipientDeliveryStatus["status"],
|
|
91
|
+
{ Icon: LucideIcon; className: string }
|
|
92
|
+
> = {
|
|
93
|
+
delivered: { Icon: CheckCheck, className: "text-success" },
|
|
94
|
+
deferred: { Icon: Clock3, className: "text-amber-600 dark:text-amber-400" },
|
|
95
|
+
bounced: { Icon: CircleAlert, className: "text-destructive" },
|
|
96
|
+
failed: { Icon: CircleAlert, className: "text-destructive" },
|
|
97
|
+
rejected: { Icon: CircleAlert, className: "text-destructive" },
|
|
98
|
+
complained: {
|
|
99
|
+
Icon: CircleAlert,
|
|
100
|
+
className: "text-amber-600 dark:text-amber-400",
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** Plain-language outcome; the SMTP detail stays available underneath. */
|
|
105
|
+
function recipientExplanation(status: RecipientDeliveryStatus | undefined) {
|
|
106
|
+
if (!status) {
|
|
107
|
+
return "Sent. Waiting for the recipient's server to report back.";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (status.status === "delivered") {
|
|
111
|
+
return "Accepted by the recipient's mail server.";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (status.status === "deferred") {
|
|
115
|
+
return "The recipient's server asked to try later. Delivery is retried automatically.";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (status.status === "bounced") {
|
|
119
|
+
return "The recipient's server refused the message permanently.";
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (status.status === "failed") return "The message could not be delivered.";
|
|
123
|
+
|
|
124
|
+
if (status.status === "rejected") return "Rejected before delivery.";
|
|
125
|
+
|
|
126
|
+
return "Delivered, but the recipient reported it as spam.";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function smtpCodeMeaning(code: string) {
|
|
130
|
+
if (code.startsWith("2")) return "OK";
|
|
131
|
+
|
|
132
|
+
if (code.startsWith("4")) return "temporary failure";
|
|
133
|
+
|
|
134
|
+
if (code.startsWith("5")) return "permanent failure";
|
|
135
|
+
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function recipientStatusLabel(status: RecipientDeliveryStatus | undefined) {
|
|
140
|
+
if (!status) return "Awaiting status";
|
|
141
|
+
|
|
142
|
+
if (status.status === "delivered") return "Delivered";
|
|
143
|
+
|
|
144
|
+
if (status.status === "deferred") return "Delivery delayed";
|
|
145
|
+
|
|
146
|
+
if (status.status === "bounced") return "Bounced";
|
|
147
|
+
|
|
148
|
+
if (status.status === "failed") return "Delivery failed";
|
|
149
|
+
|
|
150
|
+
if (status.status === "rejected") return "Rejected";
|
|
151
|
+
|
|
152
|
+
return "Marked as spam";
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function DeliveryIndicator({
|
|
156
|
+
message,
|
|
157
|
+
className,
|
|
158
|
+
}: {
|
|
159
|
+
message: MessageDetail;
|
|
160
|
+
className?: string;
|
|
161
|
+
}) {
|
|
162
|
+
if (message.direction !== "outgoing") return null;
|
|
163
|
+
const addresses = recipients(message);
|
|
164
|
+
|
|
165
|
+
const statuses = new Map(
|
|
166
|
+
message.deliveryStatuses.map((status) => [
|
|
167
|
+
status.recipient.toLocaleLowerCase(),
|
|
168
|
+
status,
|
|
169
|
+
])
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const indicator = deliveryIndicator(message, addresses.length);
|
|
173
|
+
const { Icon } = indicator;
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<DropdownMenu>
|
|
177
|
+
<DropdownMenuTrigger
|
|
178
|
+
render={
|
|
179
|
+
<button
|
|
180
|
+
type="button"
|
|
181
|
+
className={cn(
|
|
182
|
+
"focus-visible:ring-ring inline-flex items-center gap-1 rounded-sm text-xs font-medium transition-opacity outline-none hover:opacity-75 focus-visible:ring-2",
|
|
183
|
+
indicator.tone === "muted" && "text-muted-foreground",
|
|
184
|
+
indicator.tone === "warning" &&
|
|
185
|
+
"text-amber-700 dark:text-amber-400",
|
|
186
|
+
indicator.tone === "danger" && "text-destructive",
|
|
187
|
+
className
|
|
188
|
+
)}
|
|
189
|
+
aria-label={`Delivery status: ${indicator.label}`}
|
|
190
|
+
/>
|
|
191
|
+
}
|
|
192
|
+
>
|
|
193
|
+
<Icon
|
|
194
|
+
className={cn(
|
|
195
|
+
"size-3.5",
|
|
196
|
+
indicator.Icon === CheckCheck && "text-success"
|
|
197
|
+
)}
|
|
198
|
+
/>
|
|
199
|
+
<span>{indicator.label}</span>
|
|
200
|
+
</DropdownMenuTrigger>
|
|
201
|
+
<DropdownMenuContent
|
|
202
|
+
align="end"
|
|
203
|
+
className="w-80 max-w-[calc(100vw-2rem)]"
|
|
204
|
+
>
|
|
205
|
+
<DropdownMenuGroup>
|
|
206
|
+
<DropdownMenuLabel>Delivery status</DropdownMenuLabel>
|
|
207
|
+
</DropdownMenuGroup>
|
|
208
|
+
<DropdownMenuSeparator />
|
|
209
|
+
{message.transportState === "unconfirmed" ? (
|
|
210
|
+
<p className="px-2 py-2 text-xs text-amber-700 dark:text-amber-400">
|
|
211
|
+
{message.transportError
|
|
212
|
+
? `${message.transportError} Submission could not be confirmed.`
|
|
213
|
+
: "Submission could not be confirmed."}{" "}
|
|
214
|
+
Automatic resend is disabled because it could deliver a duplicate.
|
|
215
|
+
</p>
|
|
216
|
+
) : message.transportState === "failed" ? (
|
|
217
|
+
<p className="text-destructive px-2 py-2 text-xs">
|
|
218
|
+
{message.transportError ||
|
|
219
|
+
"The message could not be prepared for sending."}
|
|
220
|
+
</p>
|
|
221
|
+
) : (
|
|
222
|
+
<div className="divide-y">
|
|
223
|
+
{addresses.map((address) => {
|
|
224
|
+
const status = statuses.get(address);
|
|
225
|
+
|
|
226
|
+
const { Icon: StatusIcon, className: iconClassName } = status
|
|
227
|
+
? recipientStatusIcons[status.status]
|
|
228
|
+
: { Icon: Clock3, className: "text-muted-foreground" };
|
|
229
|
+
|
|
230
|
+
const meaning = status?.smtpCode
|
|
231
|
+
? smtpCodeMeaning(status.smtpCode)
|
|
232
|
+
: null;
|
|
233
|
+
|
|
234
|
+
return (
|
|
235
|
+
<div key={address} className="flex gap-2.5 px-2 py-2.5 text-xs">
|
|
236
|
+
<StatusIcon
|
|
237
|
+
className={cn("mt-0.5 size-3.5 shrink-0", iconClassName)}
|
|
238
|
+
/>
|
|
239
|
+
<div className="min-w-0 flex-1">
|
|
240
|
+
<p className="flex items-baseline justify-between gap-3">
|
|
241
|
+
<span className="min-w-0 truncate font-medium">
|
|
242
|
+
{address}
|
|
243
|
+
</span>
|
|
244
|
+
<span className="text-muted-foreground shrink-0">
|
|
245
|
+
{recipientStatusLabel(status)}
|
|
246
|
+
</span>
|
|
247
|
+
</p>
|
|
248
|
+
<p className="text-muted-foreground mt-0.5">
|
|
249
|
+
{recipientExplanation(status)}
|
|
250
|
+
</p>
|
|
251
|
+
{status && (
|
|
252
|
+
<p className="text-muted-foreground/80 mt-1 text-[11px]">
|
|
253
|
+
{[
|
|
254
|
+
status.smtpCode &&
|
|
255
|
+
`SMTP ${status.smtpCode}${meaning ? ` (${meaning})` : ""}`,
|
|
256
|
+
status.detail,
|
|
257
|
+
format(new Date(status.eventAt), "MMM d 'at' HH:mm"),
|
|
258
|
+
]
|
|
259
|
+
.filter(Boolean)
|
|
260
|
+
.join(" · ")}
|
|
261
|
+
</p>
|
|
262
|
+
)}
|
|
263
|
+
</div>
|
|
264
|
+
</div>
|
|
265
|
+
);
|
|
266
|
+
})}
|
|
267
|
+
</div>
|
|
268
|
+
)}
|
|
269
|
+
</DropdownMenuContent>
|
|
270
|
+
</DropdownMenu>
|
|
271
|
+
);
|
|
272
|
+
}
|