@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
|
@@ -5,7 +5,14 @@ import type {
|
|
|
5
5
|
import { apiPath, runTool } from "@open-workspace/core/module";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { autoReplyAudiences } from "../../shared/mail";
|
|
9
|
+
import {
|
|
10
|
+
MAIL_ORGANIZE_SCOPE,
|
|
11
|
+
MAIL_READ_SCOPE,
|
|
12
|
+
MAIL_SEND_SCOPE,
|
|
13
|
+
} from "../../shared/permissions";
|
|
14
|
+
import { ruleInputSchema, ruleTestSchema } from "../mail/rules";
|
|
15
|
+
import { retentionFolderSchema } from "../mail/schemas";
|
|
9
16
|
import {
|
|
10
17
|
conversationIdsSchema,
|
|
11
18
|
entityIdSchema,
|
|
@@ -130,6 +137,97 @@ export function registerMailActionTools(
|
|
|
130
137
|
)
|
|
131
138
|
);
|
|
132
139
|
|
|
140
|
+
tool(MAIL_ORGANIZE_SCOPE)(
|
|
141
|
+
"empty_folder",
|
|
142
|
+
{
|
|
143
|
+
title: "Empty Trash or Spam",
|
|
144
|
+
description:
|
|
145
|
+
"Permanently delete up to 100 of the oldest conversations in Trash or Spam. Returns { deleted, remaining }; call again while remaining is above 0. Requires send access.",
|
|
146
|
+
inputSchema: z.object({
|
|
147
|
+
mailboxId: mailboxIdSchema,
|
|
148
|
+
folder: retentionFolderSchema,
|
|
149
|
+
}),
|
|
150
|
+
annotations: { ...write, destructiveHint: true, idempotentHint: false },
|
|
151
|
+
},
|
|
152
|
+
({ mailboxId, folder }) =>
|
|
153
|
+
runTool(() =>
|
|
154
|
+
api.json(
|
|
155
|
+
`/mail/mailboxes/${encodeURIComponent(mailboxId)}/folders/${folder}/empty`,
|
|
156
|
+
{ method: "POST" }
|
|
157
|
+
)
|
|
158
|
+
)
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
tool(MAIL_READ_SCOPE)(
|
|
162
|
+
"get_auto_reply",
|
|
163
|
+
{
|
|
164
|
+
title: "Get auto-reply",
|
|
165
|
+
description:
|
|
166
|
+
"Read a mailbox's automatic reply: its schedule, its status now (off, scheduled, active, ended), and its two messages, for people inside the workspace and for everyone else. Your own mailboxes; anyone's with Manage people, and team inboxes with Manage teams.",
|
|
167
|
+
inputSchema: z.object({ mailboxId: mailboxIdSchema }),
|
|
168
|
+
annotations: { ...write, readOnlyHint: true },
|
|
169
|
+
},
|
|
170
|
+
({ mailboxId }) =>
|
|
171
|
+
runTool(() =>
|
|
172
|
+
api.json(
|
|
173
|
+
apiPath(`/mail/mailboxes/${encodeURIComponent(mailboxId)}/auto-reply`)
|
|
174
|
+
)
|
|
175
|
+
)
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
const autoReplyMessage = z.object({
|
|
179
|
+
enabled: z.boolean(),
|
|
180
|
+
subject: z
|
|
181
|
+
.string()
|
|
182
|
+
.max(998)
|
|
183
|
+
.nullable()
|
|
184
|
+
.optional()
|
|
185
|
+
.describe('Defaults to "Auto: <original subject>".'),
|
|
186
|
+
html: z.string().max(20_000).describe("The reply as HTML."),
|
|
187
|
+
text: z.string().max(10_000).describe("The same reply as plain text."),
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
tool([MAIL_ORGANIZE_SCOPE, MAIL_SEND_SCOPE])(
|
|
191
|
+
"set_auto_reply",
|
|
192
|
+
{
|
|
193
|
+
title: "Set auto-reply",
|
|
194
|
+
description:
|
|
195
|
+
"Turn a mailbox's automatic reply on or off, with an optional schedule and one message for people inside the workspace and one for everyone else (or only people the mailbox has written to). Replaces both messages and drops their images. Mailing lists, bounces, other auto-responders, Spam and Trash are never answered, and each sender gets at most one reply per interval.",
|
|
196
|
+
inputSchema: z.object({
|
|
197
|
+
mailboxId: mailboxIdSchema,
|
|
198
|
+
enabled: z.boolean(),
|
|
199
|
+
startsAt: z.iso
|
|
200
|
+
.datetime({ offset: true })
|
|
201
|
+
.nullable()
|
|
202
|
+
.optional()
|
|
203
|
+
.describe("When replies start; omit or null to start now."),
|
|
204
|
+
endsAt: z.iso
|
|
205
|
+
.datetime({ offset: true })
|
|
206
|
+
.nullable()
|
|
207
|
+
.optional()
|
|
208
|
+
.describe("When replies stop; omit or null for no end."),
|
|
209
|
+
replyIntervalDays: z.number().int().min(1).max(30).optional(),
|
|
210
|
+
inside: autoReplyMessage,
|
|
211
|
+
outside: autoReplyMessage.extend({
|
|
212
|
+
audience: z.enum(autoReplyAudiences).optional(),
|
|
213
|
+
}),
|
|
214
|
+
}),
|
|
215
|
+
annotations: write,
|
|
216
|
+
},
|
|
217
|
+
({ mailboxId, ...settings }) =>
|
|
218
|
+
runTool(() =>
|
|
219
|
+
api.json(
|
|
220
|
+
apiPath(
|
|
221
|
+
`/mail/mailboxes/${encodeURIComponent(mailboxId)}/auto-reply`
|
|
222
|
+
),
|
|
223
|
+
{
|
|
224
|
+
method: "PUT",
|
|
225
|
+
json: settings,
|
|
226
|
+
}
|
|
227
|
+
)
|
|
228
|
+
)
|
|
229
|
+
);
|
|
230
|
+
|
|
133
231
|
tool(MAIL_ORGANIZE_SCOPE)(
|
|
134
232
|
"create_folder",
|
|
135
233
|
{
|
|
@@ -248,4 +346,66 @@ export function registerMailActionTools(
|
|
|
248
346
|
})
|
|
249
347
|
)
|
|
250
348
|
);
|
|
349
|
+
|
|
350
|
+
const rulesPath = (mailboxId: string) =>
|
|
351
|
+
`/mail/mailboxes/${encodeURIComponent(mailboxId)}/rules`;
|
|
352
|
+
|
|
353
|
+
tool(MAIL_READ_SCOPE)(
|
|
354
|
+
"list_rules",
|
|
355
|
+
{
|
|
356
|
+
title: "List mailbox rules",
|
|
357
|
+
description: "List a mailbox's rules in the order they run on new mail.",
|
|
358
|
+
inputSchema: z.object({ mailboxId: mailboxIdSchema }),
|
|
359
|
+
annotations: { ...write, readOnlyHint: true },
|
|
360
|
+
},
|
|
361
|
+
({ mailboxId }) => runTool(() => api.json(rulesPath(mailboxId)))
|
|
362
|
+
);
|
|
363
|
+
|
|
364
|
+
tool(MAIL_READ_SCOPE)(
|
|
365
|
+
"test_rule",
|
|
366
|
+
{
|
|
367
|
+
title: "Test a mailbox rule",
|
|
368
|
+
description:
|
|
369
|
+
"Count how many of the latest 500 incoming messages the conditions match, without changing anything.",
|
|
370
|
+
inputSchema: ruleTestSchema.extend({ mailboxId: mailboxIdSchema }),
|
|
371
|
+
annotations: { ...write, readOnlyHint: true },
|
|
372
|
+
},
|
|
373
|
+
({ mailboxId, ...rule }) =>
|
|
374
|
+
runTool(() =>
|
|
375
|
+
api.json(`${rulesPath(mailboxId)}/test`, { method: "POST", json: rule })
|
|
376
|
+
)
|
|
377
|
+
);
|
|
378
|
+
|
|
379
|
+
tool(MAIL_ORGANIZE_SCOPE)(
|
|
380
|
+
"create_rule",
|
|
381
|
+
{
|
|
382
|
+
title: "Create a mailbox rule",
|
|
383
|
+
description:
|
|
384
|
+
"Add a rule that runs on new mail. Conditions: from (contains/equals/domain), recipient, subject, listId, hasAttachment. Actions: moveToFolder, archive, trash, spam, notSpam, markRead. recipient matches To, Cc and the address the mail was delivered to. A matching moveToFolder or archive replaces AI sorting's folder; blocked senders always go to Spam.",
|
|
385
|
+
inputSchema: ruleInputSchema.extend({ mailboxId: mailboxIdSchema }),
|
|
386
|
+
annotations: { ...write, idempotentHint: false },
|
|
387
|
+
},
|
|
388
|
+
({ mailboxId, ...rule }) =>
|
|
389
|
+
runTool(() =>
|
|
390
|
+
api.json(rulesPath(mailboxId), { method: "POST", json: rule })
|
|
391
|
+
)
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
tool(MAIL_ORGANIZE_SCOPE)(
|
|
395
|
+
"delete_rule",
|
|
396
|
+
{
|
|
397
|
+
title: "Delete a mailbox rule",
|
|
398
|
+
inputSchema: z.object({
|
|
399
|
+
mailboxId: mailboxIdSchema,
|
|
400
|
+
ruleId: entityIdSchema,
|
|
401
|
+
}),
|
|
402
|
+
annotations: { ...write, destructiveHint: true },
|
|
403
|
+
},
|
|
404
|
+
({ mailboxId, ruleId }) =>
|
|
405
|
+
runTool(() =>
|
|
406
|
+
api.json(`${rulesPath(mailboxId)}/${encodeURIComponent(ruleId)}`, {
|
|
407
|
+
method: "DELETE",
|
|
408
|
+
})
|
|
409
|
+
)
|
|
410
|
+
);
|
|
251
411
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from "../../shared/mail";
|
|
12
12
|
import { MAIL_SEND_SCOPE } from "../../shared/permissions";
|
|
13
13
|
import { dedupeRecipientFields, recipientCount } from "../mail/recipients";
|
|
14
|
+
import { forwardedAttachmentIdsSchema } from "../mail/schemas";
|
|
14
15
|
import {
|
|
15
16
|
entityIdSchema,
|
|
16
17
|
mailboxIdSchema,
|
|
@@ -49,6 +50,11 @@ const forwardInputSchema = z
|
|
|
49
50
|
.object({
|
|
50
51
|
mailboxId: mailboxIdSchema,
|
|
51
52
|
sourceMessageId: entityIdSchema,
|
|
53
|
+
forwardedAttachmentIds: forwardedAttachmentIdsSchema
|
|
54
|
+
.optional()
|
|
55
|
+
.describe(
|
|
56
|
+
"Original attachment IDs to include. Omit for all, or pass [] for none."
|
|
57
|
+
),
|
|
52
58
|
...recipientFields,
|
|
53
59
|
replyTo: emailSchema.optional(),
|
|
54
60
|
...messageContentFields,
|
|
@@ -183,7 +189,7 @@ export function registerMailComposeTools(
|
|
|
183
189
|
sourceMessageId: entityIdSchema,
|
|
184
190
|
mode: replyModeSchema.default("reply"),
|
|
185
191
|
cc: z.array(emailSchema).max(MAX_MAIL_RECIPIENTS).optional(),
|
|
186
|
-
bcc: z.array(emailSchema).max(MAX_MAIL_RECIPIENTS).
|
|
192
|
+
bcc: z.array(emailSchema).max(MAX_MAIL_RECIPIENTS).optional(),
|
|
187
193
|
...messageContentFields,
|
|
188
194
|
}),
|
|
189
195
|
annotations: sendAnnotations,
|
|
@@ -297,7 +297,7 @@ export function registerMailSafetyTools(
|
|
|
297
297
|
{
|
|
298
298
|
title: "Unsubscribe from mailing list",
|
|
299
299
|
description:
|
|
300
|
-
'OUTBOUND ACTION: unsubscribe this mailbox from the mailing list that sent an incoming message. With method "auto" the server tries, in order: an RFC 8058 one-click POST to the sender\'s URL (outcome "done"); an unsubscribe
|
|
300
|
+
'OUTBOUND ACTION: unsubscribe this mailbox from the mailing list that sent an incoming message. With method "auto" the server tries, in order: an RFC 8058 one-click POST to the sender\'s URL (outcome "done"); an email saying only "unsubscribe" sent from this mailbox, never to an address of this workspace, which requires send access (outcome "requested"); otherwise it returns the sender\'s unsubscribe page URL for the user to open themselves (outcome "link"). Method "link" only records that the user is opening the page and returns its URL; it contacts no one. Confirm with the user before calling. Rate-limited to 20 requests per minute. Check get_message_security\'s unsubscribe field first.',
|
|
301
301
|
inputSchema: messageInputSchema.extend({
|
|
302
302
|
method: z.enum(["auto", "link"]).default("auto"),
|
|
303
303
|
}),
|
|
@@ -325,7 +325,7 @@ export function registerMailSafetyTools(
|
|
|
325
325
|
{
|
|
326
326
|
title: "Report spam",
|
|
327
327
|
description:
|
|
328
|
-
"Report an incoming message as spam:
|
|
328
|
+
"Report an incoming message as spam: it and its sender's other messages in the thread go to Spam (the rest of the thread stays), are labelled, and train the sender's reputation here and across the workspace. Nothing is sent outside the workspace. Returns places: for each conversation, where its spam is now and whether the conversation left its folder (left). Confirm with the user before reporting.",
|
|
329
329
|
inputSchema: messageInputSchema,
|
|
330
330
|
annotations: { ...write, idempotentHint: false },
|
|
331
331
|
},
|
|
@@ -345,7 +345,7 @@ export function registerMailSafetyTools(
|
|
|
345
345
|
{
|
|
346
346
|
title: "Report conversations as spam",
|
|
347
347
|
description:
|
|
348
|
-
"Report the
|
|
348
|
+
"Report the received mail of up to 100 conversations as spam and move it to Spam (your own replies stay). Returns places, as report_message does. Confirm with the user first.",
|
|
349
349
|
inputSchema: z.object({
|
|
350
350
|
mailboxId: mailboxIdSchema,
|
|
351
351
|
conversationIds: z
|
|
@@ -370,7 +370,7 @@ export function registerMailSafetyTools(
|
|
|
370
370
|
{
|
|
371
371
|
title: "Mark message not spam",
|
|
372
372
|
description:
|
|
373
|
-
"Move an incoming message's conversation from Spam back to Inbox, clear its spam label, record the feedback, and mark
|
|
373
|
+
"Move an incoming message's conversation from Spam back to Inbox, clear its spam label, record the feedback, and mark its senders as trusted in this mailbox. Returns places: from, the conversation it was in; conversationId, the one it is in now (a reply kept out of its conversation as spam rejoins it); folder, where that is (inbox, archive or a custom folder id). Empty when it wasn't in Spam.",
|
|
374
374
|
inputSchema: messageInputSchema,
|
|
375
375
|
annotations: write,
|
|
376
376
|
},
|
package/worker/module.ts
CHANGED
|
@@ -10,17 +10,24 @@ import type { EmailQueueRole } from "../shared/module";
|
|
|
10
10
|
import { emailPermissions, mailOauthScopes } from "../shared/permissions";
|
|
11
11
|
import { EMAIL_WEBHOOK_SOURCE, emailWebhookEvents } from "../shared/webhooks";
|
|
12
12
|
import { blockedSenderAdminRoutes } from "./admin/blocked-sender-routes";
|
|
13
|
+
import { forgetBackupHashes, mailBackup } from "./backups/mail-backup";
|
|
13
14
|
import { jmapRoutes } from "./jmap/routes";
|
|
15
|
+
import { runArchiveTick } from "./mail/archive";
|
|
16
|
+
import { mailArchiveRoutes } from "./mail/archive-routes";
|
|
14
17
|
import { mailBootstrap } from "./mail/bootstrap";
|
|
15
18
|
import { consumeDeliveryEvents } from "./mail/delivery-events";
|
|
16
19
|
import { demoRoutes } from "./mail/demo-routes";
|
|
17
20
|
import { mailDownloadRoutes } from "./mail/downloads";
|
|
21
|
+
import {
|
|
22
|
+
addForwardDestinations,
|
|
23
|
+
forwardDestinationRoutes,
|
|
24
|
+
} from "./mail/forward-destinations";
|
|
18
25
|
import { mailImportRoutes } from "./mail/import-routes";
|
|
19
26
|
import { deleteMailboxStorage } from "./mail/mailbox-deletion";
|
|
20
27
|
import { consumeOfficePreviews } from "./mail/office-preview-queue";
|
|
21
28
|
import {
|
|
22
29
|
consumePushNotifications,
|
|
23
|
-
|
|
30
|
+
deleteEndedSessionPushSubscriptions,
|
|
24
31
|
deleteUserPushSubscriptions,
|
|
25
32
|
pushNotificationRoutes,
|
|
26
33
|
} from "./mail/push-notifications";
|
|
@@ -36,6 +43,8 @@ export const mailAccountApi = new Hono<AppEnv>()
|
|
|
36
43
|
// first, so that middleware never runs for it).
|
|
37
44
|
.route("/mail/remote", mailRemoteRoutes)
|
|
38
45
|
.route("/mail/import", mailImportRoutes)
|
|
46
|
+
.route("/mail/forward-destinations", forwardDestinationRoutes)
|
|
47
|
+
.route("/mail/archive", mailArchiveRoutes)
|
|
39
48
|
.route("/mail", mailRoutes)
|
|
40
49
|
.route("/admin", blockedSenderAdminRoutes);
|
|
41
50
|
|
|
@@ -57,7 +66,7 @@ export type MailAppType = typeof mailBrowserApi;
|
|
|
57
66
|
* and push. `Email()` in alchemy.run.ts puts it in the generated Worker
|
|
58
67
|
* entry, which also exports `MailboxDO` and `OfficePreviewContainer`.
|
|
59
68
|
*/
|
|
60
|
-
export function email()
|
|
69
|
+
export function email() {
|
|
61
70
|
return {
|
|
62
71
|
name: EMAIL_MODULE,
|
|
63
72
|
accountApi: mailAccountApi,
|
|
@@ -74,15 +83,25 @@ export function email(): WorkspaceModule {
|
|
|
74
83
|
[emailQueueRoles.deliveryEvents]: (batch, env) =>
|
|
75
84
|
consumeDeliveryEvents(batch, env),
|
|
76
85
|
} satisfies Record<EmailQueueRole, QueueConsumer>,
|
|
86
|
+
// Hourly: the mail archive's retries (a no-op without its bucket).
|
|
87
|
+
scheduled: (controller, env) =>
|
|
88
|
+
runArchiveTick(env, new Date(controller.scheduledTime)),
|
|
77
89
|
mcpTools: () =>
|
|
78
90
|
import("./mcp/tools").then((tools) => tools.registerMailTools),
|
|
79
91
|
webhookEvents: emailWebhookEvents,
|
|
80
92
|
webhookSources: { [EMAIL_WEBHOOK_SOURCE]: emailWebhookData },
|
|
93
|
+
backup: mailBackup,
|
|
81
94
|
hooks: {
|
|
95
|
+
mailboxSaved: async (env, mailboxId) => {
|
|
96
|
+
await Promise.all([
|
|
97
|
+
addForwardDestinations(env, mailboxId),
|
|
98
|
+
forgetBackupHashes(env, mailboxId),
|
|
99
|
+
]);
|
|
100
|
+
},
|
|
82
101
|
mailboxDeleted: deleteMailboxStorage,
|
|
83
|
-
|
|
102
|
+
sessionsEnded: deleteEndedSessionPushSubscriptions,
|
|
84
103
|
sessionsRevoked: deleteUserPushSubscriptions,
|
|
85
104
|
seedDemo: (env) => seedEmailDemo(env),
|
|
86
105
|
},
|
|
87
|
-
};
|
|
106
|
+
} satisfies WorkspaceModule;
|
|
88
107
|
}
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import type { FormEvent, RefObject } from "react";
|
|
2
|
-
|
|
3
|
-
import type { ComposerContent, ComposerEditorHandle } from "./composer-editor";
|
|
4
|
-
import type { ValidatedComposerRecipients } from "./composer-recipients";
|
|
5
|
-
import { isUploadedAsset } from "./composer-session";
|
|
6
|
-
import type {
|
|
7
|
-
ComposerAsset,
|
|
8
|
-
ComposerSession,
|
|
9
|
-
ComposerSessionPhase,
|
|
10
|
-
} from "./composer-session";
|
|
11
|
-
import { notifyOutboundResult } from "./outbound-notification";
|
|
12
|
-
import type { Mailbox, MessageDetail } from "./types";
|
|
13
|
-
import { resolveComposerAttachmentPlan } from "./use-composer-attachment-preflight";
|
|
14
|
-
import type { PreflightContext } from "./use-composer-attachment-preflight";
|
|
15
|
-
import { useComposerSubmission } from "./use-composer-submission";
|
|
16
|
-
import type { PreparedComposerSubmission } from "./use-composer-submission";
|
|
17
|
-
import type { MailSendDraft } from "./use-mail-send";
|
|
18
|
-
|
|
19
|
-
type ForwardedComposeMessage = Pick<MessageDetail, "id">;
|
|
20
|
-
|
|
21
|
-
type ComposeSubmissionInput = {
|
|
22
|
-
session: ComposerSession;
|
|
23
|
-
phase: ComposerSessionPhase;
|
|
24
|
-
mailbox: Mailbox;
|
|
25
|
-
forwardedMessage?: ForwardedComposeMessage;
|
|
26
|
-
recipients: ValidatedComposerRecipients;
|
|
27
|
-
subject: string;
|
|
28
|
-
content: ComposerContent;
|
|
29
|
-
editor: RefObject<ComposerEditorHandle | null>;
|
|
30
|
-
activeAssets: readonly ComposerAsset[];
|
|
31
|
-
uploadLimitError: string | null;
|
|
32
|
-
uploadsPending: boolean;
|
|
33
|
-
uploadsFailed: boolean;
|
|
34
|
-
onClose: () => void;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export function useComposeSubmission(input: ComposeSubmissionInput) {
|
|
38
|
-
const submission = useComposerSubmission({
|
|
39
|
-
session: input.session,
|
|
40
|
-
phase: input.phase,
|
|
41
|
-
validate: () => submissionValidationError(input),
|
|
42
|
-
prepare: (signal) => prepareComposeSubmission(input, signal),
|
|
43
|
-
failureLabel: "Could not send message",
|
|
44
|
-
onSuccess: (result) => {
|
|
45
|
-
notifyOutboundResult(result, "message");
|
|
46
|
-
input.onClose();
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
busy: submission.busy,
|
|
52
|
-
submit: (event: FormEvent) => {
|
|
53
|
-
event.preventDefault();
|
|
54
|
-
void submission.submit();
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function prepareComposeSubmission(
|
|
60
|
-
input: ComposeSubmissionInput,
|
|
61
|
-
signal: AbortSignal
|
|
62
|
-
): Promise<PreparedComposerSubmission> {
|
|
63
|
-
let content = input.editor.current?.content() ?? input.content;
|
|
64
|
-
|
|
65
|
-
if (!input.forwardedMessage && !hasAuthoredContent(content)) {
|
|
66
|
-
throw new Error("Add text to the message before sending");
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const activeIds = new Set(
|
|
70
|
-
input.editor.current?.assetIds() ??
|
|
71
|
-
input.activeAssets.map((asset) => asset.id)
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
const assets = input.session
|
|
75
|
-
.getSnapshot()
|
|
76
|
-
.assets.filter((asset) => activeIds.has(asset.id));
|
|
77
|
-
|
|
78
|
-
if (assets.length) {
|
|
79
|
-
await resolveComposerAttachmentPlan(
|
|
80
|
-
input.session,
|
|
81
|
-
preflightContext(input, content),
|
|
82
|
-
assets,
|
|
83
|
-
signal
|
|
84
|
-
);
|
|
85
|
-
// Freeze exactly the same link-card projection that final preflight chose.
|
|
86
|
-
input.editor.current?.reconcileAssets();
|
|
87
|
-
content = input.editor.current?.content() ?? content;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!input.forwardedMessage && !hasAuthoredContent(content)) {
|
|
91
|
-
throw new Error("Add text to the message before sending");
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const finalActiveIds = new Set(
|
|
95
|
-
input.editor.current?.assetIds() ?? [...activeIds]
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
const linkedDocumentAssetIds = new Set(content.linkedAssetIds);
|
|
99
|
-
|
|
100
|
-
const submittedAssets = input.session
|
|
101
|
-
.getSnapshot()
|
|
102
|
-
.assets.filter(isUploadedAsset)
|
|
103
|
-
.filter((asset) => finalActiveIds.has(asset.id));
|
|
104
|
-
|
|
105
|
-
const uploadedAttachments = submittedAssets.map((asset) => {
|
|
106
|
-
const linkedInline =
|
|
107
|
-
asset.intent === "inline" && linkedDocumentAssetIds.has(asset.id);
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
uploadId: asset.uploadId,
|
|
111
|
-
disposition: linkedInline ? ("attachment" as const) : asset.intent,
|
|
112
|
-
// A linked inline image goes as a plain attachment, without its content
|
|
113
|
-
// ID; JSON leaves an undefined one out.
|
|
114
|
-
contentId: (!linkedInline && asset.contentId) || undefined,
|
|
115
|
-
};
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
const common = {
|
|
119
|
-
mailboxId: input.mailbox.id,
|
|
120
|
-
bodyText: content.bodyText,
|
|
121
|
-
bodyHtml:
|
|
122
|
-
content.bodyText.trim() ||
|
|
123
|
-
content.inlineAssetIds.length ||
|
|
124
|
-
content.linkedAssetIds.length
|
|
125
|
-
? content.bodyHtml
|
|
126
|
-
: undefined,
|
|
127
|
-
uploadedAttachments,
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const command: MailSendDraft = input.forwardedMessage
|
|
131
|
-
? {
|
|
132
|
-
...common,
|
|
133
|
-
kind: "forward",
|
|
134
|
-
sourceEmailId: input.forwardedMessage.id,
|
|
135
|
-
to: input.recipients.to,
|
|
136
|
-
cc: input.recipients.cc,
|
|
137
|
-
bcc: input.recipients.bcc,
|
|
138
|
-
replyTo: input.recipients.replyTo,
|
|
139
|
-
}
|
|
140
|
-
: {
|
|
141
|
-
...common,
|
|
142
|
-
kind: "compose",
|
|
143
|
-
to: input.recipients.to,
|
|
144
|
-
cc: input.recipients.cc,
|
|
145
|
-
bcc: input.recipients.bcc,
|
|
146
|
-
replyTo: input.recipients.replyTo,
|
|
147
|
-
subject: input.subject,
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
return {
|
|
151
|
-
assetIds: submittedAssets.map((asset) => asset.id),
|
|
152
|
-
command,
|
|
153
|
-
submissionKey: JSON.stringify(command),
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function submissionValidationError(input: ComposeSubmissionInput) {
|
|
158
|
-
if (input.recipients.error) return input.recipients.error;
|
|
159
|
-
|
|
160
|
-
if (input.recipients.count === 0) {
|
|
161
|
-
return "Add at least one recipient in To, Cc, or Bcc";
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (input.uploadLimitError) return input.uploadLimitError;
|
|
165
|
-
|
|
166
|
-
if (input.uploadsPending) {
|
|
167
|
-
return "Wait for attachments to finish uploading";
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (input.uploadsFailed) return "Retry or remove failed attachments";
|
|
171
|
-
|
|
172
|
-
if (!input.mailbox.canSend) return "This mailbox is read-only";
|
|
173
|
-
const content = input.editor.current?.content() ?? input.content;
|
|
174
|
-
|
|
175
|
-
if (!input.forwardedMessage && !hasAuthoredContent(content)) {
|
|
176
|
-
return "Add text to the message before sending";
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return null;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function hasAuthoredContent(content: ComposerContent) {
|
|
183
|
-
return Boolean(content.bodyText.trim() || content.inlineAssetIds.length);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function preflightContext(
|
|
187
|
-
input: Pick<
|
|
188
|
-
ComposeSubmissionInput,
|
|
189
|
-
"forwardedMessage" | "mailbox" | "subject"
|
|
190
|
-
>,
|
|
191
|
-
content: ComposerContent
|
|
192
|
-
): PreflightContext {
|
|
193
|
-
return input.forwardedMessage
|
|
194
|
-
? {
|
|
195
|
-
kind: "forward",
|
|
196
|
-
mailboxId: input.mailbox.id,
|
|
197
|
-
sourceEmailId: input.forwardedMessage.id,
|
|
198
|
-
bodyText: content.bodyText,
|
|
199
|
-
bodyHtml: content.bodyHtml || undefined,
|
|
200
|
-
}
|
|
201
|
-
: {
|
|
202
|
-
kind: "compose",
|
|
203
|
-
mailboxId: input.mailbox.id,
|
|
204
|
-
subject: input.subject,
|
|
205
|
-
bodyText: content.bodyText,
|
|
206
|
-
bodyHtml: content.bodyHtml || undefined,
|
|
207
|
-
};
|
|
208
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type { ValidatedComposerRecipients } from "./composer-recipients";
|
|
2
|
-
import { isUploadedAsset } from "./composer-session";
|
|
3
|
-
import type { ComposerSession, ComposerSessionPhase } from "./composer-session";
|
|
4
|
-
import { notifyOutboundResult } from "./outbound-notification";
|
|
5
|
-
import type { Mailbox, MessageDetail, ReplyAction } from "./types";
|
|
6
|
-
import { resolveComposerAttachmentPlan } from "./use-composer-attachment-preflight";
|
|
7
|
-
import { useComposerSubmission } from "./use-composer-submission";
|
|
8
|
-
import type { PreparedComposerSubmission } from "./use-composer-submission";
|
|
9
|
-
import type { MailSendDraft, SubmittedMessage } from "./use-mail-send";
|
|
10
|
-
|
|
11
|
-
export type SentReply = Pick<SubmittedMessage, "conversationId" | "detached">;
|
|
12
|
-
|
|
13
|
-
type ReplySubmissionInput = {
|
|
14
|
-
session: ComposerSession;
|
|
15
|
-
phase: ComposerSessionPhase;
|
|
16
|
-
mailbox?: Mailbox;
|
|
17
|
-
parent: MessageDetail;
|
|
18
|
-
action?: ReplyAction;
|
|
19
|
-
recipients: ValidatedComposerRecipients;
|
|
20
|
-
body: string;
|
|
21
|
-
uploadLimitError: string | null;
|
|
22
|
-
uploadsPending: boolean;
|
|
23
|
-
uploadsFailed: boolean;
|
|
24
|
-
onSuccess: (result: SentReply) => void;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export function useReplySubmission(input: ReplySubmissionInput) {
|
|
28
|
-
return useComposerSubmission({
|
|
29
|
-
session: input.session,
|
|
30
|
-
phase: input.phase,
|
|
31
|
-
validate: () => replySubmissionValidationError(input),
|
|
32
|
-
prepare: (signal) => prepareReplySubmission(input, signal),
|
|
33
|
-
failureLabel: "Could not send reply",
|
|
34
|
-
onSuccess: (result) => {
|
|
35
|
-
notifyOutboundResult(result, "reply");
|
|
36
|
-
input.onSuccess({
|
|
37
|
-
conversationId: result.conversationId,
|
|
38
|
-
detached: result.detached,
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function replySubmissionValidationError(input: ReplySubmissionInput) {
|
|
45
|
-
if (!input.mailbox?.canSend || !input.action) {
|
|
46
|
-
return "Reply is no longer available";
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (input.recipients.error) return input.recipients.error;
|
|
50
|
-
|
|
51
|
-
if (input.uploadLimitError) return input.uploadLimitError;
|
|
52
|
-
|
|
53
|
-
if (input.uploadsPending) {
|
|
54
|
-
return "Wait for attachments to finish uploading";
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (input.uploadsFailed) return "Retry or remove failed attachments";
|
|
58
|
-
|
|
59
|
-
if (!input.body.trim()) return "Add text to the reply before sending";
|
|
60
|
-
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function prepareReplySubmission(
|
|
65
|
-
input: ReplySubmissionInput,
|
|
66
|
-
signal: AbortSignal
|
|
67
|
-
): Promise<PreparedComposerSubmission> {
|
|
68
|
-
if (!input.mailbox || !input.action) {
|
|
69
|
-
throw new Error("Reply is no longer available");
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const submittedAssets = input.session
|
|
73
|
-
.getSnapshot()
|
|
74
|
-
.assets.filter(isUploadedAsset);
|
|
75
|
-
|
|
76
|
-
if (submittedAssets.length) {
|
|
77
|
-
await resolveComposerAttachmentPlan(
|
|
78
|
-
input.session,
|
|
79
|
-
{
|
|
80
|
-
kind: "reply",
|
|
81
|
-
mailboxId: input.mailbox.id,
|
|
82
|
-
sourceEmailId: input.parent.id,
|
|
83
|
-
mode: input.action.mode,
|
|
84
|
-
cc: input.recipients.cc,
|
|
85
|
-
bcc: input.recipients.bcc,
|
|
86
|
-
bodyText: input.body,
|
|
87
|
-
},
|
|
88
|
-
submittedAssets,
|
|
89
|
-
signal
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const uploadedAttachments = submittedAssets.map((asset) => ({
|
|
94
|
-
uploadId: asset.uploadId,
|
|
95
|
-
disposition: "attachment" as const,
|
|
96
|
-
}));
|
|
97
|
-
|
|
98
|
-
const command: MailSendDraft = {
|
|
99
|
-
kind: "reply",
|
|
100
|
-
mailboxId: input.mailbox.id,
|
|
101
|
-
cc: input.recipients.cc,
|
|
102
|
-
bcc: input.recipients.bcc,
|
|
103
|
-
bodyText: input.body,
|
|
104
|
-
uploadedAttachments,
|
|
105
|
-
parentEmailId: input.parent.id,
|
|
106
|
-
mode: input.action.mode,
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
assetIds: submittedAssets.map((asset) => asset.id),
|
|
111
|
-
command,
|
|
112
|
-
submissionKey: JSON.stringify(command),
|
|
113
|
-
};
|
|
114
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reads a body stream to the end, or gives up (cancelling the stream) as soon
|
|
3
|
-
* as it grows past `limit` bytes: a remote server or a client cannot make the
|
|
4
|
-
* Worker buffer more than it allows.
|
|
5
|
-
*/
|
|
6
|
-
export async function readCappedBody(
|
|
7
|
-
body: ReadableStream<Uint8Array>,
|
|
8
|
-
limit: number
|
|
9
|
-
): Promise<Uint8Array | null> {
|
|
10
|
-
let total = 0;
|
|
11
|
-
let exceeded = false;
|
|
12
|
-
|
|
13
|
-
const capped = body.pipeThrough(
|
|
14
|
-
new TransformStream<Uint8Array, Uint8Array>({
|
|
15
|
-
transform(chunk, controller) {
|
|
16
|
-
total += chunk.byteLength;
|
|
17
|
-
|
|
18
|
-
if (total > limit) {
|
|
19
|
-
exceeded = true;
|
|
20
|
-
controller.error(new Error("The body is over the size limit"));
|
|
21
|
-
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
controller.enqueue(chunk);
|
|
26
|
-
},
|
|
27
|
-
})
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
return new Uint8Array(await new Response(capped).arrayBuffer());
|
|
32
|
-
} catch (error) {
|
|
33
|
-
if (exceeded) return null;
|
|
34
|
-
throw error;
|
|
35
|
-
}
|
|
36
|
-
}
|