@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
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { authResults } from "../../shared/mail-authentication";
|
|
2
2
|
import type {
|
|
3
3
|
ArcSealer,
|
|
4
|
-
AuthResult,
|
|
5
4
|
DkimResult,
|
|
6
5
|
DmarcPolicy,
|
|
7
6
|
InboundAuthentication,
|
|
@@ -66,7 +65,7 @@ export type ParsedAuthenticationResults = {
|
|
|
66
65
|
|
|
67
66
|
const VALUE = String.raw`"(?:[^"\\]|\\.)*"|[^\s;]+`;
|
|
68
67
|
|
|
69
|
-
function parseResInfo(segment: string)
|
|
68
|
+
function parseResInfo(segment: string) {
|
|
70
69
|
const { text, comments } = scanComments(segment);
|
|
71
70
|
const method = /^\s*([a-z0-9_-]+)(?:\/\d+)?\s*=\s*([a-z0-9_-]+)/iu.exec(text);
|
|
72
71
|
|
|
@@ -104,13 +103,11 @@ function parseResInfo(segment: string): AuthResInfo | null {
|
|
|
104
103
|
reason,
|
|
105
104
|
comments,
|
|
106
105
|
props,
|
|
107
|
-
};
|
|
106
|
+
} satisfies AuthResInfo;
|
|
108
107
|
}
|
|
109
108
|
|
|
110
109
|
/** Parses an Authentication-Results value (RFC 8601 §2.2), comments and all. */
|
|
111
|
-
export function parseAuthenticationResults(
|
|
112
|
-
value: string
|
|
113
|
-
): ParsedAuthenticationResults | null {
|
|
110
|
+
export function parseAuthenticationResults(value: string) {
|
|
114
111
|
const segments = splitTopLevel(value, ";");
|
|
115
112
|
|
|
116
113
|
const authservId = scanComments(segments[0] ?? "")
|
|
@@ -127,7 +124,7 @@ export function parseAuthenticationResults(
|
|
|
127
124
|
|
|
128
125
|
return info ? [info] : [];
|
|
129
126
|
}),
|
|
130
|
-
};
|
|
127
|
+
} satisfies ParsedAuthenticationResults;
|
|
131
128
|
}
|
|
132
129
|
|
|
133
130
|
/** ARC-Authentication-Results carries `i=N;` before the A-R payload. */
|
|
@@ -148,7 +145,7 @@ export type ParsedReceivedSpf = {
|
|
|
148
145
|
pairs: Record<string, string>;
|
|
149
146
|
};
|
|
150
147
|
|
|
151
|
-
export function parseReceivedSpf(value: string)
|
|
148
|
+
export function parseReceivedSpf(value: string) {
|
|
152
149
|
const result = /^\s*([a-z]+)/iu.exec(value);
|
|
153
150
|
|
|
154
151
|
if (!result) return null;
|
|
@@ -168,7 +165,7 @@ export function parseReceivedSpf(value: string): ParsedReceivedSpf | null {
|
|
|
168
165
|
result: result[1].toLocaleLowerCase(),
|
|
169
166
|
comment: comments[0] ?? null,
|
|
170
167
|
pairs,
|
|
171
|
-
};
|
|
168
|
+
} satisfies ParsedReceivedSpf;
|
|
172
169
|
}
|
|
173
170
|
|
|
174
171
|
// --- Tag lists (DKIM-Signature, ARC-Seal) ----------------------------------
|
|
@@ -199,7 +196,7 @@ type DkimSignatureTags = {
|
|
|
199
196
|
signedHeaders: string[];
|
|
200
197
|
};
|
|
201
198
|
|
|
202
|
-
function dkimSignatureTags(fields: HeaderField[])
|
|
199
|
+
function dkimSignatureTags(fields: HeaderField[]) {
|
|
203
200
|
return fields.flatMap((field) => {
|
|
204
201
|
if (field.name !== "dkim-signature") return [];
|
|
205
202
|
const tags = parseTagList(field.value);
|
|
@@ -216,7 +213,7 @@ function dkimSignatureTags(fields: HeaderField[]): DkimSignatureTags[] {
|
|
|
216
213
|
.split(":")
|
|
217
214
|
.map((name) => name.trim().toLocaleLowerCase())
|
|
218
215
|
.filter(Boolean),
|
|
219
|
-
},
|
|
216
|
+
} satisfies DkimSignatureTags,
|
|
220
217
|
];
|
|
221
218
|
});
|
|
222
219
|
}
|
|
@@ -257,13 +254,11 @@ export function trustedHeaderBlock(fields: HeaderField[]) {
|
|
|
257
254
|
return { hop, trusted: fields.slice(0, end), below: fields.slice(end) };
|
|
258
255
|
}
|
|
259
256
|
|
|
260
|
-
function authResult(value: string | null | undefined)
|
|
257
|
+
function authResult(value: string | null | undefined) {
|
|
261
258
|
return authResults.find((result) => result === value) ?? null;
|
|
262
259
|
}
|
|
263
260
|
|
|
264
|
-
function claimFrom(
|
|
265
|
-
parsed: ParsedAuthenticationResults
|
|
266
|
-
): UpstreamAuthenticationClaim {
|
|
261
|
+
function claimFrom(parsed: ParsedAuthenticationResults) {
|
|
267
262
|
const first = (method: string) =>
|
|
268
263
|
authResult(
|
|
269
264
|
parsed.results.find(
|
|
@@ -278,17 +273,20 @@ function claimFrom(
|
|
|
278
273
|
spf: first("spf"),
|
|
279
274
|
dkim: first("dkim"),
|
|
280
275
|
dmarc: first("dmarc"),
|
|
281
|
-
};
|
|
276
|
+
} satisfies UpstreamAuthenticationClaim;
|
|
282
277
|
}
|
|
283
278
|
|
|
284
|
-
function dmarcPolicy(value: string | undefined)
|
|
279
|
+
function dmarcPolicy(value: string | undefined) {
|
|
285
280
|
const normalized = value?.toLocaleLowerCase();
|
|
286
281
|
|
|
287
|
-
|
|
282
|
+
const policy: DmarcPolicy | null =
|
|
283
|
+
normalized === "none" ||
|
|
288
284
|
normalized === "quarantine" ||
|
|
289
285
|
normalized === "reject"
|
|
290
|
-
|
|
291
|
-
|
|
286
|
+
? normalized
|
|
287
|
+
: null;
|
|
288
|
+
|
|
289
|
+
return policy;
|
|
292
290
|
}
|
|
293
291
|
|
|
294
292
|
function matchSignature(
|
|
@@ -322,7 +320,7 @@ type Verdict = Pick<InboundAuthentication, "verdict" | "verdictReason">;
|
|
|
322
320
|
|
|
323
321
|
function verdictFor(
|
|
324
322
|
input: Pick<InboundAuthentication, "spf" | "dkim" | "dmarc" | "arc">
|
|
325
|
-
)
|
|
323
|
+
) {
|
|
326
324
|
const alignedDkimPass = input.dkim.some(
|
|
327
325
|
(dkim) => dkim.result === "pass" && dkim.aligned
|
|
328
326
|
);
|
|
@@ -330,7 +328,10 @@ function verdictFor(
|
|
|
330
328
|
const alignedSpfPass = input.spf?.result === "pass" && input.spf.aligned;
|
|
331
329
|
|
|
332
330
|
if (input.dmarc?.result === "pass") {
|
|
333
|
-
return {
|
|
331
|
+
return {
|
|
332
|
+
verdict: "verified",
|
|
333
|
+
verdictReason: "dmarc_pass",
|
|
334
|
+
} satisfies Verdict;
|
|
334
335
|
}
|
|
335
336
|
|
|
336
337
|
const failing =
|
|
@@ -350,17 +351,23 @@ function verdictFor(
|
|
|
350
351
|
oldestSealer &&
|
|
351
352
|
TRUSTED_ARC_SEALERS.has(oldestSealer)
|
|
352
353
|
) {
|
|
353
|
-
return {
|
|
354
|
+
return {
|
|
355
|
+
verdict: "unverified",
|
|
356
|
+
verdictReason: "forwarded_arc",
|
|
357
|
+
} satisfies Verdict;
|
|
354
358
|
}
|
|
355
359
|
|
|
356
|
-
return { verdict: "suspicious", verdictReason: failing };
|
|
360
|
+
return { verdict: "suspicious", verdictReason: failing } satisfies Verdict;
|
|
357
361
|
}
|
|
358
362
|
|
|
359
363
|
if (alignedDkimPass && (!input.dmarc || input.dmarc.result === "none")) {
|
|
360
|
-
return {
|
|
364
|
+
return {
|
|
365
|
+
verdict: "verified",
|
|
366
|
+
verdictReason: "aligned_dkim",
|
|
367
|
+
} satisfies Verdict;
|
|
361
368
|
}
|
|
362
369
|
|
|
363
|
-
return { verdict: "unverified", verdictReason: "partial" };
|
|
370
|
+
return { verdict: "unverified", verdictReason: "partial" } satisfies Verdict;
|
|
364
371
|
}
|
|
365
372
|
|
|
366
373
|
function emptyAuthentication(
|
|
@@ -368,7 +375,7 @@ function emptyAuthentication(
|
|
|
368
375
|
fromDomain: string | null,
|
|
369
376
|
reason: "not_cloudflare" | "missing_results",
|
|
370
377
|
envelopeFrom: string | null
|
|
371
|
-
)
|
|
378
|
+
) {
|
|
372
379
|
return {
|
|
373
380
|
source: "headers",
|
|
374
381
|
version: 1,
|
|
@@ -389,7 +396,7 @@ function emptyAuthentication(
|
|
|
389
396
|
upstream: [],
|
|
390
397
|
ignoredCloudflareClaims: 0,
|
|
391
398
|
trustedHeader: null,
|
|
392
|
-
};
|
|
399
|
+
} satisfies InboundAuthentication;
|
|
393
400
|
}
|
|
394
401
|
|
|
395
402
|
function claimsCloudflare(field: HeaderField) {
|
|
@@ -423,7 +430,7 @@ function arcSummary(
|
|
|
423
430
|
trusted: HeaderField[],
|
|
424
431
|
all: HeaderField[],
|
|
425
432
|
arcResult: AuthResInfo | undefined
|
|
426
|
-
)
|
|
433
|
+
) {
|
|
427
434
|
const ownSeal = trusted.find(
|
|
428
435
|
(field) =>
|
|
429
436
|
field.name === "arc-seal" &&
|
|
@@ -487,7 +494,7 @@ function arcSummary(
|
|
|
487
494
|
(left, right) => left.instance - right.instance
|
|
488
495
|
),
|
|
489
496
|
oldest,
|
|
490
|
-
};
|
|
497
|
+
} satisfies InboundAuthentication["arc"];
|
|
491
498
|
}
|
|
492
499
|
|
|
493
500
|
/**
|
|
@@ -500,7 +507,7 @@ export function parseInboundAuthentication(input: {
|
|
|
500
507
|
fromAddress: string | null;
|
|
501
508
|
envelopeFrom?: string | null;
|
|
502
509
|
now?: number;
|
|
503
|
-
})
|
|
510
|
+
}) {
|
|
504
511
|
const now = input.now ?? Date.now();
|
|
505
512
|
const fields = headerFields(input.raw);
|
|
506
513
|
const block = trustedHeaderBlock(fields);
|
|
@@ -571,7 +578,7 @@ export function parseInboundAuthentication(input: {
|
|
|
571
578
|
spamScore: score,
|
|
572
579
|
upstream,
|
|
573
580
|
ignoredCloudflareClaims,
|
|
574
|
-
};
|
|
581
|
+
} satisfies InboundAuthentication;
|
|
575
582
|
}
|
|
576
583
|
|
|
577
584
|
const { results } = authenticationResults.parsed;
|
|
@@ -692,7 +699,7 @@ export function parseInboundAuthentication(input: {
|
|
|
692
699
|
0,
|
|
693
700
|
MAX_TRUSTED_HEADER_LENGTH
|
|
694
701
|
),
|
|
695
|
-
};
|
|
702
|
+
} satisfies InboundAuthentication;
|
|
696
703
|
}
|
|
697
704
|
|
|
698
705
|
// --- List-Unsubscribe (RFC 2369 / RFC 8058) --------------------------------
|
|
@@ -737,7 +744,7 @@ function mailtoUnsubscribeUrl(value: string) {
|
|
|
737
744
|
export function parseListUnsubscribe(
|
|
738
745
|
raw: string,
|
|
739
746
|
authentication: Pick<InboundAuthentication, "dkim">
|
|
740
|
-
)
|
|
747
|
+
) {
|
|
741
748
|
const fields = headerFields(raw);
|
|
742
749
|
|
|
743
750
|
const header = fields.find(
|
|
@@ -753,12 +760,13 @@ export function parseListUnsubscribe(
|
|
|
753
760
|
const httpsUrl = uris.map(httpsUnsubscribeUrl).find(Boolean) ?? null;
|
|
754
761
|
const mailto = uris.map(mailtoUnsubscribeUrl).find(Boolean) ?? null;
|
|
755
762
|
|
|
756
|
-
const result = (reason: ListUnsubscribe["reason"])
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
763
|
+
const result = (reason: ListUnsubscribe["reason"]) =>
|
|
764
|
+
({
|
|
765
|
+
httpsUrl,
|
|
766
|
+
mailto,
|
|
767
|
+
oneClick: reason === null,
|
|
768
|
+
reason,
|
|
769
|
+
}) satisfies ListUnsubscribe;
|
|
762
770
|
|
|
763
771
|
if (!httpsUrl && !mailto) return result("invalid-uri");
|
|
764
772
|
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import {
|
|
2
|
+
apiError,
|
|
3
|
+
createDb,
|
|
4
|
+
mailboxAddressSql,
|
|
5
|
+
oauthScope,
|
|
6
|
+
zValidator,
|
|
7
|
+
} from "@open-workspace/core/module";
|
|
8
|
+
import type { AppEnv } from "@open-workspace/core/module";
|
|
9
|
+
import { mailboxes } from "@open-workspace/core/schema";
|
|
10
|
+
import { and, desc, eq } from "drizzle-orm";
|
|
11
|
+
import { Hono } from "hono";
|
|
12
|
+
import type { Context } from "hono";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
|
|
15
|
+
import { MAIL_ORGANIZE_SCOPE, MAIL_READ_SCOPE } from "../../shared/permissions";
|
|
16
|
+
import { mailboxStub } from "../mailbox";
|
|
17
|
+
import type { AutoReplyMessage, AutoReplySettings } from "../mailbox/schema";
|
|
18
|
+
import {
|
|
19
|
+
autoReplyContentError,
|
|
20
|
+
autoReplyImagePrefix,
|
|
21
|
+
autoReplyStatus,
|
|
22
|
+
} from "./auto-reply";
|
|
23
|
+
import { mayConfigureAddress } from "./capabilities";
|
|
24
|
+
import { deleteRichImages, storeRichImages } from "./rich-content";
|
|
25
|
+
import { autoReplySchema } from "./schemas";
|
|
26
|
+
import { UploadValidationError } from "./uploads";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Who may see and change an address's auto-reply: its owner for their own
|
|
30
|
+
* mailbox (Settings), people who manage people for anyone's (People), and
|
|
31
|
+
* people who manage teams for a team inbox (Teams). Only addresses with a
|
|
32
|
+
* mailbox of their own have one: mail to an alias is answered by its
|
|
33
|
+
* target's, and a mailing list's goes straight to its members.
|
|
34
|
+
*/
|
|
35
|
+
async function autoReplyAccess(c: Context<AppEnv>, mailboxId: string) {
|
|
36
|
+
const [mailbox] = await createDb(c.env.DB)
|
|
37
|
+
.select({ ownerUserId: mailboxes.ownerUserId })
|
|
38
|
+
.from(mailboxes)
|
|
39
|
+
.where(and(eq(mailboxes.id, mailboxId), eq(mailboxes.delivery, "inbox")))
|
|
40
|
+
.limit(1);
|
|
41
|
+
|
|
42
|
+
if (!mailbox) return "not found";
|
|
43
|
+
|
|
44
|
+
return (await mayConfigureAddress(c, mailbox)) ? "allowed" : "forbidden";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function refusal(c: Context<AppEnv>, access: "not found" | "forbidden") {
|
|
48
|
+
return access === "not found"
|
|
49
|
+
? apiError(c, 404, "NOT_FOUND", "Mailbox not found")
|
|
50
|
+
: apiError(
|
|
51
|
+
c,
|
|
52
|
+
403,
|
|
53
|
+
"FORBIDDEN",
|
|
54
|
+
"You can't change this mailbox's auto-reply"
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function messageView({ text: _text, ...message }: AutoReplyMessage) {
|
|
59
|
+
return message;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function autoReplyView(mailboxId: string, settings: AutoReplySettings | null) {
|
|
63
|
+
return {
|
|
64
|
+
ok: true as const,
|
|
65
|
+
/** Saved images are shown from `/auto-reply/images/:contentId` of this mailbox. */
|
|
66
|
+
ownerId: mailboxId,
|
|
67
|
+
status: autoReplyStatus(settings, new Date()),
|
|
68
|
+
settings: settings && {
|
|
69
|
+
enabled: settings.enabled,
|
|
70
|
+
startsAt: settings.startsAt,
|
|
71
|
+
endsAt: settings.endsAt,
|
|
72
|
+
replyIntervalDays: settings.replyIntervalDays,
|
|
73
|
+
inside: messageView(settings.inside),
|
|
74
|
+
outside: {
|
|
75
|
+
...messageView(settings.outside),
|
|
76
|
+
audience: settings.outside.audience,
|
|
77
|
+
},
|
|
78
|
+
updatedAt: settings.updatedAt,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Mailboxes' auto-replies (mailbox/index.ts sends them). Mounted under
|
|
85
|
+
* /mail. Messages are rich content (rich-content.ts) whose images live under
|
|
86
|
+
* the mailbox's own objects, so they go when it does.
|
|
87
|
+
*/
|
|
88
|
+
export const autoReplyRoutes = new Hono<AppEnv>()
|
|
89
|
+
// Settings → Auto-reply: the signed-in person's own mailboxes.
|
|
90
|
+
.get("/auto-replies", oauthScope(MAIL_READ_SCOPE), async (c) => {
|
|
91
|
+
const rows = await createDb(c.env.DB)
|
|
92
|
+
.select({
|
|
93
|
+
id: mailboxes.id,
|
|
94
|
+
address: mailboxAddressSql,
|
|
95
|
+
displayName: mailboxes.displayName,
|
|
96
|
+
})
|
|
97
|
+
.from(mailboxes)
|
|
98
|
+
.where(
|
|
99
|
+
and(
|
|
100
|
+
eq(mailboxes.ownerUserId, c.get("user").id),
|
|
101
|
+
eq(mailboxes.delivery, "inbox")
|
|
102
|
+
)
|
|
103
|
+
)
|
|
104
|
+
.orderBy(desc(mailboxes.isPrimary), mailboxes.displayName);
|
|
105
|
+
|
|
106
|
+
return c.json({ ok: true as const, mailboxes: rows });
|
|
107
|
+
})
|
|
108
|
+
.get("/mailboxes/:id/auto-reply", oauthScope(MAIL_READ_SCOPE), async (c) => {
|
|
109
|
+
const mailboxId = c.req.param("id");
|
|
110
|
+
const access = await autoReplyAccess(c, mailboxId);
|
|
111
|
+
|
|
112
|
+
if (access !== "allowed") return refusal(c, access);
|
|
113
|
+
|
|
114
|
+
return c.json(
|
|
115
|
+
autoReplyView(
|
|
116
|
+
mailboxId,
|
|
117
|
+
await mailboxStub(c.env, mailboxId).getAutoReply()
|
|
118
|
+
)
|
|
119
|
+
);
|
|
120
|
+
})
|
|
121
|
+
.put(
|
|
122
|
+
"/mailboxes/:id/auto-reply",
|
|
123
|
+
oauthScope(MAIL_ORGANIZE_SCOPE),
|
|
124
|
+
zValidator("json", autoReplySchema),
|
|
125
|
+
async (c) => {
|
|
126
|
+
const mailboxId = c.req.param("id");
|
|
127
|
+
const access = await autoReplyAccess(c, mailboxId);
|
|
128
|
+
|
|
129
|
+
if (access !== "allowed") return refusal(c, access);
|
|
130
|
+
const input = c.req.valid("json");
|
|
131
|
+
|
|
132
|
+
const stub = mailboxStub(c.env, mailboxId);
|
|
133
|
+
const previous = await stub.getAutoReply();
|
|
134
|
+
|
|
135
|
+
const contentError = autoReplyContentError(
|
|
136
|
+
input.enabled ?? previous?.enabled ?? false,
|
|
137
|
+
input
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
if (contentError) return apiError(c, 400, "BAD_REQUEST", contentError);
|
|
141
|
+
const prefix = autoReplyImagePrefix(mailboxId);
|
|
142
|
+
|
|
143
|
+
// One folder for both messages, so an image can move between them.
|
|
144
|
+
const previousImages = previous
|
|
145
|
+
? [...previous.inside.images, ...previous.outside.images]
|
|
146
|
+
: [];
|
|
147
|
+
|
|
148
|
+
let images;
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
images = await Promise.all(
|
|
152
|
+
[input.inside, input.outside].map((content) =>
|
|
153
|
+
storeRichImages({
|
|
154
|
+
env: c.env,
|
|
155
|
+
userId: c.get("user").id,
|
|
156
|
+
prefix,
|
|
157
|
+
previous: previousImages,
|
|
158
|
+
content,
|
|
159
|
+
})
|
|
160
|
+
)
|
|
161
|
+
);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (error instanceof UploadValidationError) {
|
|
164
|
+
return apiError(c, 400, "BAD_REQUEST", error.message);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const [insideImages = [], outsideImages = []] = images;
|
|
171
|
+
|
|
172
|
+
const message = (
|
|
173
|
+
content: typeof input.inside,
|
|
174
|
+
stored: typeof insideImages
|
|
175
|
+
) => ({
|
|
176
|
+
enabled: content.enabled,
|
|
177
|
+
subject: content.subject,
|
|
178
|
+
html: content.html,
|
|
179
|
+
text: content.text,
|
|
180
|
+
images: stored,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const saved = await stub.setAutoReply(
|
|
184
|
+
{
|
|
185
|
+
enabled: input.enabled,
|
|
186
|
+
startsAt: input.startsAt,
|
|
187
|
+
endsAt: input.endsAt,
|
|
188
|
+
replyIntervalDays: input.replyIntervalDays,
|
|
189
|
+
inside: message(input.inside, insideImages),
|
|
190
|
+
outside: {
|
|
191
|
+
...message(input.outside, outsideImages),
|
|
192
|
+
audience: input.outside.audience,
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
c.get("user").id
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
if ("error" in saved) return apiError(c, 400, "BAD_REQUEST", saved.error);
|
|
199
|
+
|
|
200
|
+
await deleteRichImages(
|
|
201
|
+
c.env.MAIL_STORAGE,
|
|
202
|
+
prefix,
|
|
203
|
+
new Set(
|
|
204
|
+
[...insideImages, ...outsideImages].map((image) => image.contentId)
|
|
205
|
+
)
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
return c.json(autoReplyView(mailboxId, saved));
|
|
209
|
+
}
|
|
210
|
+
)
|
|
211
|
+
// The banner in Mail turns it off without sending the messages back.
|
|
212
|
+
.patch(
|
|
213
|
+
"/mailboxes/:id/auto-reply",
|
|
214
|
+
oauthScope(MAIL_ORGANIZE_SCOPE),
|
|
215
|
+
zValidator("json", z.object({ enabled: z.literal(false) })),
|
|
216
|
+
async (c) => {
|
|
217
|
+
const mailboxId = c.req.param("id");
|
|
218
|
+
const access = await autoReplyAccess(c, mailboxId);
|
|
219
|
+
|
|
220
|
+
if (access !== "allowed") return refusal(c, access);
|
|
221
|
+
|
|
222
|
+
return c.json(
|
|
223
|
+
autoReplyView(
|
|
224
|
+
mailboxId,
|
|
225
|
+
await mailboxStub(c.env, mailboxId).turnOffAutoReply(c.get("user").id)
|
|
226
|
+
)
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
)
|
|
230
|
+
.get(
|
|
231
|
+
"/mailboxes/:id/auto-reply/images/:contentId",
|
|
232
|
+
oauthScope(MAIL_READ_SCOPE),
|
|
233
|
+
async (c) => {
|
|
234
|
+
const { id: mailboxId, contentId } = c.req.param();
|
|
235
|
+
const access = await autoReplyAccess(c, mailboxId);
|
|
236
|
+
|
|
237
|
+
const object =
|
|
238
|
+
access === "allowed"
|
|
239
|
+
? await c.env.MAIL_STORAGE.get(
|
|
240
|
+
`${autoReplyImagePrefix(mailboxId)}${contentId}`
|
|
241
|
+
)
|
|
242
|
+
: null;
|
|
243
|
+
|
|
244
|
+
if (!object) return apiError(c, 404, "NOT_FOUND", "Image not found");
|
|
245
|
+
|
|
246
|
+
return new Response(object.body, {
|
|
247
|
+
headers: {
|
|
248
|
+
"content-type":
|
|
249
|
+
object.httpMetadata?.contentType ?? "application/octet-stream",
|
|
250
|
+
"cache-control": "private, max-age=300",
|
|
251
|
+
"x-content-type-options": "nosniff",
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
);
|