@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
|
@@ -1,35 +1,64 @@
|
|
|
1
|
+
import { createDb } from "@open-workspace/core/module";
|
|
1
2
|
import { and, desc, eq, ne } from "drizzle-orm";
|
|
3
|
+
|
|
2
4
|
import type { FeedbackLabel } from "../../shared/mail-feedback";
|
|
3
|
-
import { createDb } from "@open-workspace/core/worker/db/client.ts";
|
|
4
5
|
import { blockedSenders, senderReports } from "../db/schema";
|
|
6
|
+
import { isolateCache, WORKSPACE_CACHE_TTL_MS } from "./isolate-cache";
|
|
5
7
|
|
|
6
|
-
const MAX_WORKSPACE_BLOCKS =
|
|
8
|
+
const MAX_WORKSPACE_BLOCKS = 5000;
|
|
7
9
|
|
|
8
10
|
/** Workspace-wide block patterns with the time each was added. */
|
|
9
11
|
export async function workspaceBlockPatterns(binding: D1Database) {
|
|
10
12
|
const rows = await createDb(binding)
|
|
11
|
-
.select({
|
|
13
|
+
.select({
|
|
14
|
+
pattern: blockedSenders.pattern,
|
|
15
|
+
createdAt: blockedSenders.createdAt,
|
|
16
|
+
})
|
|
12
17
|
.from(blockedSenders)
|
|
13
18
|
.orderBy(desc(blockedSenders.createdAt))
|
|
14
19
|
.limit(MAX_WORKSPACE_BLOCKS);
|
|
20
|
+
|
|
15
21
|
return new Map(rows.map((row) => [row.pattern, row.createdAt.getTime()]));
|
|
16
22
|
}
|
|
17
23
|
|
|
24
|
+
const blockPatternCache = isolateCache(
|
|
25
|
+
WORKSPACE_CACHE_TTL_MS,
|
|
26
|
+
workspaceBlockPatterns
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* `workspaceBlockPatterns` reused for up to a minute in this isolate, for
|
|
31
|
+
* showing mail. Changes made through this isolate drop it at once (see
|
|
32
|
+
* `forgetWorkspaceBlockPatterns`); others show within the minute. Delivery
|
|
33
|
+
* and blocking decisions read it fresh.
|
|
34
|
+
*/
|
|
35
|
+
export function cachedWorkspaceBlockPatterns(binding: D1Database) {
|
|
36
|
+
return blockPatternCache.get(binding);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function forgetWorkspaceBlockPatterns() {
|
|
40
|
+
blockPatternCache.clear();
|
|
41
|
+
}
|
|
18
42
|
|
|
19
43
|
function addressDomain(address: string) {
|
|
20
44
|
return address.slice(address.lastIndexOf("@") + 1);
|
|
21
45
|
}
|
|
22
46
|
|
|
23
|
-
/** Shares a spam
|
|
24
|
-
export async function recordWorkspaceFeedback(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
47
|
+
/** Shares a spam or not-spam verdict with the rest of the workspace. */
|
|
48
|
+
export async function recordWorkspaceFeedback(
|
|
49
|
+
binding: D1Database,
|
|
50
|
+
input: {
|
|
51
|
+
mailboxId: string;
|
|
52
|
+
emailId: string;
|
|
53
|
+
address: string;
|
|
54
|
+
label: FeedbackLabel;
|
|
55
|
+
}
|
|
56
|
+
) {
|
|
30
57
|
const address = input.address.toLocaleLowerCase();
|
|
58
|
+
|
|
31
59
|
if (!address.includes("@")) return;
|
|
32
60
|
const db = createDb(binding);
|
|
61
|
+
|
|
33
62
|
const row = {
|
|
34
63
|
mailboxId: input.mailboxId,
|
|
35
64
|
emailId: input.emailId,
|
|
@@ -38,55 +67,85 @@ export async function recordWorkspaceFeedback(binding: D1Database, input: {
|
|
|
38
67
|
label: input.label,
|
|
39
68
|
createdAt: new Date(),
|
|
40
69
|
};
|
|
70
|
+
|
|
41
71
|
// A new stance replaces the opposite one this mailbox gave the sender before.
|
|
42
|
-
const opposite =
|
|
43
|
-
|
|
44
|
-
|
|
72
|
+
const opposite =
|
|
73
|
+
input.label === "not_spam"
|
|
74
|
+
? ne(senderReports.label, "not_spam")
|
|
75
|
+
: eq(senderReports.label, "not_spam");
|
|
76
|
+
|
|
45
77
|
await db.batch([
|
|
46
|
-
db
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
78
|
+
db
|
|
79
|
+
.delete(senderReports)
|
|
80
|
+
.where(
|
|
81
|
+
and(
|
|
82
|
+
eq(senderReports.mailboxId, input.mailboxId),
|
|
83
|
+
eq(senderReports.address, address),
|
|
84
|
+
opposite
|
|
85
|
+
)
|
|
86
|
+
),
|
|
87
|
+
db
|
|
88
|
+
.insert(senderReports)
|
|
89
|
+
.values(row)
|
|
90
|
+
.onConflictDoUpdate({
|
|
91
|
+
target: [senderReports.mailboxId, senderReports.emailId],
|
|
92
|
+
set: { label: row.label, createdAt: row.createdAt },
|
|
93
|
+
}),
|
|
55
94
|
]);
|
|
56
95
|
}
|
|
57
96
|
|
|
58
97
|
/** Verdicts other mailboxes in the workspace gave this sender and its domain. */
|
|
59
|
-
export async function workspaceFeedbackSummary(
|
|
98
|
+
export async function workspaceFeedbackSummary(
|
|
99
|
+
binding: D1Database,
|
|
100
|
+
mailboxId: string,
|
|
101
|
+
address: string
|
|
102
|
+
) {
|
|
60
103
|
const value = address.toLocaleLowerCase();
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
104
|
+
|
|
105
|
+
const [groups, reporters] = await binding.batch<
|
|
106
|
+
{
|
|
107
|
+
label: FeedbackLabel;
|
|
108
|
+
same_address: number;
|
|
109
|
+
count: number;
|
|
110
|
+
} & { mailboxes: number }
|
|
111
|
+
>([
|
|
112
|
+
binding
|
|
113
|
+
.prepare(`
|
|
67
114
|
select label, address = ?1 as same_address, count(*) as count
|
|
68
115
|
from sender_reports
|
|
69
116
|
where domain = ?2 and mailbox_id <> ?3
|
|
70
117
|
group by label, address = ?1
|
|
71
|
-
`)
|
|
72
|
-
|
|
118
|
+
`)
|
|
119
|
+
.bind(value, addressDomain(value), mailboxId),
|
|
120
|
+
binding
|
|
121
|
+
.prepare(`
|
|
73
122
|
select count(distinct mailbox_id) as mailboxes
|
|
74
123
|
from sender_reports
|
|
75
124
|
where address = ?1 and label <> 'not_spam' and mailbox_id <> ?2
|
|
76
|
-
`)
|
|
125
|
+
`)
|
|
126
|
+
.bind(value, mailboxId),
|
|
77
127
|
]);
|
|
128
|
+
|
|
78
129
|
const rows = groups?.results ?? [];
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
130
|
+
|
|
131
|
+
const count = (labels: FeedbackLabel[], sameAddress: boolean) =>
|
|
132
|
+
rows
|
|
133
|
+
.filter(
|
|
134
|
+
(row) =>
|
|
135
|
+
labels.includes(row.label) &&
|
|
136
|
+
Boolean(row.same_address) === sameAddress
|
|
137
|
+
)
|
|
138
|
+
.reduce((total, row) => total + Number(row.count), 0);
|
|
139
|
+
|
|
82
140
|
return {
|
|
83
141
|
spamReports: count(["spam"], true),
|
|
84
|
-
phishingReports: count(["phishing"], true),
|
|
85
142
|
notSpam: count(["not_spam"], true),
|
|
86
|
-
domainReports: count(["spam"
|
|
143
|
+
domainReports: count(["spam"], false),
|
|
87
144
|
/** How many other mailboxes reported this exact address. */
|
|
88
145
|
reportingMailboxes: Number(reporters?.results[0]?.mailboxes ?? 0),
|
|
89
146
|
};
|
|
90
147
|
}
|
|
91
148
|
|
|
92
|
-
export type WorkspaceFeedbackSummary = Awaited<
|
|
149
|
+
export type WorkspaceFeedbackSummary = Awaited<
|
|
150
|
+
ReturnType<typeof workspaceFeedbackSummary>
|
|
151
|
+
>;
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// service mail (fixed-width tables, inline styles, bulletproof buttons) so the
|
|
3
3
|
// reader's HTML path is exercised locally; every name, link and number is made up.
|
|
4
4
|
|
|
5
|
-
export const
|
|
6
|
-
<html><head><meta charset="utf-8"><title>
|
|
5
|
+
export const marginNotesHtml = `<!doctype html>
|
|
6
|
+
<html><head><meta charset="utf-8"><title>Margin Notes 341</title></head>
|
|
7
7
|
<body style="margin:0;padding:0;background:#f4f1ea">
|
|
8
8
|
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f4f1ea">
|
|
9
9
|
<tr><td align="center" style="padding:32px 12px">
|
|
10
10
|
<table role="presentation" width="600" cellpadding="0" cellspacing="0" style="width:600px;background:#ffffff;border:1px solid #e4dfd3">
|
|
11
|
-
<tr><td style="padding:28px 40px 0;font:600 13px/1.4 Helvetica,Arial,sans-serif;letter-spacing:.12em;text-transform:uppercase;color:#8a8170">
|
|
11
|
+
<tr><td style="padding:28px 40px 0;font:600 13px/1.4 Helvetica,Arial,sans-serif;letter-spacing:.12em;text-transform:uppercase;color:#8a8170">Margin Notes · Issue 341</td></tr>
|
|
12
12
|
<tr><td style="padding:12px 40px 0;font:400 34px/1.2 Georgia,'Times New Roman',serif;color:#1d1b16">Tools for thought</td></tr>
|
|
13
13
|
<tr><td style="padding:16px 40px 0"><hr style="border:0;border-top:1px solid #e4dfd3;margin:0"></td></tr>
|
|
14
14
|
<tr><td style="padding:20px 40px 0;font:400 16px/1.65 Helvetica,Arial,sans-serif;color:#3b372e">
|
|
@@ -40,7 +40,7 @@ export const denseDiscoveryHtml = `<!doctype html>
|
|
|
40
40
|
</td></tr></table>
|
|
41
41
|
</td></tr>
|
|
42
42
|
<tr><td style="padding:24px 40px 32px;font:400 12px/1.6 Helvetica,Arial,sans-serif;color:#8a8170">
|
|
43
|
-
You are receiving this because you subscribed to
|
|
43
|
+
You are receiving this because you subscribed to Margin Notes.<br>
|
|
44
44
|
<a href="https://example.com/dd/unsubscribe" style="color:#8a8170">Unsubscribe</a> · <a href="https://example.com/dd/archive" style="color:#8a8170">Past issues</a>
|
|
45
45
|
</td></tr>
|
|
46
46
|
</table>
|
|
@@ -48,7 +48,7 @@ You are receiving this because you subscribed to Dense Discovery.<br>
|
|
|
48
48
|
</table>
|
|
49
49
|
</body></html>`;
|
|
50
50
|
|
|
51
|
-
export const
|
|
51
|
+
export const canvaslyInvoiceHtml = `<!doctype html>
|
|
52
52
|
<html><head><meta charset="utf-8"><title>Your July invoice</title></head>
|
|
53
53
|
<body style="margin:0;padding:0;background:#f5f5f5">
|
|
54
54
|
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f5f5f5">
|
|
@@ -56,12 +56,12 @@ export const figmaInvoiceHtml = `<!doctype html>
|
|
|
56
56
|
<table role="presentation" width="640" cellpadding="0" cellspacing="0" style="width:640px;background:#ffffff;border-radius:8px">
|
|
57
57
|
<tr><td style="padding:24px 36px;background:#1e1e1e;border-radius:8px 8px 0 0">
|
|
58
58
|
<table role="presentation" width="100%" cellpadding="0" cellspacing="0"><tr>
|
|
59
|
-
<td style="font:700 20px/1 Helvetica,Arial,sans-serif;color:#ffffff">
|
|
59
|
+
<td style="font:700 20px/1 Helvetica,Arial,sans-serif;color:#ffffff">Canvasly</td>
|
|
60
60
|
<td align="right" style="font:400 13px/1 Helvetica,Arial,sans-serif;color:#bdbdbd">Invoice INV-2026-0714</td>
|
|
61
61
|
</tr></table>
|
|
62
62
|
</td></tr>
|
|
63
63
|
<tr><td style="padding:32px 36px 8px;font:600 26px/1.3 Helvetica,Arial,sans-serif;color:#1e1e1e">Your July invoice is ready</td></tr>
|
|
64
|
-
<tr><td style="padding:0 36px 24px;font:400 15px/1.6 Helvetica,Arial,sans-serif;color:#4d4d4d">Hi
|
|
64
|
+
<tr><td style="padding:0 36px 24px;font:400 15px/1.6 Helvetica,Arial,sans-serif;color:#4d4d4d">Hi Sam, thanks for working with us. No action is required — the card on file was charged automatically.</td></tr>
|
|
65
65
|
<tr><td style="padding:0 36px">
|
|
66
66
|
<table role="presentation" width="568" cellpadding="0" cellspacing="0" style="width:568px;border:1px solid #e6e6e6;border-collapse:collapse;font:400 14px/1.4 Helvetica,Arial,sans-serif;color:#1e1e1e">
|
|
67
67
|
<tr style="background:#fafafa">
|
|
@@ -1,79 +1,45 @@
|
|
|
1
|
-
import { createDb } from "@open-workspace/core/worker/db/client.ts";
|
|
2
|
-
import { reportedMessages } from "../db/schema";
|
|
3
|
-
import { emailSecurity } from "../mail/message-view";
|
|
4
|
-
import { reportSnapshot } from "../mail/reported-messages";
|
|
5
|
-
import { workspaceIdentity } from "../mail/security-settings";
|
|
6
|
-
import { storedSenderIntel } from "../mail/sender-intel";
|
|
7
1
|
import {
|
|
8
2
|
demoMailboxConversationState,
|
|
9
3
|
demoMailboxEmails,
|
|
10
4
|
demoMailboxObjects,
|
|
11
5
|
demoMailboxFolders,
|
|
12
6
|
demoMailboxEmailIds,
|
|
13
|
-
demoMailboxRules,
|
|
14
7
|
demoMailboxSenders,
|
|
15
|
-
demoReportedMessage,
|
|
16
8
|
} from "./demo";
|
|
17
9
|
import { mailboxStub } from "./index";
|
|
18
10
|
|
|
19
11
|
async function seedDemoMailbox(env: Env, mailboxId: string) {
|
|
20
12
|
const mailbox = mailboxStub(env, mailboxId);
|
|
21
13
|
const senders = demoMailboxSenders(mailboxId);
|
|
22
|
-
const rules = demoMailboxRules(mailboxId);
|
|
23
14
|
await mailbox.seedMailbox(
|
|
24
15
|
demoMailboxFolders(mailboxId),
|
|
25
16
|
demoMailboxEmails(mailboxId),
|
|
26
17
|
demoMailboxConversationState(mailboxId),
|
|
27
|
-
senders
|
|
28
|
-
rules,
|
|
18
|
+
senders
|
|
29
19
|
);
|
|
30
20
|
await mailbox.resetDemoSafetyState({
|
|
31
21
|
emailIds: demoMailboxEmailIds(mailboxId),
|
|
32
|
-
reportLabels: demoReportedMessage.mailboxId === mailboxId
|
|
33
|
-
? { [demoReportedMessage.emailId]: demoReportedMessage.reportLabel }
|
|
34
|
-
: {},
|
|
35
22
|
blockedPatterns: senders.flatMap((sender) =>
|
|
36
|
-
"blockedAt" in sender && sender.blockedAt
|
|
23
|
+
"blockedAt" in sender && sender.blockedAt
|
|
24
|
+
? [{ pattern: sender.address, at: sender.blockedAt.getTime() }]
|
|
25
|
+
: []
|
|
37
26
|
),
|
|
38
|
-
ruleIds: rules.map((rule) => rule.id),
|
|
39
27
|
});
|
|
40
28
|
}
|
|
41
29
|
|
|
42
|
-
/**
|
|
43
|
-
async function
|
|
44
|
-
const { mailboxId, emailId } = demoReportedMessage;
|
|
45
|
-
const email = await mailboxStub(env, mailboxId).getEmail(emailId);
|
|
46
|
-
if (!email) return;
|
|
47
|
-
const security = emailSecurity(email, await workspaceIdentity(env.DB), {});
|
|
48
|
-
await createDb(env.DB).insert(reportedMessages).values({
|
|
49
|
-
id: demoReportedMessage.id,
|
|
50
|
-
mailboxId,
|
|
51
|
-
emailId,
|
|
52
|
-
reporterUserId,
|
|
53
|
-
senderAddress: email.fromJson[0]?.address ?? "unknown@invalid",
|
|
54
|
-
senderDomain: email.fromJson[0]?.address.split("@")[1] ?? "invalid",
|
|
55
|
-
subject: email.subject,
|
|
56
|
-
receivedAt: email.timelineAt,
|
|
57
|
-
snapshotJson: reportSnapshot({ email, security, intel: storedSenderIntel(email.senderIntelJson), bodyHtml: null }),
|
|
58
|
-
status: "open",
|
|
59
|
-
createdAt: new Date(email.timelineAt.getTime() + 600_000),
|
|
60
|
-
}).onConflictDoNothing();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Seeds the demo administrator's mailboxes and the phishing report. */
|
|
64
|
-
export async function seedEmailDemo(env: Env, input: { userId: string }) {
|
|
65
|
-
const { userId } = input;
|
|
30
|
+
/** Seeds the demo administrator's mailboxes. */
|
|
31
|
+
export async function seedEmailDemo(env: Env) {
|
|
66
32
|
await Promise.all(
|
|
67
33
|
// Rows only reference the R2 keys, so objects and rows seed concurrently.
|
|
68
34
|
["mbx_demo_personal", "mbx_demo_support"].flatMap((mailboxId) => [
|
|
69
35
|
...demoMailboxObjects(mailboxId).map((object) =>
|
|
70
36
|
env.MAIL_STORAGE.put(object.key, object.body, {
|
|
71
37
|
httpMetadata: { contentType: object.contentType },
|
|
72
|
-
customMetadata:
|
|
73
|
-
|
|
38
|
+
customMetadata:
|
|
39
|
+
"customMetadata" in object ? object.customMetadata : undefined,
|
|
40
|
+
})
|
|
74
41
|
),
|
|
75
42
|
seedDemoMailbox(env, mailboxId),
|
|
76
|
-
])
|
|
43
|
+
])
|
|
77
44
|
);
|
|
78
|
-
await seedDemoReport(env, userId);
|
|
79
45
|
}
|