@open-workspace/email 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -22
- package/alchemy/index.ts +273 -0
- package/drizzle/mailbox/0000_puzzling_dracula.sql +149 -0
- package/drizzle/mailbox/0001_mute_jack_flag.sql +12 -0
- package/drizzle/mailbox/meta/0000_snapshot.json +1002 -0
- package/drizzle/mailbox/meta/0001_snapshot.json +1002 -0
- package/drizzle/mailbox/meta/_journal.json +20 -0
- package/drizzle/mailbox/migrations.js +12 -0
- package/index.ts +3 -1
- package/migrations/{0000_email.sql → 0000_dry_moon_knight.sql} +26 -20
- package/migrations/meta/0000_snapshot.json +125 -109
- package/migrations/meta/_journal.json +2 -2
- package/package.json +74 -68
- package/shared/attachment-preview.ts +37 -27
- package/shared/folder-order.ts +106 -0
- package/shared/mail-authentication.ts +8 -3
- package/shared/mail-feedback.ts +18 -25
- package/shared/mail-headers.ts +114 -39
- package/shared/mail-import.ts +38 -0
- package/shared/mail-path.ts +42 -0
- package/shared/mail-received.ts +174 -31
- package/shared/mail-remote.ts +59 -2
- package/shared/mail-sender-intel.ts +22 -4
- package/shared/mail.ts +77 -28
- package/shared/module.ts +33 -0
- package/shared/office-preview.ts +14 -2
- package/shared/pdfjs-assets.ts +35 -0
- package/shared/permissions.ts +73 -0
- package/shared/webhooks.ts +41 -0
- package/src/admin/blocked-senders.tsx +189 -0
- package/src/client.tsx +97 -0
- package/src/lib/mail-api.ts +9 -0
- package/src/mail/attachment-preview-dialog.tsx +161 -0
- package/src/mail/blocked-senders.tsx +138 -0
- package/src/mail/compose-window-chrome.tsx +194 -0
- package/src/mail/compose-window.tsx +486 -0
- package/src/mail/composer-asset-bookmarks.ts +409 -0
- package/src/mail/composer-asset.tsx +229 -0
- package/src/mail/composer-attachment-list.tsx +138 -0
- package/src/mail/composer-editor-document.ts +65 -0
- package/src/mail/composer-editor.tsx +284 -0
- package/src/mail/composer-linked-attachment-text.ts +12 -0
- package/src/mail/composer-recipient-fields.tsx +165 -0
- package/src/mail/composer-recipients.ts +208 -0
- package/src/mail/composer-session.ts +562 -0
- package/src/mail/composer-toolbar.tsx +303 -0
- package/src/mail/composer-upload-client.ts +105 -0
- package/src/mail/composer-upload-progress.ts +53 -0
- package/src/mail/conversation-list.tsx +550 -0
- package/src/mail/conversation-loading-skeleton.tsx +119 -0
- package/src/mail/conversation-message.tsx +346 -0
- package/src/mail/conversation-reply.tsx +470 -0
- package/src/mail/conversation-selection-toolbar.tsx +322 -0
- package/src/mail/conversation-view.tsx +437 -0
- package/src/mail/delivery-indicator.tsx +272 -0
- package/src/mail/email-html-body.tsx +203 -0
- package/src/mail/folder-glyph.tsx +46 -0
- package/src/mail/folder-manager.tsx +532 -0
- package/src/mail/format-bytes.ts +7 -0
- package/src/mail/mail-app-bar.tsx +253 -0
- package/src/mail/mail-background.tsx +12 -0
- package/src/mail/mail-dock.tsx +137 -0
- package/src/mail/mail-folders.ts +44 -0
- package/src/mail/mail-layout.css +236 -0
- package/src/mail/mail-location.ts +73 -0
- package/src/mail/mail-mailbox-sheet.tsx +275 -0
- package/src/mail/mail-nav-rail.tsx +129 -0
- package/src/mail/mail-nav.tsx +324 -0
- package/src/mail/mail-prefetch.ts +59 -0
- package/src/mail/mail-primitives.tsx +66 -0
- package/src/mail/mail-queries.ts +209 -0
- package/src/mail/mail-query-cache.ts +486 -0
- package/src/mail/mail-seed.ts +47 -0
- package/src/mail/mail-shell.tsx +126 -0
- package/src/mail/mailbox-ai-settings.tsx +185 -0
- package/src/mail/mailbox-realtime.tsx +251 -0
- package/src/mail/mailbox-route.tsx +15 -0
- package/src/mail/message-actions.tsx +353 -0
- package/src/mail/message-attachments.tsx +200 -0
- package/src/mail/message-format.ts +75 -0
- package/src/mail/message-header.tsx +260 -0
- package/src/mail/message-translation.tsx +225 -0
- package/src/mail/original-message-sheet.tsx +619 -0
- package/src/mail/original-message.ts +191 -0
- package/src/mail/outbound-notification.ts +53 -0
- package/src/mail/pane-splitter.tsx +117 -0
- package/src/mail/pdf-preview-toolbar.tsx +152 -0
- package/src/mail/pdf-preview.css +44 -0
- package/src/mail/pdf-preview.tsx +156 -0
- package/src/mail/pdf-translation-layout.ts +95 -0
- package/src/mail/print-message.ts +92 -0
- package/src/mail/reader-pane.tsx +535 -0
- package/src/mail/recipient-combobox.tsx +335 -0
- package/src/mail/recipient-field-row.tsx +34 -0
- package/src/mail/reply-to-warning.tsx +50 -0
- package/src/mail/sanitize-email-html.ts +430 -0
- package/src/mail/sender-actions.tsx +149 -0
- package/src/mail/sender-authentication.tsx +485 -0
- package/src/mail/sender-dialogs.tsx +384 -0
- package/src/mail/sender-security.tsx +545 -0
- package/src/mail/toolbar-tooltip.tsx +29 -0
- package/src/mail/translation-html.ts +49 -0
- package/src/mail/translation-language.ts +21 -0
- package/src/mail/types.ts +53 -0
- package/src/mail/unread-document-indicator.tsx +60 -0
- package/src/mail/use-compose-submission.ts +208 -0
- package/src/mail/use-composer-attachment-preflight.ts +184 -0
- package/src/mail/use-composer-submission.ts +117 -0
- package/src/mail/use-conversation-selection.ts +186 -0
- package/src/mail/use-mail-controller.ts +427 -0
- package/src/mail/use-mail-data.ts +279 -0
- package/src/mail/use-mail-safety.ts +155 -0
- package/src/mail/use-mail-send.ts +142 -0
- package/src/mail/use-pdf-translation-overlay.ts +156 -0
- package/src/mail/use-pdf-translation.ts +100 -0
- package/src/mail/use-pdf-viewer.ts +215 -0
- package/src/mail/use-reply-submission.ts +114 -0
- package/src/mail/use-sanitized-email-html.ts +20 -0
- package/src/mail/use-visible-message-read.ts +138 -0
- package/src/pwa/push-subscription.ts +151 -0
- package/src/settings/mail-apps-page.tsx +235 -0
- package/src/settings/notifications-page.tsx +291 -0
- package/worker/admin/blocked-sender-routes.ts +166 -0
- package/worker/admin/schemas.ts +11 -0
- package/worker/bindings.d.ts +14 -10
- package/worker/db/schema.ts +63 -40
- package/worker/jmap/eventsource.ts +84 -16
- package/worker/jmap/methods.ts +1630 -524
- package/worker/jmap/push-types.ts +27 -0
- package/worker/jmap/push.ts +140 -56
- package/worker/jmap/routes.ts +366 -105
- package/worker/mail/access.ts +258 -21
- package/worker/mail/ai-classification.ts +36 -20
- package/worker/mail/ai-translation.ts +13 -6
- package/worker/mail/auth-headers.ts +395 -137
- package/worker/mail/bimi.ts +200 -73
- package/worker/mail/bootstrap.ts +79 -0
- package/worker/mail/capped-body.ts +36 -0
- package/worker/mail/classification-signals.ts +35 -25
- package/worker/mail/conversation-cursor.ts +30 -19
- package/worker/mail/delivery-events.ts +88 -62
- package/worker/mail/delivery-facts.ts +46 -10
- package/worker/mail/demo-routes.ts +34 -10
- package/worker/mail/doh.ts +62 -23
- package/worker/mail/downloads.ts +75 -40
- package/worker/mail/edge-cache.ts +155 -0
- package/worker/mail/header-metadata.ts +88 -22
- package/worker/mail/impersonation.ts +160 -38
- package/worker/mail/import-routes.ts +313 -0
- package/worker/mail/inbound-delivery.ts +19 -9
- package/worker/mail/inbound-threading.ts +18 -8
- package/worker/mail/inbound.ts +82 -40
- package/worker/mail/ip-intel.ts +110 -27
- package/worker/mail/isolate-cache.ts +35 -0
- package/worker/mail/link-domains.ts +29 -7
- package/worker/mail/mailbox-deletion.ts +10 -4
- package/worker/mail/mailbox-directory.ts +16 -6
- package/worker/mail/mailing-list.ts +94 -39
- package/worker/mail/message-security.ts +90 -15
- package/worker/mail/message-view.ts +18 -6
- package/worker/mail/office-conversion.ts +31 -9
- package/worker/mail/office-preview-container.ts +40 -13
- package/worker/mail/office-preview-queue.ts +76 -32
- package/worker/mail/org-domain.ts +8 -1
- package/worker/mail/outbound-content.ts +71 -26
- package/worker/mail/outbound-delivery.ts +31 -17
- package/worker/mail/outbound-service.ts +48 -30
- package/worker/mail/outbound-threading.ts +30 -17
- package/worker/mail/outbound.ts +97 -70
- package/worker/mail/outgoing-context.ts +25 -15
- package/worker/mail/participants.ts +44 -29
- package/worker/mail/push-notifications.ts +271 -173
- package/worker/mail/quote-parser.ts +21 -10
- package/worker/mail/r2-presigned-urls.ts +31 -25
- package/worker/mail/receive.ts +23 -11
- package/worker/mail/recipients.ts +6 -1
- package/worker/mail/remote-proxy.ts +187 -31
- package/worker/mail/remote-routes.ts +87 -0
- package/worker/mail/remote-token.ts +104 -0
- package/worker/mail/repeat.ts +19 -0
- package/worker/mail/reply-plan.ts +62 -33
- package/worker/mail/rfc.ts +32 -7
- package/worker/mail/routes.ts +870 -541
- package/worker/mail/safety-routes.ts +328 -200
- package/worker/mail/schemas.ts +84 -105
- package/worker/mail/search.ts +1 -0
- package/worker/mail/security-settings.ts +41 -9
- package/worker/mail/sender-intel.ts +206 -51
- package/worker/mail/spamhaus.ts +92 -45
- package/worker/mail/unsubscribe.ts +76 -18
- package/worker/mail/uploads.ts +126 -93
- package/worker/mail/webhook-source.ts +35 -12
- package/worker/mail/workspace-safety.ts +97 -38
- package/worker/mailbox/demo-html.ts +7 -7
- package/worker/mailbox/demo-seed.ts +10 -44
- package/worker/mailbox/demo.ts +595 -225
- package/worker/mailbox/email-index.ts +53 -0
- package/worker/mailbox/folder-model.ts +53 -17
- package/worker/mailbox/import-placement.ts +88 -0
- package/worker/mailbox/inbox-counts.ts +106 -0
- package/worker/mailbox/index.ts +1734 -721
- package/worker/mailbox/jmap-store.ts +139 -35
- package/worker/mailbox/model.ts +8 -6
- package/worker/mailbox/office-preview-jobs.ts +56 -25
- package/worker/mailbox/schema.ts +87 -66
- package/worker/mailbox/senders.ts +176 -70
- package/worker/mcp/mail-action-tools.ts +128 -87
- package/worker/mcp/mail-compose-tools.ts +133 -82
- package/worker/mcp/mail-query-tools.ts +120 -71
- package/worker/mcp/mail-safety-tools.ts +321 -248
- package/worker/mcp/schemas.ts +43 -0
- package/worker/mcp/tools.ts +13 -10
- package/worker/module.ts +43 -18
- package/worker/sql.d.ts +8 -0
- package/alchemy.ts +0 -142
- package/containers/office-preview/Dockerfile +0 -10
- package/shared/mail-rules.ts +0 -156
- package/worker/admin/report-routes.ts +0 -164
- package/worker/mail/reported-messages.ts +0 -68
- package/worker/mailbox/migrations.ts +0 -10
- package/worker/mailbox/rules.ts +0 -110
package/worker/mail/schemas.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { emailSchema } from "@open-workspace/core/module";
|
|
1
2
|
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
import { MOVABLE_SYSTEM_FOLDER_IDS } from "../../shared/folder-order";
|
|
2
5
|
import {
|
|
3
6
|
mailboxStates,
|
|
4
7
|
MAX_BULK_CONVERSATION_COUNT,
|
|
@@ -12,8 +15,6 @@ import {
|
|
|
12
15
|
MAX_TRANSLATION_CHARACTERS,
|
|
13
16
|
MAX_TRANSLATION_SEGMENTS,
|
|
14
17
|
} from "../../shared/mail-translation";
|
|
15
|
-
import { emailSchema } from "@open-workspace/core/worker/auth/schemas.ts";
|
|
16
|
-
import { hasActions, hasConditions, MAX_MAIL_RULES } from "../../shared/mail-rules";
|
|
17
18
|
import { dedupeRecipientFields, recipientCount } from "./recipients";
|
|
18
19
|
|
|
19
20
|
export const folderSchema = z.string().trim().min(1).max(80);
|
|
@@ -27,14 +28,15 @@ export const createFolderSchema = z.object({
|
|
|
27
28
|
export const renameFolderSchema = createFolderSchema;
|
|
28
29
|
|
|
29
30
|
export const mailboxAiConfigurationSchema = z.object({
|
|
30
|
-
instructions: z.string().trim().max(
|
|
31
|
+
instructions: z.string().trim().max(4000),
|
|
31
32
|
confidenceThreshold: z.number().int().min(50).max(100),
|
|
32
33
|
});
|
|
33
34
|
|
|
35
|
+
/** Every folder but Inbox, in order: the movable system folders and the custom ones. */
|
|
34
36
|
export const reorderFoldersSchema = z.object({
|
|
35
37
|
folderIds: z
|
|
36
38
|
.array(folderSchema)
|
|
37
|
-
.max(MAX_CUSTOM_FOLDER_COUNT)
|
|
39
|
+
.max(MAX_CUSTOM_FOLDER_COUNT + MOVABLE_SYSTEM_FOLDER_IDS.length)
|
|
38
40
|
.refine((ids) => new Set(ids).size === ids.length, {
|
|
39
41
|
message: "Folder order contains duplicate ids",
|
|
40
42
|
}),
|
|
@@ -50,7 +52,9 @@ export const recipientSuggestionQuerySchema = z.object({
|
|
|
50
52
|
});
|
|
51
53
|
|
|
52
54
|
export const remoteProxyQuerySchema = mailboxQuerySchema.extend({
|
|
53
|
-
|
|
55
|
+
/** From the conversation response (`remoteTokens`, for this `url`); see remote-token.ts. */
|
|
56
|
+
token: z.string().min(1).max(512),
|
|
57
|
+
url: z.string().trim().min(1).max(4096),
|
|
54
58
|
});
|
|
55
59
|
|
|
56
60
|
export const conversationListQuerySchema = mailboxQuerySchema.extend({
|
|
@@ -73,9 +77,16 @@ export const messageReadSchema = z.object({
|
|
|
73
77
|
});
|
|
74
78
|
|
|
75
79
|
export const messageTranslationSchema = z.object({
|
|
76
|
-
language: z
|
|
77
|
-
|
|
78
|
-
.
|
|
80
|
+
language: z
|
|
81
|
+
.string()
|
|
82
|
+
.trim()
|
|
83
|
+
.min(2)
|
|
84
|
+
.max(35)
|
|
85
|
+
.regex(/^[a-zA-Z]{2,8}(?:-[a-zA-Z0-9]{1,8})*$/u),
|
|
86
|
+
segments: z
|
|
87
|
+
.array(z.string().trim().min(1).max(MAX_TRANSLATION_CHARACTERS))
|
|
88
|
+
.min(1)
|
|
89
|
+
.max(MAX_TRANSLATION_SEGMENTS),
|
|
79
90
|
});
|
|
80
91
|
|
|
81
92
|
export const createUploadSchema = z.object({
|
|
@@ -91,32 +102,35 @@ export const uploadIdSchema = z
|
|
|
91
102
|
.max(80)
|
|
92
103
|
.regex(/^upl_[a-f0-9]{32}$/u, "Attachment upload id is invalid");
|
|
93
104
|
|
|
94
|
-
export const outboundAttachmentSchema = z
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
105
|
+
export const outboundAttachmentSchema = z
|
|
106
|
+
.object({
|
|
107
|
+
uploadId: uploadIdSchema,
|
|
108
|
+
disposition: z.enum(["attachment", "inline"]).default("attachment"),
|
|
109
|
+
contentId: z
|
|
110
|
+
.string()
|
|
111
|
+
.trim()
|
|
112
|
+
.min(1)
|
|
113
|
+
.max(255)
|
|
114
|
+
.regex(/^[a-zA-Z0-9._+-]+@[a-zA-Z0-9.-]+$/u, "Content ID is invalid")
|
|
115
|
+
.optional(),
|
|
116
|
+
})
|
|
117
|
+
.superRefine((attachment, context) => {
|
|
118
|
+
if (attachment.disposition === "inline" && !attachment.contentId) {
|
|
119
|
+
context.addIssue({
|
|
120
|
+
code: "custom",
|
|
121
|
+
path: ["contentId"],
|
|
122
|
+
message: "Inline attachments require a content ID",
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (attachment.disposition === "attachment" && attachment.contentId) {
|
|
127
|
+
context.addIssue({
|
|
128
|
+
code: "custom",
|
|
129
|
+
path: ["contentId"],
|
|
130
|
+
message: "Regular attachments cannot have a content ID",
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
120
134
|
|
|
121
135
|
export const outboundMessageContentFields = {
|
|
122
136
|
bodyText: z.string().max(500_000).default(""),
|
|
@@ -127,17 +141,19 @@ export const outboundMessageContentFields = {
|
|
|
127
141
|
.default([])
|
|
128
142
|
.refine(
|
|
129
143
|
(attachments) =>
|
|
130
|
-
new Set(attachments.map((file) => file.uploadId)).size ===
|
|
131
|
-
|
|
144
|
+
new Set(attachments.map((file) => file.uploadId)).size ===
|
|
145
|
+
attachments.length,
|
|
146
|
+
{ message: "Duplicate attachment uploads are not allowed" }
|
|
132
147
|
)
|
|
133
148
|
.refine(
|
|
134
149
|
(attachments) => {
|
|
135
150
|
const contentIds = attachments.flatMap((file) =>
|
|
136
151
|
file.contentId ? [file.contentId.toLocaleLowerCase("en-US")] : []
|
|
137
152
|
);
|
|
153
|
+
|
|
138
154
|
return new Set(contentIds).size === contentIds.length;
|
|
139
155
|
},
|
|
140
|
-
{ message: "Duplicate attachment content IDs are not allowed" }
|
|
156
|
+
{ message: "Duplicate attachment content IDs are not allowed" }
|
|
141
157
|
),
|
|
142
158
|
};
|
|
143
159
|
|
|
@@ -177,21 +193,21 @@ export const composeSchema = z
|
|
|
177
193
|
...dedupeRecipientFields(value),
|
|
178
194
|
}))
|
|
179
195
|
.refine(hasMessageBody, missingMessageBody)
|
|
180
|
-
.refine(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
{ message: `An email can have at most ${MAX_MAIL_RECIPIENTS} recipients across To, Cc, and Bcc` },
|
|
187
|
-
);
|
|
196
|
+
.refine((value) => recipientCount(value) > 0, {
|
|
197
|
+
message: "Add at least one recipient in To, Cc, or Bcc",
|
|
198
|
+
})
|
|
199
|
+
.refine((value) => recipientCount(value) <= MAX_MAIL_RECIPIENTS, {
|
|
200
|
+
message: `An email can have at most ${MAX_MAIL_RECIPIENTS} recipients across To, Cc, and Bcc`,
|
|
201
|
+
});
|
|
188
202
|
|
|
189
|
-
export const replySchema = z
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
203
|
+
export const replySchema = z
|
|
204
|
+
.object({
|
|
205
|
+
...outboundRequestFields,
|
|
206
|
+
mode: z.enum(replyActionModes),
|
|
207
|
+
cc: z.array(emailSchema).max(MAX_MAIL_RECIPIENTS).optional(),
|
|
208
|
+
bcc: z.array(emailSchema).max(MAX_MAIL_RECIPIENTS).default([]),
|
|
209
|
+
})
|
|
210
|
+
.refine(hasMessageBody, missingMessageBody);
|
|
195
211
|
|
|
196
212
|
export const forwardSchema = z
|
|
197
213
|
.object({
|
|
@@ -203,14 +219,12 @@ export const forwardSchema = z
|
|
|
203
219
|
...value,
|
|
204
220
|
...dedupeRecipientFields(value),
|
|
205
221
|
}))
|
|
206
|
-
.refine(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
{ message: `An email can have at most ${MAX_MAIL_RECIPIENTS} recipients across To, Cc, and Bcc` },
|
|
213
|
-
);
|
|
222
|
+
.refine((value) => recipientCount(value) > 0, {
|
|
223
|
+
message: "Add at least one recipient in To, Cc, or Bcc",
|
|
224
|
+
})
|
|
225
|
+
.refine((value) => recipientCount(value) <= MAX_MAIL_RECIPIENTS, {
|
|
226
|
+
message: `An email can have at most ${MAX_MAIL_RECIPIENTS} recipients across To, Cc, and Bcc`,
|
|
227
|
+
});
|
|
214
228
|
|
|
215
229
|
export const attachmentPreflightSchema = z.discriminatedUnion("kind", [
|
|
216
230
|
z.object({
|
|
@@ -238,19 +252,22 @@ export const updateConversationSchema = z
|
|
|
238
252
|
mailboxState: mailboxStateSchema.optional(),
|
|
239
253
|
folderId: z.string().min(1).nullable().optional(),
|
|
240
254
|
})
|
|
241
|
-
.refine(
|
|
242
|
-
|
|
243
|
-
|
|
255
|
+
.refine(
|
|
256
|
+
(value) => value.mailboxState !== undefined || value.folderId !== undefined,
|
|
257
|
+
{
|
|
258
|
+
message: "No changes supplied",
|
|
259
|
+
}
|
|
260
|
+
)
|
|
244
261
|
.refine(
|
|
245
262
|
(value) =>
|
|
246
|
-
value.folderId === undefined
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
263
|
+
value.folderId === undefined ||
|
|
264
|
+
value.folderId === null ||
|
|
265
|
+
value.mailboxState === undefined ||
|
|
266
|
+
value.mailboxState === "active",
|
|
250
267
|
{
|
|
251
268
|
path: ["mailboxState"],
|
|
252
269
|
message: "Moving to a custom folder requires the active mailbox state",
|
|
253
|
-
}
|
|
270
|
+
}
|
|
254
271
|
);
|
|
255
272
|
|
|
256
273
|
const bulkConversationIdsSchema = z
|
|
@@ -277,39 +294,6 @@ export const bulkConversationActionSchema = z.discriminatedUnion("type", [
|
|
|
277
294
|
}),
|
|
278
295
|
]);
|
|
279
296
|
|
|
280
|
-
const ruleText = z.string().trim().max(200).optional().transform((value) => value || undefined);
|
|
281
|
-
|
|
282
|
-
export const mailRuleSchema = z.object({
|
|
283
|
-
name: z.string().trim().min(1).max(80),
|
|
284
|
-
enabled: z.boolean().default(true),
|
|
285
|
-
conditions: z.object({
|
|
286
|
-
from: ruleText,
|
|
287
|
-
to: ruleText,
|
|
288
|
-
subjectContains: ruleText,
|
|
289
|
-
listId: ruleText,
|
|
290
|
-
hasAttachment: z.boolean().optional().transform((value) => value || undefined),
|
|
291
|
-
}).refine(hasConditions, { message: "Add at least one condition" }),
|
|
292
|
-
actions: z.object({
|
|
293
|
-
folderId: z.string().trim().min(1).max(255).optional(),
|
|
294
|
-
archive: z.boolean().optional().transform((value) => value || undefined),
|
|
295
|
-
spam: z.boolean().optional().transform((value) => value || undefined),
|
|
296
|
-
markRead: z.boolean().optional().transform((value) => value || undefined),
|
|
297
|
-
neverSpam: z.boolean().optional().transform((value) => value || undefined),
|
|
298
|
-
})
|
|
299
|
-
.refine(hasActions, { message: "Choose at least one action" })
|
|
300
|
-
.refine(
|
|
301
|
-
(actions) => [actions.folderId, actions.archive, actions.spam].filter(Boolean).length <= 1,
|
|
302
|
-
{ message: "Choose one destination: a folder, Archive, or Spam" },
|
|
303
|
-
)
|
|
304
|
-
.refine((actions) => !(actions.spam && actions.neverSpam), {
|
|
305
|
-
message: "A rule cannot both send to Spam and never send to Spam",
|
|
306
|
-
}),
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
export const reorderRulesSchema = z.object({
|
|
310
|
-
ruleIds: z.array(z.string().min(1).max(255)).max(MAX_MAIL_RULES),
|
|
311
|
-
});
|
|
312
|
-
|
|
313
297
|
export const blockSenderSchema = z.object({
|
|
314
298
|
pattern: z.string().trim().min(3).max(320),
|
|
315
299
|
moveExisting: z.boolean().default(false),
|
|
@@ -329,11 +313,6 @@ export const unsubscribeSchema = z.object({
|
|
|
329
313
|
method: z.enum(["auto", "link"]).default("auto"),
|
|
330
314
|
});
|
|
331
315
|
|
|
332
|
-
export const reportMessageSchema = z.object({
|
|
333
|
-
kind: z.enum(["spam", "phishing"]),
|
|
334
|
-
});
|
|
335
|
-
|
|
336
316
|
export const bulkReportSchema = z.object({
|
|
337
|
-
kind: z.enum(["spam", "phishing"]),
|
|
338
317
|
conversationIds: z.array(z.string().trim().min(1).max(255)).min(1).max(100),
|
|
339
318
|
});
|
package/worker/mail/search.ts
CHANGED
|
@@ -8,6 +8,7 @@ const MAX_SEARCH_TOKENS = 24;
|
|
|
8
8
|
export function buildEmailSearchQuery(value: string) {
|
|
9
9
|
const tokens = value.normalize("NFKC").match(SEARCH_TOKEN_PATTERN) ?? [];
|
|
10
10
|
const unique = [...new Set(tokens)].slice(0, MAX_SEARCH_TOKENS);
|
|
11
|
+
|
|
11
12
|
return unique.length
|
|
12
13
|
? unique.map((token) => `"${token}"*`).join(" AND ")
|
|
13
14
|
: null;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
configuredMailDomains,
|
|
3
|
+
createDb,
|
|
4
|
+
mailboxes,
|
|
5
|
+
users,
|
|
6
|
+
} from "@open-workspace/core/module";
|
|
1
7
|
import { inArray, isNotNull } from "drizzle-orm";
|
|
2
|
-
|
|
3
|
-
import { domains, mailboxes, users } from "@open-workspace/core/worker/db/schema.ts";
|
|
8
|
+
|
|
4
9
|
import { protectedNames } from "./impersonation";
|
|
10
|
+
import { isolateCache, WORKSPACE_CACHE_TTL_MS } from "./isolate-cache";
|
|
5
11
|
import { DQS_KEY_PATTERN } from "./spamhaus";
|
|
6
12
|
|
|
7
13
|
/** Workspace-wide inputs for sender checks, read from D1 once per request or delivery. */
|
|
@@ -11,28 +17,54 @@ export type WorkspaceIdentity = {
|
|
|
11
17
|
names: Map<string, string>;
|
|
12
18
|
};
|
|
13
19
|
|
|
14
|
-
export async function workspaceIdentity(
|
|
20
|
+
export async function workspaceIdentity(
|
|
21
|
+
binding: D1Database
|
|
22
|
+
): Promise<WorkspaceIdentity> {
|
|
15
23
|
const db = createDb(binding);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
db
|
|
24
|
+
|
|
25
|
+
const [userRows, mailboxRows] = await db.batch([
|
|
26
|
+
db
|
|
27
|
+
.select({ name: users.name })
|
|
28
|
+
.from(users)
|
|
29
|
+
.where(inArray(users.status, ["active", "invited"])),
|
|
19
30
|
// Shared mailboxes ("Support", "Customer care") are generic names that
|
|
20
31
|
// vendors use too; only personal mailboxes name a person.
|
|
21
|
-
db
|
|
32
|
+
db
|
|
33
|
+
.select({ name: mailboxes.displayName })
|
|
34
|
+
.from(mailboxes)
|
|
35
|
+
.where(isNotNull(mailboxes.ownerUserId)),
|
|
22
36
|
]);
|
|
37
|
+
|
|
23
38
|
return {
|
|
24
|
-
domains:
|
|
39
|
+
domains: [...configuredMailDomains()],
|
|
25
40
|
names: protectedNames([...userRows, ...mailboxRows].map((row) => row.name)),
|
|
26
41
|
};
|
|
27
42
|
}
|
|
28
43
|
|
|
44
|
+
const identityCache = isolateCache(WORKSPACE_CACHE_TTL_MS, workspaceIdentity);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* `workspaceIdentity` reused for up to a minute in this isolate, for showing
|
|
48
|
+
* mail: a new person or domain reaches the reader's impersonation and
|
|
49
|
+
* external-sender hints within that minute. Delivery reads it fresh.
|
|
50
|
+
*/
|
|
51
|
+
export function cachedWorkspaceIdentity(binding: D1Database) {
|
|
52
|
+
return identityCache.get(binding);
|
|
53
|
+
}
|
|
54
|
+
|
|
29
55
|
/** The Spamhaus DQS key from the SPAMHAUS_DQS_KEY secret, when set and well-formed. */
|
|
30
56
|
export function spamhausDqsKey(env: { SPAMHAUS_DQS_KEY?: string }) {
|
|
31
57
|
const key = env.SPAMHAUS_DQS_KEY?.trim().toLowerCase();
|
|
58
|
+
|
|
32
59
|
if (!key) return null;
|
|
60
|
+
|
|
33
61
|
if (!DQS_KEY_PATTERN.test(key)) {
|
|
34
|
-
console.error(
|
|
62
|
+
console.error(
|
|
63
|
+
"SPAMHAUS_DQS_KEY is not a Spamhaus DQS key; blocklist checks are off"
|
|
64
|
+
);
|
|
65
|
+
|
|
35
66
|
return null;
|
|
36
67
|
}
|
|
68
|
+
|
|
37
69
|
return key;
|
|
38
70
|
}
|