@open-workspace/email 0.4.2 → 0.5.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 +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.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 +49 -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 +387 -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 +9 -10
- 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 +754 -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 +108 -1815
- 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 +682 -0
- package/worker/mail/auth-headers.ts +48 -40
- package/worker/mail/auto-reply-routes.ts +255 -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.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 +3 -3
- 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 +696 -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 +201 -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 +301 -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 +450 -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 +240 -0
- package/worker/mailbox/support.ts +416 -0
- package/worker/mcp/mail-action-tools.ts +156 -0
- 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
|
@@ -16,9 +16,7 @@ export type RecipientFieldValue = {
|
|
|
16
16
|
|
|
17
17
|
export const RECIPIENT_SEPARATOR = /[,;\n]/u;
|
|
18
18
|
|
|
19
|
-
export function normalizeComposerRecipient(
|
|
20
|
-
recipient: ComposerRecipient
|
|
21
|
-
): ComposerRecipient | null {
|
|
19
|
+
export function normalizeComposerRecipient(recipient: ComposerRecipient) {
|
|
22
20
|
const address = normalizeExternalEmailAddress(recipient.address);
|
|
23
21
|
|
|
24
22
|
if (!isValidExternalEmailAddress(address)) return null;
|
|
@@ -29,7 +27,7 @@ export function normalizeComposerRecipient(
|
|
|
29
27
|
};
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
function recipientFromText(value: string)
|
|
30
|
+
function recipientFromText(value: string) {
|
|
33
31
|
const trimmed = value.trim();
|
|
34
32
|
|
|
35
33
|
if (!trimmed) return null;
|
|
@@ -109,8 +107,36 @@ export function parseComposerRecipients(value: string) {
|
|
|
109
107
|
return { recipients, invalidParts };
|
|
110
108
|
}
|
|
111
109
|
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
/** Drafts also hold unfinished addresses so they can be edited after reopening. */
|
|
111
|
+
export function recipientField(addresses: readonly string[]) {
|
|
112
|
+
const recipients: ComposerRecipient[] = [];
|
|
113
|
+
const unfinished: string[] = [];
|
|
114
|
+
|
|
115
|
+
for (const address of addresses) {
|
|
116
|
+
const recipient = recipientFromText(address);
|
|
117
|
+
|
|
118
|
+
if (recipient) recipients.push(recipient);
|
|
119
|
+
else unfinished.push(address);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return { recipients, input: unfinished.join(", ") };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function draftRecipientAddresses(value: RecipientFieldValue) {
|
|
126
|
+
const { recipients, invalidParts } = parseComposerRecipients(value.input);
|
|
127
|
+
|
|
128
|
+
return [
|
|
129
|
+
...recipientsWithPendingInput(value, recipients).map(
|
|
130
|
+
(recipient) => recipient.address
|
|
131
|
+
),
|
|
132
|
+
...invalidParts,
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function recipientsWithPendingInput(
|
|
137
|
+
value: RecipientFieldValue,
|
|
138
|
+
pending = parseComposerRecipients(value.input).recipients
|
|
139
|
+
) {
|
|
114
140
|
const seen = new Set<string>();
|
|
115
141
|
|
|
116
142
|
return [...value.recipients, ...pending].filter((recipient) => {
|
|
@@ -136,16 +162,23 @@ export type ValidatedComposerRecipients = {
|
|
|
136
162
|
error: string | null;
|
|
137
163
|
};
|
|
138
164
|
|
|
165
|
+
const recipientErrors = {
|
|
166
|
+
address: "Check the recipient addresses",
|
|
167
|
+
empty: "Add at least one recipient in To, Cc, or Bcc",
|
|
168
|
+
limit: `Use at most ${MAX_MAIL_RECIPIENTS} recipients across To, Cc, and Bcc`,
|
|
169
|
+
replyTo: "Check the Reply-to address",
|
|
170
|
+
} as const;
|
|
171
|
+
|
|
139
172
|
export function validateComposerRecipients(input: {
|
|
140
173
|
to: RecipientFieldValue;
|
|
141
174
|
cc: RecipientFieldValue;
|
|
142
175
|
bcc: RecipientFieldValue;
|
|
143
176
|
replyTo?: string;
|
|
144
|
-
})
|
|
177
|
+
}) {
|
|
145
178
|
const fields = [input.to, input.cc, input.bcc] as const;
|
|
146
179
|
|
|
147
180
|
if (fields.some(hasInvalidRecipientInput)) {
|
|
148
|
-
return invalidRecipients("
|
|
181
|
+
return invalidRecipients("address");
|
|
149
182
|
}
|
|
150
183
|
|
|
151
184
|
let invalidCommittedAddress = false;
|
|
@@ -172,15 +205,17 @@ export function validateComposerRecipients(input: {
|
|
|
172
205
|
const bcc = take(input.bcc);
|
|
173
206
|
|
|
174
207
|
if (invalidCommittedAddress) {
|
|
175
|
-
return invalidRecipients("
|
|
208
|
+
return invalidRecipients("address");
|
|
176
209
|
}
|
|
177
210
|
|
|
178
211
|
const count = to.length + cc.length + bcc.length;
|
|
179
212
|
|
|
213
|
+
if (count === 0) {
|
|
214
|
+
return invalidRecipients("empty");
|
|
215
|
+
}
|
|
216
|
+
|
|
180
217
|
if (count > MAX_MAIL_RECIPIENTS) {
|
|
181
|
-
return invalidRecipients(
|
|
182
|
-
`Use at most ${MAX_MAIL_RECIPIENTS} recipients across To, Cc, and Bcc`
|
|
183
|
-
);
|
|
218
|
+
return invalidRecipients("limit");
|
|
184
219
|
}
|
|
185
220
|
|
|
186
221
|
const rawReplyTo = input.replyTo?.trim() ?? "";
|
|
@@ -190,19 +225,30 @@ export function validateComposerRecipients(input: {
|
|
|
190
225
|
: undefined;
|
|
191
226
|
|
|
192
227
|
if (replyTo && !isValidExternalEmailAddress(replyTo)) {
|
|
193
|
-
return invalidRecipients("
|
|
228
|
+
return invalidRecipients("replyTo");
|
|
194
229
|
}
|
|
195
230
|
|
|
196
|
-
return {
|
|
231
|
+
return {
|
|
232
|
+
to,
|
|
233
|
+
cc,
|
|
234
|
+
bcc,
|
|
235
|
+
replyTo,
|
|
236
|
+
count,
|
|
237
|
+
issue: null,
|
|
238
|
+
error: null,
|
|
239
|
+
feedback: null,
|
|
240
|
+
};
|
|
197
241
|
}
|
|
198
242
|
|
|
199
|
-
function invalidRecipients(
|
|
243
|
+
function invalidRecipients(issue: keyof typeof recipientErrors) {
|
|
200
244
|
return {
|
|
201
245
|
to: [],
|
|
202
246
|
cc: [],
|
|
203
247
|
bcc: [],
|
|
204
248
|
replyTo: undefined,
|
|
205
249
|
count: 0,
|
|
206
|
-
|
|
250
|
+
issue,
|
|
251
|
+
error: recipientErrors[issue],
|
|
252
|
+
feedback: issue === "empty" ? null : recipientErrors[issue],
|
|
207
253
|
};
|
|
208
254
|
}
|
|
@@ -57,16 +57,30 @@ export function isComposerSessionBusy(phase: ComposerSessionPhase) {
|
|
|
57
57
|
return phase === "preflighting" || phase === "submitting";
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
export type ForwardedAttachment = {
|
|
61
|
+
id: string;
|
|
62
|
+
filename: string;
|
|
63
|
+
size: number;
|
|
64
|
+
};
|
|
65
|
+
|
|
60
66
|
type ComposerSessionSnapshot = {
|
|
67
|
+
forwardedAttachments: readonly ForwardedAttachment[];
|
|
68
|
+
/** Every asset still held, including those removed but kept for undo. */
|
|
61
69
|
assets: readonly ComposerAsset[];
|
|
70
|
+
/**
|
|
71
|
+
* The assets the message holds: those the editor's document refers to.
|
|
72
|
+
* Only these count against the limits, are saved and are sent.
|
|
73
|
+
*/
|
|
74
|
+
documentAssetIds: ReadonlySet<string>;
|
|
62
75
|
phase: ComposerSessionPhase;
|
|
63
76
|
planError: boolean;
|
|
64
77
|
linkedAssetIds: ReadonlySet<string>;
|
|
78
|
+
linkedForwardedIds: ReadonlySet<string>;
|
|
65
79
|
};
|
|
66
80
|
|
|
67
81
|
type Listener = () => void;
|
|
68
82
|
|
|
69
|
-
const
|
|
83
|
+
const NO_FORWARDED_FILES: readonly ForwardedAttachment[] = [];
|
|
70
84
|
const EMPTY_LINKED_ASSETS: ReadonlySet<string> = new Set();
|
|
71
85
|
|
|
72
86
|
/**
|
|
@@ -77,10 +91,13 @@ export class ComposerSession {
|
|
|
77
91
|
readonly progress = createComposerUploadProgressStore();
|
|
78
92
|
|
|
79
93
|
private snapshot: ComposerSessionSnapshot = {
|
|
94
|
+
forwardedAttachments: NO_FORWARDED_FILES,
|
|
80
95
|
assets: [],
|
|
96
|
+
documentAssetIds: EMPTY_LINKED_ASSETS,
|
|
81
97
|
phase: "editing",
|
|
82
98
|
planError: false,
|
|
83
99
|
linkedAssetIds: EMPTY_LINKED_ASSETS,
|
|
100
|
+
linkedForwardedIds: EMPTY_LINKED_ASSETS,
|
|
84
101
|
};
|
|
85
102
|
private readonly listeners = new Set<Listener>();
|
|
86
103
|
private readonly files = new Map<string, File>();
|
|
@@ -88,19 +105,38 @@ export class ComposerSession {
|
|
|
88
105
|
private readonly operations = new Map<string, string>();
|
|
89
106
|
private claimedAssetIds: ReadonlySet<string> = EMPTY_LINKED_ASSETS;
|
|
90
107
|
private planKey: string | null = null;
|
|
108
|
+
private planReady = false;
|
|
91
109
|
private submissionAttempt: { id: string; key: string } | null = null;
|
|
92
110
|
private owners = 0;
|
|
93
111
|
private disposed = false;
|
|
94
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Whether closing keeps finished uploads, because a draft holds (or is
|
|
115
|
+
* about to copy) them. Unkept uploads expire with `composer-uploads/`.
|
|
116
|
+
*/
|
|
117
|
+
private retainUploads = false;
|
|
118
|
+
|
|
95
119
|
constructor(
|
|
96
120
|
readonly mailboxId: string,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
) {
|
|
121
|
+
forwardedAttachments: readonly ForwardedAttachment[] = NO_FORWARDED_FILES,
|
|
122
|
+
/** Uploaded assets a reopened draft brings back. */
|
|
123
|
+
restoredAssets: readonly ComposerAsset[] = []
|
|
124
|
+
) {
|
|
125
|
+
this.snapshot = {
|
|
126
|
+
...this.snapshot,
|
|
127
|
+
assets: restoredAssets,
|
|
128
|
+
forwardedAttachments,
|
|
129
|
+
// The editor bookmarks every asset it opens with.
|
|
130
|
+
documentAssetIds: new Set(restoredAssets.map((asset) => asset.id)),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
101
133
|
|
|
102
134
|
getSnapshot = () => this.snapshot;
|
|
103
135
|
|
|
136
|
+
setRetainUploads(retain: boolean) {
|
|
137
|
+
this.retainUploads = retain;
|
|
138
|
+
}
|
|
139
|
+
|
|
104
140
|
subscribe = (listener: Listener) => {
|
|
105
141
|
this.listeners.add(listener);
|
|
106
142
|
|
|
@@ -126,17 +162,39 @@ export class ComposerSession {
|
|
|
126
162
|
return this.snapshot.linkedAssetIds.has(id);
|
|
127
163
|
}
|
|
128
164
|
|
|
165
|
+
/** The assets the message holds (documentAssetIds), in upload order. */
|
|
166
|
+
documentAssets() {
|
|
167
|
+
const { assets, documentAssetIds } = this.snapshot;
|
|
168
|
+
|
|
169
|
+
return assets.filter((asset) => documentAssetIds.has(asset.id));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The editor's document now refers to these assets. */
|
|
173
|
+
setDocumentAssetIds = (assetIds: readonly string[]) => {
|
|
174
|
+
const next = new Set(assetIds);
|
|
175
|
+
|
|
176
|
+
if (setsEqual(next, this.snapshot.documentAssetIds)) return;
|
|
177
|
+
this.publish({ ...this.snapshot, documentAssetIds: next });
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
removeForwardedAttachment(id: string) {
|
|
181
|
+
if (this.snapshot.phase !== "editing") return;
|
|
182
|
+
this.publish({
|
|
183
|
+
...this.snapshot,
|
|
184
|
+
forwardedAttachments: this.snapshot.forwardedAttachments.filter(
|
|
185
|
+
(file) => file.id !== id
|
|
186
|
+
),
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
129
190
|
limitError() {
|
|
130
191
|
return composerAttachmentLimitError([
|
|
131
|
-
...this.
|
|
132
|
-
...this.
|
|
192
|
+
...this.documentAssets(),
|
|
193
|
+
...this.snapshot.forwardedAttachments,
|
|
133
194
|
]);
|
|
134
195
|
}
|
|
135
196
|
|
|
136
|
-
addFiles(
|
|
137
|
-
selected: Iterable<File>,
|
|
138
|
-
intent: ComposerAssetIntent
|
|
139
|
-
): ComposerAsset[] | null {
|
|
197
|
+
addFiles(selected: Iterable<File>, intent: ComposerAssetIntent) {
|
|
140
198
|
if (this.snapshot.phase !== "editing") {
|
|
141
199
|
toast.error("Wait for the message to finish sending");
|
|
142
200
|
|
|
@@ -157,8 +215,8 @@ export class ComposerSession {
|
|
|
157
215
|
if (!accepted.length) return null;
|
|
158
216
|
|
|
159
217
|
const limitError = composerAttachmentLimitError([
|
|
160
|
-
...this.
|
|
161
|
-
...this.
|
|
218
|
+
...this.documentAssets(),
|
|
219
|
+
...this.snapshot.forwardedAttachments,
|
|
162
220
|
...accepted.map((file) => ({ size: file.size })),
|
|
163
221
|
]);
|
|
164
222
|
|
|
@@ -276,13 +334,20 @@ export class ComposerSession {
|
|
|
276
334
|
return false;
|
|
277
335
|
}
|
|
278
336
|
|
|
337
|
+
if (this.planKey === planKey && this.planReady) return false;
|
|
279
338
|
this.planKey = planKey;
|
|
339
|
+
this.planReady = false;
|
|
280
340
|
|
|
281
341
|
return true;
|
|
282
342
|
}
|
|
283
343
|
|
|
284
|
-
resolvePlan(
|
|
344
|
+
resolvePlan(
|
|
345
|
+
planKey: string,
|
|
346
|
+
linkedAssetIds: Iterable<string>,
|
|
347
|
+
linkedForwardedIds: ReadonlySet<string>
|
|
348
|
+
) {
|
|
285
349
|
if (this.planKey !== planKey) return false;
|
|
350
|
+
this.planReady = true;
|
|
286
351
|
const nextLinkedAssetIds = new Set(linkedAssetIds);
|
|
287
352
|
|
|
288
353
|
const linkedAssetsChanged = !setsEqual(
|
|
@@ -290,10 +355,18 @@ export class ComposerSession {
|
|
|
290
355
|
nextLinkedAssetIds
|
|
291
356
|
);
|
|
292
357
|
|
|
293
|
-
if (
|
|
358
|
+
if (
|
|
359
|
+
!this.snapshot.planError &&
|
|
360
|
+
!linkedAssetsChanged &&
|
|
361
|
+
setsEqual(this.snapshot.linkedForwardedIds, linkedForwardedIds)
|
|
362
|
+
) {
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
365
|
+
|
|
294
366
|
this.publish({
|
|
295
367
|
...this.snapshot,
|
|
296
368
|
planError: false,
|
|
369
|
+
linkedForwardedIds,
|
|
297
370
|
linkedAssetIds: linkedAssetsChanged
|
|
298
371
|
? nextLinkedAssetIds
|
|
299
372
|
: this.snapshot.linkedAssetIds,
|
|
@@ -303,7 +376,10 @@ export class ComposerSession {
|
|
|
303
376
|
}
|
|
304
377
|
|
|
305
378
|
failPlan(planKey: string) {
|
|
306
|
-
if (this.planKey !== planKey
|
|
379
|
+
if (this.planKey !== planKey) return;
|
|
380
|
+
this.planReady = false;
|
|
381
|
+
|
|
382
|
+
if (this.snapshot.planError) return;
|
|
307
383
|
this.publish({ ...this.snapshot, planError: true });
|
|
308
384
|
}
|
|
309
385
|
|
|
@@ -335,6 +411,10 @@ export class ComposerSession {
|
|
|
335
411
|
return this.submissionAttempt.id;
|
|
336
412
|
}
|
|
337
413
|
|
|
414
|
+
hasUnconfirmedSubmission() {
|
|
415
|
+
return this.submissionAttempt !== null;
|
|
416
|
+
}
|
|
417
|
+
|
|
338
418
|
releaseSubmission(preserveAttempt = false) {
|
|
339
419
|
const claimed = this.claimedAssetIds;
|
|
340
420
|
this.claimedAssetIds = EMPTY_LINKED_ASSETS;
|
|
@@ -369,14 +449,17 @@ export class ComposerSession {
|
|
|
369
449
|
if (this.disposed) return;
|
|
370
450
|
this.disposed = true;
|
|
371
451
|
const claimed = this.claimedAssetIds;
|
|
372
|
-
|
|
452
|
+
const { documentAssetIds } = this.snapshot;
|
|
453
|
+
// A saved draft holds only the files still in the message.
|
|
454
|
+
this.disposeAssets(
|
|
455
|
+
(asset) =>
|
|
456
|
+
!claimed.has(asset.id) &&
|
|
457
|
+
!(this.retainUploads && documentAssetIds.has(asset.id))
|
|
458
|
+
);
|
|
373
459
|
this.publish({ ...this.snapshot, phase: "closed" });
|
|
374
460
|
};
|
|
375
461
|
|
|
376
|
-
private startUpload = async (
|
|
377
|
-
assetId: string,
|
|
378
|
-
file: File
|
|
379
|
-
): Promise<ComposerAsset | null> => {
|
|
462
|
+
private startUpload = async (assetId: string, file: File) => {
|
|
380
463
|
const operationId = crypto.randomUUID();
|
|
381
464
|
this.operations.set(assetId, operationId);
|
|
382
465
|
let uploadId: string | null = null;
|
|
@@ -542,12 +625,13 @@ function setsEqual<T>(left: ReadonlySet<T>, right: ReadonlySet<T>) {
|
|
|
542
625
|
|
|
543
626
|
export function useComposerSession(
|
|
544
627
|
mailboxId: string,
|
|
545
|
-
|
|
628
|
+
forwardedAttachments?: readonly ForwardedAttachment[],
|
|
629
|
+
restoredAssets?: readonly ComposerAsset[]
|
|
546
630
|
) {
|
|
547
631
|
// One session for the composer's lifetime: created once, never replaced.
|
|
548
632
|
// oxlint-disable-next-line react/hook-use-state -- the lazy initializer keeps one instance; there is nothing to set
|
|
549
633
|
const [session] = useState(
|
|
550
|
-
() => new ComposerSession(mailboxId,
|
|
634
|
+
() => new ComposerSession(mailboxId, forwardedAttachments, restoredAssets)
|
|
551
635
|
);
|
|
552
636
|
|
|
553
637
|
const snapshot = useSyncExternalStore(
|
|
@@ -142,7 +142,21 @@ export function ComposerToolbar({
|
|
|
142
142
|
? value
|
|
143
143
|
: `https://${value}`;
|
|
144
144
|
|
|
145
|
-
editor
|
|
145
|
+
editor
|
|
146
|
+
.chain()
|
|
147
|
+
.focus()
|
|
148
|
+
.extendMarkRange("link")
|
|
149
|
+
.command(({ commands, tr }) => {
|
|
150
|
+
if (!commands.setLink({ href })) return false;
|
|
151
|
+
|
|
152
|
+
if (!tr.selection.empty) return true;
|
|
153
|
+
|
|
154
|
+
// With no label selected, insert the address under the validated link mark.
|
|
155
|
+
tr.insertText(href);
|
|
156
|
+
|
|
157
|
+
return commands.unsetMark("link");
|
|
158
|
+
})
|
|
159
|
+
.run();
|
|
146
160
|
setLinkValue("");
|
|
147
161
|
closeLinkEditor(true);
|
|
148
162
|
}
|
|
@@ -65,6 +65,9 @@ async function requestComposerUploadCompletion(
|
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
/** An upload that sends nothing for this long has stalled: it fails, and can be retried. */
|
|
69
|
+
const UPLOAD_STALL_MS = 60_000;
|
|
70
|
+
|
|
68
71
|
export function uploadComposerFile(
|
|
69
72
|
uploadUrl: string,
|
|
70
73
|
headers: Record<string, string>,
|
|
@@ -74,6 +77,20 @@ export function uploadComposerFile(
|
|
|
74
77
|
) {
|
|
75
78
|
return new Promise<void>((resolve, reject) => {
|
|
76
79
|
const request = new XMLHttpRequest();
|
|
80
|
+
let stalled = false;
|
|
81
|
+
let stallTimer: ReturnType<typeof setTimeout> | undefined;
|
|
82
|
+
|
|
83
|
+
// A hung connection would otherwise keep Send disabled for good.
|
|
84
|
+
const watch = () => {
|
|
85
|
+
clearTimeout(stallTimer);
|
|
86
|
+
stallTimer = setTimeout(() => {
|
|
87
|
+
stalled = true;
|
|
88
|
+
request.abort();
|
|
89
|
+
}, UPLOAD_STALL_MS);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const settle = () => clearTimeout(stallTimer);
|
|
93
|
+
|
|
77
94
|
onRequest(request);
|
|
78
95
|
request.open("PUT", uploadUrl);
|
|
79
96
|
|
|
@@ -82,11 +99,15 @@ export function uploadComposerFile(
|
|
|
82
99
|
}
|
|
83
100
|
|
|
84
101
|
request.upload.addEventListener("progress", (event) => {
|
|
102
|
+
watch();
|
|
103
|
+
|
|
85
104
|
if (event.lengthComputable && event.total > 0) {
|
|
86
105
|
onProgress(Math.min(1, event.loaded / event.total));
|
|
87
106
|
}
|
|
88
107
|
});
|
|
89
108
|
request.addEventListener("load", () => {
|
|
109
|
+
settle();
|
|
110
|
+
|
|
90
111
|
if (request.status >= 200 && request.status < 300) {
|
|
91
112
|
onProgress(1);
|
|
92
113
|
resolve();
|
|
@@ -95,11 +116,18 @@ export function uploadComposerFile(
|
|
|
95
116
|
}
|
|
96
117
|
});
|
|
97
118
|
request.addEventListener("error", () => {
|
|
119
|
+
settle();
|
|
98
120
|
reject(new Error("Attachment upload failed"));
|
|
99
121
|
});
|
|
100
122
|
request.addEventListener("abort", () => {
|
|
101
|
-
|
|
123
|
+
settle();
|
|
124
|
+
reject(
|
|
125
|
+
stalled
|
|
126
|
+
? new Error("Attachment upload stalled")
|
|
127
|
+
: new DOMException("Attachment upload was cancelled", "AbortError")
|
|
128
|
+
);
|
|
102
129
|
});
|
|
130
|
+
watch();
|
|
103
131
|
request.send(file);
|
|
104
132
|
});
|
|
105
133
|
}
|
|
@@ -10,7 +10,7 @@ type MutableComposerUploadProgressStore = ComposerUploadProgressStore & {
|
|
|
10
10
|
set: (localId: string, progress: number) => void;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export function createComposerUploadProgressStore()
|
|
13
|
+
export function createComposerUploadProgressStore() {
|
|
14
14
|
const values = new Map<string, number>();
|
|
15
15
|
const listeners = new Map<string, Set<() => void>>();
|
|
16
16
|
|
|
@@ -38,7 +38,7 @@ export function createComposerUploadProgressStore(): MutableComposerUploadProgre
|
|
|
38
38
|
|
|
39
39
|
for (const listener of listeners.get(localId) ?? []) listener();
|
|
40
40
|
},
|
|
41
|
-
};
|
|
41
|
+
} satisfies MutableComposerUploadProgressStore;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export function useComposerUploadProgress(
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { conversationFolder } from "../../shared/folder-order";
|
|
2
|
+
import type { ConversationSummary } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Which actions conversations in a folder offer, the same for the open
|
|
6
|
+
* conversation's bar and a selection's toolbar. `folder` is where they are
|
|
7
|
+
* listed (`conversationFolder` for one conversation): a system folder's
|
|
8
|
+
* id, or "custom" for a folder of the person's.
|
|
9
|
+
*/
|
|
10
|
+
export function conversationActionsIn(
|
|
11
|
+
folder: "inbox" | "custom" | "sent" | "archive" | "spam" | "trash"
|
|
12
|
+
) {
|
|
13
|
+
const inInbox = folder === "inbox" || folder === "custom";
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
/** Out of the Inbox, and out of Sent (a thread you started). */
|
|
17
|
+
archive: inInbox || folder === "sent",
|
|
18
|
+
/** Back to the Inbox from Archive or Trash. */
|
|
19
|
+
restore: folder === "archive" || folder === "trash",
|
|
20
|
+
/** Back from Spam, which also trusts the senders. */
|
|
21
|
+
notSpam: folder === "spam",
|
|
22
|
+
trash: folder !== "trash",
|
|
23
|
+
/** For people who can send from the mailbox. */
|
|
24
|
+
deleteForever: folder === "trash",
|
|
25
|
+
/** Received mail in the Inbox or Archive. */
|
|
26
|
+
report: inInbox || folder === "archive",
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The folder kind `conversationActionsIn` takes, from a folder's id: a system folder's, else one of the person's. */
|
|
31
|
+
export function actionFolder(folderId: string) {
|
|
32
|
+
switch (folderId) {
|
|
33
|
+
case "inbox":
|
|
34
|
+
case "sent":
|
|
35
|
+
case "archive":
|
|
36
|
+
case "spam":
|
|
37
|
+
case "trash": {
|
|
38
|
+
return folderId;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
default: {
|
|
42
|
+
return "custom";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Sent can show both active and archived conversations in the same selection. */
|
|
48
|
+
export function canArchiveOrRestore(
|
|
49
|
+
row: ConversationSummary,
|
|
50
|
+
state: "archive" | "active"
|
|
51
|
+
) {
|
|
52
|
+
if (row.draftId !== null) return false;
|
|
53
|
+
const actions = conversationActionsIn(actionFolder(conversationFolder(row)));
|
|
54
|
+
|
|
55
|
+
return state === "archive" ? actions.archive : actions.restore;
|
|
56
|
+
}
|