@open-workspace/email 0.4.2 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/alchemy/index.ts +130 -2
- package/drizzle/mailbox/0003_after_0_4_2.sql +180 -0
- package/drizzle/mailbox/meta/0003_snapshot.json +1507 -0
- package/drizzle/mailbox/meta/_journal.json +7 -0
- package/drizzle/mailbox/migrations.js +3 -1
- package/migrations/0002_after_0_4_2.sql +35 -0
- package/migrations/meta/0002_snapshot.json +807 -0
- package/migrations/meta/_journal.json +7 -0
- package/package.json +23 -7
- package/shared/attachment-preview.ts +18 -8
- package/shared/folder-order.ts +31 -6
- package/shared/mail-headers.ts +3 -3
- package/shared/mail-html.ts +25 -0
- package/shared/mail-import.ts +0 -7
- package/shared/mail-received.ts +4 -4
- package/shared/mail-rule-actions.ts +47 -0
- package/shared/mail-sender-intel.ts +5 -1
- package/shared/mail.ts +70 -4
- package/shared/office-preview.ts +0 -4
- package/shared/pdfjs-assets.ts +1 -3
- package/shared/rich-content.ts +35 -0
- package/shared/signature.ts +15 -0
- package/src/admin/address-auto-reply.tsx +52 -0
- package/src/admin/blocked-senders.tsx +86 -66
- package/src/admin/forward-destinations.tsx +140 -0
- package/src/admin/mail-archive.tsx +134 -0
- package/src/admin/team-signature.tsx +90 -0
- package/src/client.tsx +130 -16
- package/src/mail/attachment-preview-dialog.tsx +13 -5
- package/src/mail/auto-reply-banner.tsx +61 -0
- package/src/mail/blocked-senders.tsx +124 -91
- package/src/mail/compose-window-chrome.tsx +20 -8
- package/src/mail/compose-window.tsx +391 -365
- package/src/mail/composer-asset-bookmarks.ts +47 -12
- package/src/mail/composer-attachment-list.tsx +42 -17
- package/src/mail/composer-editor-document.ts +54 -10
- package/src/mail/composer-editor.tsx +44 -44
- package/src/mail/composer-link-text.ts +42 -0
- package/src/mail/composer-recipient-fields.tsx +25 -16
- package/src/mail/composer-recipients.ts +62 -16
- package/src/mail/composer-session.ts +107 -23
- package/src/mail/composer-toolbar.tsx +15 -1
- package/src/mail/composer-upload-client.ts +29 -1
- package/src/mail/composer-upload-progress.ts +2 -2
- package/src/mail/conversation-actions-model.ts +56 -0
- package/src/mail/conversation-list.tsx +263 -128
- package/src/mail/conversation-loading-skeleton.tsx +165 -90
- package/src/mail/conversation-message.tsx +257 -102
- package/src/mail/conversation-order.ts +12 -0
- package/src/mail/conversation-reply.tsx +313 -189
- package/src/mail/conversation-selection-toolbar.tsx +188 -143
- package/src/mail/conversation-view.tsx +315 -85
- package/src/mail/delivery-indicator.tsx +33 -12
- package/src/mail/draft-attachments.ts +194 -0
- package/src/mail/email-html-body.tsx +97 -53
- package/src/mail/folder-cleanup-bar.tsx +193 -0
- package/src/mail/folder-glyph.tsx +5 -0
- package/src/mail/folder-manager.tsx +71 -38
- package/src/mail/mail-app-bar.tsx +15 -3
- package/src/mail/mail-dock.tsx +19 -3
- package/src/mail/mail-focus.ts +48 -0
- package/src/mail/mail-folders.ts +14 -2
- package/src/mail/mail-layout.css +20 -0
- package/src/mail/mail-mailbox-sheet.tsx +22 -69
- package/src/mail/mail-nav-rail.tsx +7 -4
- package/src/mail/mail-nav.tsx +66 -46
- package/src/mail/mail-prefetch.ts +30 -9
- package/src/mail/mail-primitives.tsx +6 -4
- package/src/mail/mail-queries.ts +122 -20
- package/src/mail/mail-query-cache.ts +1085 -173
- package/src/mail/mail-search-params.ts +35 -0
- package/src/mail/mail-shell.tsx +32 -9
- package/src/mail/mailbox-ai-settings.tsx +56 -42
- package/src/mail/mailbox-realtime.tsx +4 -12
- package/src/mail/mailbox-rules.tsx +898 -0
- package/src/mail/message-actions.tsx +38 -26
- package/src/mail/message-attachments.tsx +20 -12
- package/src/mail/message-body.ts +53 -0
- package/src/mail/message-format.ts +8 -2
- package/src/mail/message-header.tsx +3 -1
- package/src/mail/message-translation.tsx +34 -67
- package/src/mail/original-message-sheet.tsx +63 -50
- package/src/mail/original-message.ts +6 -6
- package/src/mail/pane-splitter.tsx +3 -3
- package/src/mail/pdf-preview.tsx +70 -62
- package/src/mail/plain-message-text.tsx +28 -0
- package/src/mail/print-message.ts +31 -36
- package/src/mail/reader-pane.tsx +134 -103
- package/src/mail/recipient-combobox.tsx +52 -29
- package/src/mail/recipient-field-row.tsx +3 -0
- package/src/mail/rich-content.ts +128 -0
- package/src/mail/sanitize-email-html.ts +53 -32
- package/src/mail/sender-actions.tsx +48 -46
- package/src/mail/sender-authentication.tsx +1 -1
- package/src/mail/sender-dialogs.tsx +67 -43
- package/src/mail/sender-security.tsx +12 -11
- package/src/mail/signature.ts +43 -0
- package/src/mail/translation-html.ts +3 -3
- package/src/mail/types.ts +12 -0
- package/src/mail/use-composer-attachment-preflight.ts +23 -60
- package/src/mail/use-composer-core.ts +286 -0
- package/src/mail/use-composer-navigation.ts +120 -0
- package/src/mail/use-composer-submission.ts +154 -19
- package/src/mail/use-conversation-actions.ts +292 -0
- package/src/mail/use-conversation-position.ts +51 -0
- package/src/mail/use-conversation-selection.ts +192 -89
- package/src/mail/use-draft-autosave.ts +394 -0
- package/src/mail/use-drafts.ts +194 -0
- package/src/mail/use-mail-controller.ts +758 -213
- package/src/mail/use-mail-data.ts +210 -100
- package/src/mail/use-mail-safety.ts +19 -38
- package/src/mail/use-mail-send.ts +18 -6
- package/src/mail/use-pdf-translation.ts +1 -1
- package/src/mail/use-reply-cc.ts +61 -0
- package/src/mail/use-visible-message-read.ts +128 -64
- package/src/pwa/push-key.ts +18 -0
- package/src/pwa/push-subscription.ts +88 -26
- package/src/settings/auto-reply-editor.tsx +454 -0
- package/src/settings/auto-reply-page.tsx +59 -0
- package/src/settings/mail-apps-page.tsx +52 -43
- package/src/settings/notifications-page.tsx +82 -67
- package/src/settings/rich-content-editor.tsx +182 -0
- package/src/settings/settings-queries.ts +57 -0
- package/src/settings/signature-editor.tsx +142 -0
- package/src/settings/signature-page.tsx +70 -0
- package/worker/admin/blocked-sender-routes.ts +10 -16
- package/worker/backups/eml.ts +185 -0
- package/worker/backups/file-parts.ts +140 -0
- package/worker/backups/mail-backup.ts +644 -0
- package/worker/backups/settings-backup.ts +866 -0
- package/worker/backups/stream-eml.ts +73 -0
- package/worker/db/schema.ts +89 -5
- package/worker/jmap/attachment-blobs.ts +113 -0
- package/worker/jmap/blobs.ts +162 -0
- package/worker/jmap/draft-content.ts +42 -0
- package/worker/jmap/drafts.ts +70 -0
- package/worker/jmap/email-body.ts +152 -0
- package/worker/jmap/email-methods.ts +1223 -0
- package/worker/jmap/eventsource.ts +9 -8
- package/worker/jmap/import-methods.ts +205 -0
- package/worker/jmap/mailbox-methods.ts +187 -0
- package/worker/jmap/method-core.ts +379 -0
- package/worker/jmap/methods.ts +119 -1816
- package/worker/jmap/push-subscription-methods.ts +373 -0
- package/worker/jmap/push-types.ts +46 -2
- package/worker/jmap/push.ts +24 -31
- package/worker/jmap/routes.ts +144 -153
- package/worker/jmap/submission-methods.ts +395 -0
- package/worker/mail/access.ts +35 -12
- package/worker/mail/ai-classification.ts +2 -2
- package/worker/mail/archive-object.ts +96 -0
- package/worker/mail/archive-routes.ts +35 -0
- package/worker/mail/archive.ts +700 -0
- package/worker/mail/auth-headers.ts +57 -43
- package/worker/mail/auto-reply-routes.ts +260 -0
- package/worker/mail/auto-reply.ts +243 -0
- package/worker/mail/bimi.ts +53 -36
- package/worker/mail/bootstrap.ts +11 -3
- package/worker/mail/capabilities.ts +69 -0
- package/worker/mail/classification-signals.ts +1 -1
- package/worker/mail/confusables-data.ts +9 -0
- package/worker/mail/conversation-cursor.ts +6 -15
- package/worker/mail/delivery-events.ts +9 -7
- package/worker/mail/delivery-facts.ts +1 -1
- package/worker/mail/demo-routes.ts +3 -3
- package/worker/mail/doh.ts +3 -3
- package/worker/mail/download-links.ts +153 -0
- package/worker/mail/downloads.ts +2 -6
- package/worker/mail/draft-routes.ts +473 -0
- package/worker/mail/draft-sender.ts +54 -0
- package/worker/mail/edge-cache.ts +41 -55
- package/worker/mail/email-routing.ts +123 -0
- package/worker/mail/forward-destinations.ts +114 -0
- package/worker/mail/forward-downloads.ts +115 -0
- package/worker/mail/forward-html.ts +85 -0
- package/worker/mail/header-metadata.ts +2 -5
- package/worker/mail/impersonation.ts +102 -101
- package/worker/mail/import-routes.ts +29 -82
- package/worker/mail/import.ts +130 -0
- package/worker/mail/inbound-delivery.ts +6 -5
- package/worker/mail/inbound-threading.ts +15 -2
- package/worker/mail/inbound.ts +58 -28
- package/worker/mail/ip-intel.ts +8 -17
- package/worker/mail/isolate-cache.ts +1 -1
- package/worker/mail/mailbox-deletion.ts +33 -12
- package/worker/mail/mailbox-directory.ts +39 -65
- package/worker/mail/mailing-list.ts +29 -58
- package/worker/mail/message-security.ts +19 -8
- package/worker/mail/message-view.ts +12 -10
- package/worker/mail/office-conversion.ts +3 -5
- package/worker/mail/office-preview-container.ts +3 -8
- package/worker/mail/outbound-content.ts +139 -65
- package/worker/mail/outbound-delivery.ts +20 -17
- package/worker/mail/outbound-service.ts +34 -9
- package/worker/mail/outbound.ts +146 -75
- package/worker/mail/outgoing-context.ts +60 -30
- package/worker/mail/participants.ts +10 -15
- package/worker/mail/plain-body.ts +39 -0
- package/worker/mail/push-endpoint.ts +17 -0
- package/worker/mail/push-notifications.ts +53 -62
- package/worker/mail/quote-parser.ts +36 -24
- package/worker/mail/receive.ts +146 -39
- package/worker/mail/recipients.ts +1 -1
- package/worker/mail/remote-proxy.ts +3 -3
- package/worker/mail/repeat.ts +1 -1
- package/worker/mail/reply-plan.ts +124 -26
- package/worker/mail/rfc.ts +15 -7
- package/worker/mail/rich-content.ts +207 -0
- package/worker/mail/routes.ts +698 -304
- package/worker/mail/routing.ts +274 -0
- package/worker/mail/rules.ts +230 -0
- package/worker/mail/safety-routes.ts +88 -86
- package/worker/mail/schemas.ts +222 -31
- package/worker/mail/search.ts +25 -2
- package/worker/mail/security-settings.ts +4 -10
- package/worker/mail/send-message.ts +238 -0
- package/worker/mail/sender-intel.ts +12 -20
- package/worker/mail/signature-routes.ts +206 -0
- package/worker/mail/signatures.ts +195 -0
- package/worker/mail/spamhaus.ts +28 -16
- package/worker/mail/storage-keys.ts +35 -0
- package/worker/mail/unsubscribe.ts +19 -41
- package/worker/mail/uploads.ts +192 -80
- package/worker/mail/webhook-source.ts +3 -2
- package/worker/mail/workspace-safety.ts +194 -60
- package/worker/mailbox/demo.ts +13 -15
- package/worker/mailbox/email-index.ts +65 -35
- package/worker/mailbox/folder-model.ts +0 -20
- package/worker/mailbox/import-placement.ts +21 -36
- package/worker/mailbox/inbound-decision.ts +114 -0
- package/worker/mailbox/inbox-counts.ts +45 -25
- package/worker/mailbox/index.ts +756 -3201
- package/worker/mailbox/jmap-change-log.ts +195 -0
- package/worker/mailbox/jmap-email-rows.ts +186 -0
- package/worker/mailbox/jmap-mailboxes.ts +116 -0
- package/worker/mailbox/jmap-placement.ts +139 -0
- package/worker/mailbox/jmap-query-filter.ts +231 -0
- package/worker/mailbox/jmap-store.ts +167 -299
- package/worker/mailbox/mailbox-auto-reply.ts +316 -0
- package/worker/mailbox/mailbox-backup.ts +538 -0
- package/worker/mailbox/mailbox-drafts.ts +417 -0
- package/worker/mailbox/mailbox-folders.ts +242 -0
- package/worker/mailbox/mailbox-import.ts +455 -0
- package/worker/mailbox/mailbox-inbound.ts +934 -0
- package/worker/mailbox/mailbox-jmap.ts +294 -0
- package/worker/mailbox/mailbox-outbound.ts +413 -0
- package/worker/mailbox/mailbox-rules.ts +336 -0
- package/worker/mailbox/mailbox-senders.ts +294 -0
- package/worker/mailbox/mailbox-storage.ts +438 -0
- package/worker/mailbox/mailbox-views.ts +891 -0
- package/worker/mailbox/model.ts +1 -0
- package/worker/mailbox/office-preview-jobs.ts +59 -47
- package/worker/mailbox/placement.ts +933 -0
- package/worker/mailbox/restore-thread.ts +52 -0
- package/worker/mailbox/retention.ts +36 -0
- package/worker/mailbox/schema.ts +200 -1
- package/worker/mailbox/senders.ts +216 -178
- package/worker/mailbox/spam-undo-filing.ts +138 -0
- package/worker/mailbox/spam-undo.ts +253 -0
- package/worker/mailbox/support.ts +416 -0
- package/worker/mcp/mail-action-tools.ts +161 -1
- package/worker/mcp/mail-compose-tools.ts +7 -1
- package/worker/mcp/mail-safety-tools.ts +4 -4
- package/worker/module.ts +23 -4
- package/src/mail/use-compose-submission.ts +0 -208
- package/src/mail/use-reply-submission.ts +0 -114
- package/worker/mail/capped-body.ts +0 -36
|
@@ -9,11 +9,6 @@ import {
|
|
|
9
9
|
DropdownMenuItem,
|
|
10
10
|
DropdownMenuLabel,
|
|
11
11
|
DropdownMenuTrigger,
|
|
12
|
-
InputGroup,
|
|
13
|
-
InputGroupAddon,
|
|
14
|
-
InputGroupButton,
|
|
15
|
-
InputGroupText,
|
|
16
|
-
InputGroupTextarea,
|
|
17
12
|
} from "@open-workspace/core/ui";
|
|
18
13
|
import {
|
|
19
14
|
Check,
|
|
@@ -26,51 +21,63 @@ import {
|
|
|
26
21
|
Users,
|
|
27
22
|
X,
|
|
28
23
|
} from "lucide-react";
|
|
29
|
-
import {
|
|
30
|
-
import type {
|
|
24
|
+
import { useImperativeHandle, useState } from "react";
|
|
25
|
+
import type { Ref } from "react";
|
|
26
|
+
import { toast } from "sonner";
|
|
31
27
|
|
|
32
28
|
import { normalizeExternalEmailAddress } from "../../shared/mail";
|
|
33
29
|
import { ComposerAttachmentList } from "./composer-attachment-list";
|
|
30
|
+
import { ComposerEditor } from "./composer-editor";
|
|
31
|
+
import type { ComposerContent } from "./composer-editor";
|
|
32
|
+
import { sentBody } from "./composer-editor-document";
|
|
34
33
|
import {
|
|
34
|
+
draftRecipientAddresses,
|
|
35
35
|
recipientsWithPendingInput,
|
|
36
|
+
recipientField,
|
|
36
37
|
validateComposerRecipients,
|
|
37
38
|
} from "./composer-recipients";
|
|
38
39
|
import type { RecipientFieldValue } from "./composer-recipients";
|
|
39
|
-
import {
|
|
40
|
+
import { notifyOutboundResult } from "./outbound-notification";
|
|
40
41
|
import { RecipientCombobox } from "./recipient-combobox";
|
|
41
42
|
import { ReplyToWarning } from "./reply-to-warning";
|
|
42
|
-
import type {
|
|
43
|
-
Mailbox,
|
|
44
|
-
MessageDetail,
|
|
45
|
-
ReplyAction,
|
|
46
|
-
ReplyActionMode,
|
|
47
|
-
} from "./types";
|
|
43
|
+
import type { Mailbox, ReplySource, ReplyActionMode } from "./types";
|
|
48
44
|
import { useComposerAttachmentPreflight } from "./use-composer-attachment-preflight";
|
|
49
|
-
import {
|
|
50
|
-
import
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
import { useComposerCore } from "./use-composer-core";
|
|
46
|
+
import { useComposerLeaveCheck } from "./use-composer-navigation";
|
|
47
|
+
import {
|
|
48
|
+
hasContentToSend,
|
|
49
|
+
useComposerSubmission,
|
|
50
|
+
} from "./use-composer-submission";
|
|
51
|
+
import { useDraftAutosave } from "./use-draft-autosave";
|
|
52
|
+
import { newDraftId } from "./use-drafts";
|
|
53
|
+
import type { DraftContent, SavedDraft } from "./use-drafts";
|
|
54
|
+
import type { SubmittedMessage } from "./use-mail-send";
|
|
55
|
+
import { useReplyCc } from "./use-reply-cc";
|
|
56
|
+
|
|
57
|
+
export type SentReply = Pick<
|
|
58
|
+
SubmittedMessage,
|
|
59
|
+
"messageId" | "conversationId" | "detached"
|
|
60
|
+
>;
|
|
61
|
+
|
|
62
|
+
/** What the conversation asks the open reply box before replacing it. */
|
|
63
|
+
export type ReplyHandle = {
|
|
64
|
+
/** Something was written: replacing the reply would lose it. */
|
|
65
|
+
hasContent: () => boolean;
|
|
66
|
+
/** Stops saving and deletes its draft. */
|
|
67
|
+
discard: () => Promise<void>;
|
|
68
|
+
};
|
|
53
69
|
|
|
54
70
|
const EMPTY_RECIPIENT_FIELD: RecipientFieldValue = {
|
|
55
71
|
recipients: [],
|
|
56
72
|
input: "",
|
|
57
73
|
};
|
|
58
74
|
|
|
59
|
-
function recipientField(addresses: string[]): RecipientFieldValue {
|
|
60
|
-
return {
|
|
61
|
-
recipients: addresses.map((address) => ({ address, name: null })),
|
|
62
|
-
input: "",
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function recipientAddresses(value: RecipientFieldValue) {
|
|
67
|
-
return recipientsWithPendingInput(value).map(
|
|
68
|
-
(recipient) => recipient.address
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
75
|
function recipientAddressSet(value: RecipientFieldValue) {
|
|
73
|
-
return new Set(
|
|
76
|
+
return new Set(
|
|
77
|
+
recipientsWithPendingInput(value).map(({ address }) =>
|
|
78
|
+
normalizeExternalEmailAddress(address)
|
|
79
|
+
)
|
|
80
|
+
);
|
|
74
81
|
}
|
|
75
82
|
|
|
76
83
|
export function ConversationReply({
|
|
@@ -80,42 +87,66 @@ export function ConversationReply({
|
|
|
80
87
|
onModeChange,
|
|
81
88
|
onCancel,
|
|
82
89
|
onSent,
|
|
90
|
+
draft,
|
|
91
|
+
ref,
|
|
83
92
|
}: {
|
|
84
93
|
mailbox?: Mailbox;
|
|
85
|
-
parent:
|
|
94
|
+
parent: ReplySource;
|
|
86
95
|
mode: ReplyActionMode;
|
|
87
96
|
onModeChange: (mode: ReplyActionMode) => void;
|
|
88
97
|
onCancel: () => void;
|
|
89
98
|
onSent: (result: SentReply) => void;
|
|
99
|
+
/** A saved reply to this message to reopen. */
|
|
100
|
+
draft?: SavedDraft;
|
|
101
|
+
ref?: Ref<ReplyHandle>;
|
|
90
102
|
}) {
|
|
91
|
-
const
|
|
92
|
-
const initialAction = findAction(parent, mode);
|
|
93
|
-
const fieldsSource = `${mode}\0${parent.id}`;
|
|
94
|
-
const [body, setBody] = useState("");
|
|
95
|
-
const [cc, setCc] = useState(() => recipientField(initialAction?.cc ?? []));
|
|
96
|
-
const [bcc, setBcc] = useState<RecipientFieldValue>(EMPTY_RECIPIENT_FIELD);
|
|
97
|
-
const [showCc, setShowCc] = useState(Boolean(initialAction?.cc.length));
|
|
98
|
-
const [showBcc, setShowBcc] = useState(false);
|
|
99
|
-
const [ccSource, setCcSource] = useState(fieldsSource);
|
|
100
|
-
|
|
101
|
-
// Another reply mode or parent message resets Cc to its own; adjusted
|
|
102
|
-
// while rendering, so the old Cc never shows with the new reply.
|
|
103
|
-
if (ccSource !== fieldsSource) {
|
|
104
|
-
setCcSource(fieldsSource);
|
|
105
|
-
setCc(recipientField(initialAction?.cc ?? []));
|
|
106
|
-
setShowCc(Boolean(initialAction?.cc.length));
|
|
107
|
-
}
|
|
103
|
+
const action = findAction(parent, mode);
|
|
108
104
|
|
|
109
|
-
const
|
|
110
|
-
const activeAssets = snapshot.assets;
|
|
111
|
-
const uploadLimitError = session.limitError();
|
|
105
|
+
const core = useComposerCore({ mailbox, draft, signature: "reply" });
|
|
112
106
|
|
|
113
|
-
const
|
|
114
|
-
|
|
107
|
+
const {
|
|
108
|
+
session,
|
|
109
|
+
snapshot,
|
|
110
|
+
editor,
|
|
111
|
+
activeAssets,
|
|
112
|
+
dropProps,
|
|
113
|
+
addFiles,
|
|
114
|
+
statusError,
|
|
115
|
+
attachmentListProps,
|
|
116
|
+
content: reportedContent,
|
|
117
|
+
editorProps,
|
|
118
|
+
fileInput,
|
|
119
|
+
form,
|
|
120
|
+
holdsOnlyOpening,
|
|
121
|
+
inlineFileInput,
|
|
122
|
+
keptAttachments,
|
|
123
|
+
limitError,
|
|
124
|
+
readContent,
|
|
125
|
+
uploadsError,
|
|
126
|
+
uploadsFailed,
|
|
127
|
+
uploadsPending,
|
|
128
|
+
} = core;
|
|
129
|
+
|
|
130
|
+
const initialCc = draft?.cc ?? action?.cc ?? [];
|
|
131
|
+
|
|
132
|
+
const { value: cc, onChange: setCc } = useReplyCc(
|
|
133
|
+
action?.cc ?? [],
|
|
134
|
+
draft?.cc
|
|
115
135
|
);
|
|
116
136
|
|
|
117
|
-
const
|
|
118
|
-
|
|
137
|
+
const initialBcc = draft?.bcc ?? action?.bcc ?? [];
|
|
138
|
+
|
|
139
|
+
const [bcc, setBcc] = useState<RecipientFieldValue>(() =>
|
|
140
|
+
recipientField(initialBcc)
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const [ccOpened, setCcOpened] = useState(Boolean(draft?.cc.length));
|
|
144
|
+
|
|
145
|
+
const showCc = ccOpened || Boolean(action?.cc.length);
|
|
146
|
+
|
|
147
|
+
const [showBcc, setShowBcc] = useState(Boolean(initialBcc.length));
|
|
148
|
+
const ccAddresses = draftRecipientAddresses(cc);
|
|
149
|
+
const bccAddresses = draftRecipientAddresses(bcc);
|
|
119
150
|
|
|
120
151
|
const recipients = validateComposerRecipients({
|
|
121
152
|
to: recipientField(action?.to ?? []),
|
|
@@ -123,42 +154,147 @@ export function ConversationReply({
|
|
|
123
154
|
bcc,
|
|
124
155
|
});
|
|
125
156
|
|
|
157
|
+
const footerError = recipients.feedback ?? statusError;
|
|
158
|
+
|
|
159
|
+
const preflightContext = (content: ComposerContent) => ({
|
|
160
|
+
kind: "reply" as const,
|
|
161
|
+
mailboxId: mailbox?.id ?? "",
|
|
162
|
+
sourceEmailId: parent.id,
|
|
163
|
+
mode: action?.mode ?? mode,
|
|
164
|
+
cc: recipients.cc,
|
|
165
|
+
bcc: recipients.bcc,
|
|
166
|
+
...sentBody(content),
|
|
167
|
+
});
|
|
168
|
+
|
|
126
169
|
useComposerAttachmentPreflight(
|
|
127
170
|
session,
|
|
128
|
-
|
|
129
|
-
kind: "reply",
|
|
130
|
-
mailboxId: mailbox?.id ?? "",
|
|
131
|
-
sourceEmailId: parent.id,
|
|
132
|
-
mode: action?.mode ?? mode,
|
|
133
|
-
cc: recipients.cc,
|
|
134
|
-
bcc: recipients.bcc,
|
|
135
|
-
bodyText: body,
|
|
136
|
-
},
|
|
171
|
+
preflightContext(reportedContent),
|
|
137
172
|
activeAssets,
|
|
138
173
|
snapshot.phase === "editing" && Boolean(mailbox && action)
|
|
139
174
|
);
|
|
140
175
|
|
|
141
|
-
|
|
176
|
+
// One id for the reply box's lifetime: created once, never replaced.
|
|
177
|
+
// oxlint-disable-next-line react/hook-use-state -- the lazy initializer keeps one id; there is nothing to set
|
|
178
|
+
const [draftId] = useState(() => draft?.id ?? newDraftId());
|
|
179
|
+
|
|
180
|
+
const draftContent = (
|
|
181
|
+
body: ComposerContent,
|
|
182
|
+
attachments: DraftContent["attachments"]
|
|
183
|
+
) =>
|
|
184
|
+
({
|
|
185
|
+
kind: "reply",
|
|
186
|
+
sourceEmailId: parent.id,
|
|
187
|
+
conversationId: parent.conversationId,
|
|
188
|
+
replyMode: action?.mode ?? mode,
|
|
189
|
+
// Shown in the drafts list; sending works out the recipients again.
|
|
190
|
+
to: action?.to ?? [],
|
|
191
|
+
cc: ccAddresses,
|
|
192
|
+
bcc: bccAddresses,
|
|
193
|
+
replyTo: null,
|
|
194
|
+
subject: parent.subject,
|
|
195
|
+
bodyText: body.bodyText,
|
|
196
|
+
bodyHtml: body.bodyHtml || null,
|
|
197
|
+
// The editor's HTML, so the reopened editor puts the files back in place.
|
|
198
|
+
editorHtml: body.editorHtml || null,
|
|
199
|
+
attachments,
|
|
200
|
+
storedImages: body.storedImages,
|
|
201
|
+
}) satisfies DraftContent;
|
|
202
|
+
|
|
203
|
+
// Compare against the reply as opened, including recipients supplied by Reply all.
|
|
204
|
+
// oxlint-disable-next-line react/hook-use-state -- the opening is fixed for this editor
|
|
205
|
+
const [opening] = useState(() => ({
|
|
206
|
+
reopened: Boolean(draft),
|
|
207
|
+
mode,
|
|
208
|
+
cc: initialCc,
|
|
209
|
+
bcc: initialBcc,
|
|
210
|
+
}));
|
|
211
|
+
|
|
212
|
+
const untouchedBody = (
|
|
213
|
+
saved: Pick<DraftContent, "bodyText" | "attachments">
|
|
214
|
+
) => !opening.reopened && holdsOnlyOpening(saved);
|
|
215
|
+
|
|
216
|
+
const blank = (saved: Pick<DraftContent, "bodyText" | "attachments">) =>
|
|
217
|
+
untouchedBody(saved) &&
|
|
218
|
+
mode === opening.mode &&
|
|
219
|
+
bccAddresses.length === opening.bcc.length &&
|
|
220
|
+
bccAddresses.every((address, index) => address === opening.bcc[index]) &&
|
|
221
|
+
ccAddresses.length === opening.cc.length &&
|
|
222
|
+
ccAddresses.every((address, index) => address === opening.cc[index]);
|
|
223
|
+
|
|
224
|
+
const autosave = useDraftAutosave({
|
|
225
|
+
mailboxId: mailbox?.id ?? "",
|
|
226
|
+
session,
|
|
227
|
+
draftId,
|
|
228
|
+
restored: draft,
|
|
229
|
+
content: draftContent(reportedContent, keptAttachments()),
|
|
230
|
+
current: () => draftContent(readContent(), keptAttachments()),
|
|
231
|
+
blank,
|
|
232
|
+
editing:
|
|
233
|
+
snapshot.phase === "editing" && Boolean(mailbox?.canSend && action),
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
useComposerLeaveCheck(
|
|
237
|
+
"reply",
|
|
238
|
+
() => core.closeUploadError ?? autosave.beforeLeave()
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
const submission = useComposerSubmission({
|
|
142
242
|
session,
|
|
143
243
|
phase: snapshot.phase,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
244
|
+
editor,
|
|
245
|
+
validate: () =>
|
|
246
|
+
!mailbox?.canSend || !action
|
|
247
|
+
? "Reply is no longer available"
|
|
248
|
+
: (recipients.error ?? uploadsError),
|
|
249
|
+
missingText: (content) => {
|
|
250
|
+
const attachments = keptAttachments();
|
|
251
|
+
|
|
252
|
+
return hasContentToSend(content, attachments, () =>
|
|
253
|
+
untouchedBody({ bodyText: content.bodyText, attachments })
|
|
254
|
+
)
|
|
255
|
+
? null
|
|
256
|
+
: "Add text or a file to the reply before sending";
|
|
257
|
+
},
|
|
258
|
+
context: preflightContext,
|
|
259
|
+
command: (content, uploadedAttachments) => ({
|
|
260
|
+
kind: "reply",
|
|
261
|
+
mailboxId: mailbox?.id ?? "",
|
|
262
|
+
cc: recipients.cc,
|
|
263
|
+
bcc: recipients.bcc,
|
|
264
|
+
...sentBody(content),
|
|
265
|
+
uploadedAttachments,
|
|
266
|
+
parentEmailId: parent.id,
|
|
267
|
+
mode: action?.mode ?? mode,
|
|
268
|
+
}),
|
|
269
|
+
draftForSubmission: autosave.forSubmission,
|
|
270
|
+
failureLabel: "Could not send reply",
|
|
152
271
|
onSuccess: (result) => {
|
|
153
|
-
|
|
272
|
+
notifyOutboundResult(result, "reply");
|
|
273
|
+
autosave.ended();
|
|
154
274
|
setBcc(EMPTY_RECIPIENT_FIELD);
|
|
155
|
-
onSent(
|
|
275
|
+
onSent({
|
|
276
|
+
messageId: result.messageId,
|
|
277
|
+
conversationId: result.conversationId,
|
|
278
|
+
detached: result.detached,
|
|
279
|
+
});
|
|
156
280
|
},
|
|
157
281
|
});
|
|
158
282
|
|
|
283
|
+
// What the reply holds right now, not as of the editor's last report.
|
|
284
|
+
const holdsNothing = () =>
|
|
285
|
+
!activeAssets.length &&
|
|
286
|
+
blank({
|
|
287
|
+
bodyText: readContent().bodyText,
|
|
288
|
+
attachments: keptAttachments(),
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
useImperativeHandle(ref, () => ({
|
|
292
|
+
hasContent: () => !holdsNothing(),
|
|
293
|
+
discard: autosave.discard,
|
|
294
|
+
}));
|
|
295
|
+
|
|
159
296
|
const { busy } = submission;
|
|
160
297
|
const { confirm, dialog: confirmDialog } = useConfirm();
|
|
161
|
-
const linkedIds = snapshot.linkedAssetIds;
|
|
162
298
|
|
|
163
299
|
const toAddresses = new Set(
|
|
164
300
|
(action?.to ?? []).map(normalizeExternalEmailAddress)
|
|
@@ -174,23 +310,14 @@ export function ConversationReply({
|
|
|
174
310
|
...recipientAddressSet(cc),
|
|
175
311
|
]);
|
|
176
312
|
|
|
177
|
-
if (!mailbox?.canSend || !action
|
|
178
|
-
|
|
179
|
-
function selectAction(next: ReplyAction) {
|
|
180
|
-
onModeChange(next.mode);
|
|
181
|
-
setCc(recipientField(next.cc));
|
|
182
|
-
setShowCc(next.cc.length > 0);
|
|
183
|
-
}
|
|
313
|
+
if (!mailbox?.canSend || !action) return null;
|
|
184
314
|
|
|
185
315
|
async function cancel() {
|
|
186
316
|
if (
|
|
187
|
-
(
|
|
317
|
+
!holdsNothing() &&
|
|
188
318
|
!(await confirm({
|
|
189
319
|
title: "Discard this reply?",
|
|
190
|
-
description:
|
|
191
|
-
activeAssets.length > 0
|
|
192
|
-
? "The text you wrote and its attachments are deleted."
|
|
193
|
-
: "The text you wrote is deleted.",
|
|
320
|
+
description: "The draft and any attachments will be deleted.",
|
|
194
321
|
action: "Discard reply",
|
|
195
322
|
destructive: true,
|
|
196
323
|
}))
|
|
@@ -198,15 +325,17 @@ export function ConversationReply({
|
|
|
198
325
|
return;
|
|
199
326
|
}
|
|
200
327
|
|
|
201
|
-
|
|
202
|
-
|
|
328
|
+
try {
|
|
329
|
+
await autosave.discard();
|
|
330
|
+
} catch (error) {
|
|
331
|
+
toast.error(
|
|
332
|
+
error instanceof Error ? error.message : "Could not discard the draft"
|
|
333
|
+
);
|
|
203
334
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
event.preventDefault();
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
207
337
|
|
|
208
|
-
|
|
209
|
-
session.addFiles(Array.from(event.dataTransfer.files), "attachment");
|
|
338
|
+
onCancel();
|
|
210
339
|
}
|
|
211
340
|
|
|
212
341
|
return (
|
|
@@ -214,14 +343,14 @@ export function ConversationReply({
|
|
|
214
343
|
{confirmDialog}
|
|
215
344
|
{/* oxlint-disable-next-line jsx-a11y/no-noninteractive-element-interactions -- files can be dropped anywhere on the form */}
|
|
216
345
|
<form
|
|
346
|
+
ref={form}
|
|
217
347
|
className="animate-rise border-input bg-surface focus-within:border-ring/60 focus-within:ring-ring/12 overflow-hidden rounded-lg border shadow-sm transition-shadow focus-within:ring-3"
|
|
218
348
|
aria-busy={busy}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
onDrop={handleDrop}
|
|
349
|
+
onDragEnter={dropProps.onDragEnter}
|
|
350
|
+
onDragOver={dropProps.onDragOver}
|
|
351
|
+
onDragLeave={dropProps.onDragLeave}
|
|
352
|
+
onDragEnd={dropProps.onDragEnd}
|
|
353
|
+
onDrop={dropProps.onDrop}
|
|
225
354
|
onSubmit={(event) => {
|
|
226
355
|
event.preventDefault();
|
|
227
356
|
void submission.submit();
|
|
@@ -256,7 +385,7 @@ export function ConversationReply({
|
|
|
256
385
|
<DropdownMenuItem
|
|
257
386
|
key={candidate.mode}
|
|
258
387
|
disabled={busy}
|
|
259
|
-
onClick={() =>
|
|
388
|
+
onClick={() => onModeChange(candidate.mode)}
|
|
260
389
|
>
|
|
261
390
|
<ReplyActionIcon mode={candidate.mode} />
|
|
262
391
|
<span className="min-w-0 flex-1">
|
|
@@ -285,7 +414,7 @@ export function ConversationReply({
|
|
|
285
414
|
size="xs"
|
|
286
415
|
className="text-muted-foreground"
|
|
287
416
|
disabled={busy}
|
|
288
|
-
onClick={() =>
|
|
417
|
+
onClick={() => setCcOpened(true)}
|
|
289
418
|
>
|
|
290
419
|
Cc
|
|
291
420
|
</Button>
|
|
@@ -338,7 +467,10 @@ export function ConversationReply({
|
|
|
338
467
|
value={cc}
|
|
339
468
|
excludedAddresses={ccExcludedAddresses}
|
|
340
469
|
disabled={busy}
|
|
341
|
-
onChange={
|
|
470
|
+
onChange={(value) => {
|
|
471
|
+
setCcOpened(true);
|
|
472
|
+
setCc(value);
|
|
473
|
+
}}
|
|
342
474
|
/>
|
|
343
475
|
</div>
|
|
344
476
|
)}
|
|
@@ -355,101 +487,93 @@ export function ConversationReply({
|
|
|
355
487
|
</div>
|
|
356
488
|
)}
|
|
357
489
|
|
|
358
|
-
<
|
|
359
|
-
<
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
onChange={(event) => setBody(event.target.value)}
|
|
364
|
-
onKeyDown={(event) => {
|
|
365
|
-
if (
|
|
366
|
-
!busy &&
|
|
367
|
-
(event.metaKey || event.ctrlKey) &&
|
|
368
|
-
event.key === "Enter" &&
|
|
369
|
-
(body.trim() || activeAssets.length > 0)
|
|
370
|
-
) {
|
|
371
|
-
event.preventDefault();
|
|
372
|
-
void submission.submit();
|
|
373
|
-
}
|
|
374
|
-
}}
|
|
490
|
+
<div className="flex h-64 flex-col">
|
|
491
|
+
<ComposerEditor
|
|
492
|
+
ref={editor}
|
|
493
|
+
{...editorProps}
|
|
494
|
+
label="Reply"
|
|
375
495
|
placeholder={
|
|
376
496
|
action.mode === "reply_all"
|
|
377
497
|
? "Reply to everyone"
|
|
378
|
-
:
|
|
498
|
+
: action.to.length
|
|
499
|
+
? `Reply to ${action.to.join(", ")}`
|
|
500
|
+
: "Write a reply"
|
|
379
501
|
}
|
|
380
502
|
/>
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
503
|
+
</div>
|
|
504
|
+
<div className="border-border text-muted-foreground flex items-center gap-2 border-t px-2 py-1.5 text-sm">
|
|
505
|
+
<input
|
|
506
|
+
ref={fileInput}
|
|
507
|
+
className="sr-only"
|
|
508
|
+
type="file"
|
|
509
|
+
multiple
|
|
510
|
+
disabled={busy}
|
|
511
|
+
onChange={(event) => {
|
|
512
|
+
addFiles(Array.from(event.target.files ?? []), "attachment");
|
|
513
|
+
event.target.value = "";
|
|
514
|
+
}}
|
|
515
|
+
/>
|
|
516
|
+
<input
|
|
517
|
+
ref={inlineFileInput}
|
|
518
|
+
className="sr-only"
|
|
519
|
+
type="file"
|
|
520
|
+
accept="image/png,image/jpeg,image/gif,image/webp"
|
|
521
|
+
multiple
|
|
522
|
+
tabIndex={-1}
|
|
523
|
+
aria-hidden
|
|
524
|
+
disabled={busy}
|
|
525
|
+
onChange={(event) => {
|
|
526
|
+
addFiles(Array.from(event.target.files ?? []), "inline");
|
|
527
|
+
event.target.value = "";
|
|
528
|
+
}}
|
|
529
|
+
/>
|
|
530
|
+
<Button
|
|
531
|
+
type="button"
|
|
532
|
+
variant="ghost"
|
|
533
|
+
size="icon-sm"
|
|
534
|
+
disabled={busy}
|
|
535
|
+
onClick={() => fileInput.current?.click()}
|
|
384
536
|
>
|
|
385
|
-
<
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
) : (
|
|
419
|
-
<span className="hidden sm:inline">Ctrl + Enter to send</span>
|
|
420
|
-
))}
|
|
421
|
-
</InputGroupText>
|
|
422
|
-
<Button
|
|
423
|
-
type="submit"
|
|
424
|
-
size="sm"
|
|
425
|
-
disabled={
|
|
426
|
-
busy ||
|
|
427
|
-
Boolean(uploadLimitError) ||
|
|
428
|
-
uploadsPending ||
|
|
429
|
-
uploadsFailed
|
|
430
|
-
}
|
|
431
|
-
>
|
|
432
|
-
{busy ? <LoaderCircle className="animate-spin" /> : <Send />}
|
|
433
|
-
Send
|
|
434
|
-
</Button>
|
|
435
|
-
</InputGroupAddon>
|
|
436
|
-
</InputGroup>
|
|
437
|
-
|
|
438
|
-
<ComposerAttachmentList
|
|
439
|
-
uploads={activeAssets}
|
|
440
|
-
linkedIds={linkedIds}
|
|
441
|
-
progress={session.progress}
|
|
442
|
-
disabled={busy}
|
|
443
|
-
onRemove={(asset) => session.remove(asset.id)}
|
|
444
|
-
onRetry={(asset) => void session.retry(asset.id)}
|
|
445
|
-
/>
|
|
537
|
+
<Paperclip />
|
|
538
|
+
<span className="sr-only">Add attachments</span>
|
|
539
|
+
</Button>
|
|
540
|
+
<span
|
|
541
|
+
className={cn(
|
|
542
|
+
"min-w-0 flex-1 text-xs",
|
|
543
|
+
footerError && "text-destructive"
|
|
544
|
+
)}
|
|
545
|
+
>
|
|
546
|
+
{footerError ??
|
|
547
|
+
(activeAssets.length ? (
|
|
548
|
+
`${activeAssets.length} attachment${activeAssets.length === 1 ? "" : "s"}`
|
|
549
|
+
) : (
|
|
550
|
+
<span className="hidden sm:inline">Ctrl + Enter to send</span>
|
|
551
|
+
))}
|
|
552
|
+
</span>
|
|
553
|
+
<Button
|
|
554
|
+
type="submit"
|
|
555
|
+
size="sm"
|
|
556
|
+
disabled={
|
|
557
|
+
busy ||
|
|
558
|
+
Boolean(recipients.error) ||
|
|
559
|
+
Boolean(limitError) ||
|
|
560
|
+
uploadsPending ||
|
|
561
|
+
uploadsFailed
|
|
562
|
+
}
|
|
563
|
+
>
|
|
564
|
+
{busy ? <LoaderCircle className="animate-spin" /> : <Send />}
|
|
565
|
+
Send
|
|
566
|
+
</Button>
|
|
567
|
+
</div>
|
|
568
|
+
|
|
569
|
+
<ComposerAttachmentList {...attachmentListProps} />
|
|
446
570
|
</form>
|
|
447
571
|
</div>
|
|
448
572
|
);
|
|
449
573
|
}
|
|
450
574
|
|
|
451
575
|
/** The plan's action for the mode, else its default; none for an empty plan. */
|
|
452
|
-
function findAction(parent:
|
|
576
|
+
function findAction(parent: ReplySource, requestedMode: ReplyActionMode) {
|
|
453
577
|
return (
|
|
454
578
|
parent.replyPlan.actions.find((action) => action.mode === requestedMode) ??
|
|
455
579
|
parent.replyPlan.actions.find(
|