@open-workspace/email 0.2.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.
Files changed (223) hide show
  1. package/README.md +23 -20
  2. package/alchemy/index.ts +273 -0
  3. package/drizzle/mailbox/0000_puzzling_dracula.sql +149 -0
  4. package/drizzle/mailbox/0001_mute_jack_flag.sql +12 -0
  5. package/drizzle/mailbox/meta/0000_snapshot.json +1002 -0
  6. package/drizzle/mailbox/meta/0001_snapshot.json +1002 -0
  7. package/drizzle/mailbox/meta/_journal.json +20 -0
  8. package/drizzle/mailbox/migrations.js +12 -0
  9. package/index.ts +3 -1
  10. package/migrations/0000_dry_moon_knight.sql +77 -0
  11. package/migrations/meta/0000_snapshot.json +248 -106
  12. package/migrations/meta/_journal.json +2 -2
  13. package/package.json +74 -68
  14. package/shared/attachment-preview.ts +37 -27
  15. package/shared/folder-order.ts +106 -0
  16. package/shared/mail-authentication.ts +8 -3
  17. package/shared/mail-feedback.ts +18 -25
  18. package/shared/mail-headers.ts +114 -39
  19. package/shared/mail-import.ts +38 -0
  20. package/shared/mail-path.ts +42 -0
  21. package/shared/mail-received.ts +174 -31
  22. package/shared/mail-remote.ts +59 -2
  23. package/shared/mail-sender-intel.ts +22 -4
  24. package/shared/mail.ts +78 -26
  25. package/shared/module.ts +33 -0
  26. package/shared/office-preview.ts +14 -2
  27. package/shared/pdfjs-assets.ts +35 -0
  28. package/shared/permissions.ts +73 -0
  29. package/shared/webhooks.ts +41 -0
  30. package/src/admin/blocked-senders.tsx +189 -0
  31. package/src/client.tsx +97 -0
  32. package/src/lib/mail-api.ts +9 -0
  33. package/src/mail/attachment-preview-dialog.tsx +161 -0
  34. package/src/mail/blocked-senders.tsx +138 -0
  35. package/src/mail/compose-window-chrome.tsx +194 -0
  36. package/src/mail/compose-window.tsx +486 -0
  37. package/src/mail/composer-asset-bookmarks.ts +409 -0
  38. package/src/mail/composer-asset.tsx +229 -0
  39. package/src/mail/composer-attachment-list.tsx +138 -0
  40. package/src/mail/composer-editor-document.ts +65 -0
  41. package/src/mail/composer-editor.tsx +284 -0
  42. package/src/mail/composer-linked-attachment-text.ts +12 -0
  43. package/src/mail/composer-recipient-fields.tsx +165 -0
  44. package/src/mail/composer-recipients.ts +208 -0
  45. package/src/mail/composer-session.ts +562 -0
  46. package/src/mail/composer-toolbar.tsx +303 -0
  47. package/src/mail/composer-upload-client.ts +105 -0
  48. package/src/mail/composer-upload-progress.ts +53 -0
  49. package/src/mail/conversation-list.tsx +550 -0
  50. package/src/mail/conversation-loading-skeleton.tsx +119 -0
  51. package/src/mail/conversation-message.tsx +346 -0
  52. package/src/mail/conversation-reply.tsx +470 -0
  53. package/src/mail/conversation-selection-toolbar.tsx +322 -0
  54. package/src/mail/conversation-view.tsx +437 -0
  55. package/src/mail/delivery-indicator.tsx +272 -0
  56. package/src/mail/email-html-body.tsx +203 -0
  57. package/src/mail/folder-glyph.tsx +46 -0
  58. package/src/mail/folder-manager.tsx +532 -0
  59. package/src/mail/format-bytes.ts +7 -0
  60. package/src/mail/mail-app-bar.tsx +253 -0
  61. package/src/mail/mail-background.tsx +12 -0
  62. package/src/mail/mail-dock.tsx +137 -0
  63. package/src/mail/mail-folders.ts +44 -0
  64. package/src/mail/mail-layout.css +236 -0
  65. package/src/mail/mail-location.ts +73 -0
  66. package/src/mail/mail-mailbox-sheet.tsx +275 -0
  67. package/src/mail/mail-nav-rail.tsx +129 -0
  68. package/src/mail/mail-nav.tsx +324 -0
  69. package/src/mail/mail-prefetch.ts +59 -0
  70. package/src/mail/mail-primitives.tsx +66 -0
  71. package/src/mail/mail-queries.ts +209 -0
  72. package/src/mail/mail-query-cache.ts +486 -0
  73. package/src/mail/mail-seed.ts +47 -0
  74. package/src/mail/mail-shell.tsx +126 -0
  75. package/src/mail/mailbox-ai-settings.tsx +185 -0
  76. package/src/mail/mailbox-realtime.tsx +251 -0
  77. package/src/mail/mailbox-route.tsx +15 -0
  78. package/src/mail/message-actions.tsx +353 -0
  79. package/src/mail/message-attachments.tsx +200 -0
  80. package/src/mail/message-format.ts +75 -0
  81. package/src/mail/message-header.tsx +260 -0
  82. package/src/mail/message-translation.tsx +225 -0
  83. package/src/mail/original-message-sheet.tsx +619 -0
  84. package/src/mail/original-message.ts +191 -0
  85. package/src/mail/outbound-notification.ts +53 -0
  86. package/src/mail/pane-splitter.tsx +117 -0
  87. package/src/mail/pdf-preview-toolbar.tsx +152 -0
  88. package/src/mail/pdf-preview.css +44 -0
  89. package/src/mail/pdf-preview.tsx +156 -0
  90. package/src/mail/pdf-translation-layout.ts +95 -0
  91. package/src/mail/print-message.ts +92 -0
  92. package/src/mail/reader-pane.tsx +535 -0
  93. package/src/mail/recipient-combobox.tsx +335 -0
  94. package/src/mail/recipient-field-row.tsx +34 -0
  95. package/src/mail/reply-to-warning.tsx +50 -0
  96. package/src/mail/sanitize-email-html.ts +430 -0
  97. package/src/mail/sender-actions.tsx +149 -0
  98. package/src/mail/sender-authentication.tsx +485 -0
  99. package/src/mail/sender-dialogs.tsx +384 -0
  100. package/src/mail/sender-security.tsx +545 -0
  101. package/src/mail/toolbar-tooltip.tsx +29 -0
  102. package/src/mail/translation-html.ts +49 -0
  103. package/src/mail/translation-language.ts +21 -0
  104. package/src/mail/types.ts +53 -0
  105. package/src/mail/unread-document-indicator.tsx +60 -0
  106. package/src/mail/use-compose-submission.ts +208 -0
  107. package/src/mail/use-composer-attachment-preflight.ts +184 -0
  108. package/src/mail/use-composer-submission.ts +117 -0
  109. package/src/mail/use-conversation-selection.ts +186 -0
  110. package/src/mail/use-mail-controller.ts +427 -0
  111. package/src/mail/use-mail-data.ts +279 -0
  112. package/src/mail/use-mail-safety.ts +155 -0
  113. package/src/mail/use-mail-send.ts +142 -0
  114. package/src/mail/use-pdf-translation-overlay.ts +156 -0
  115. package/src/mail/use-pdf-translation.ts +100 -0
  116. package/src/mail/use-pdf-viewer.ts +215 -0
  117. package/src/mail/use-reply-submission.ts +114 -0
  118. package/src/mail/use-sanitized-email-html.ts +20 -0
  119. package/src/mail/use-visible-message-read.ts +138 -0
  120. package/src/pwa/push-subscription.ts +151 -0
  121. package/src/settings/mail-apps-page.tsx +235 -0
  122. package/src/settings/notifications-page.tsx +291 -0
  123. package/worker/admin/blocked-sender-routes.ts +166 -0
  124. package/worker/admin/schemas.ts +11 -0
  125. package/worker/bindings.d.ts +14 -10
  126. package/worker/db/schema.ts +90 -34
  127. package/worker/jmap/eventsource.ts +169 -0
  128. package/worker/jmap/methods.ts +1716 -361
  129. package/worker/jmap/push-types.ts +27 -0
  130. package/worker/jmap/push.ts +207 -0
  131. package/worker/jmap/routes.ts +448 -86
  132. package/worker/mail/access.ts +258 -21
  133. package/worker/mail/ai-classification.ts +36 -20
  134. package/worker/mail/ai-translation.ts +13 -6
  135. package/worker/mail/auth-headers.ts +395 -137
  136. package/worker/mail/bimi.ts +200 -73
  137. package/worker/mail/bootstrap.ts +79 -0
  138. package/worker/mail/capped-body.ts +36 -0
  139. package/worker/mail/classification-signals.ts +35 -25
  140. package/worker/mail/conversation-cursor.ts +30 -19
  141. package/worker/mail/delivery-events.ts +88 -62
  142. package/worker/mail/delivery-facts.ts +46 -10
  143. package/worker/mail/demo-routes.ts +34 -10
  144. package/worker/mail/doh.ts +62 -23
  145. package/worker/mail/downloads.ts +75 -40
  146. package/worker/mail/edge-cache.ts +155 -0
  147. package/worker/mail/header-metadata.ts +84 -52
  148. package/worker/mail/impersonation.ts +160 -38
  149. package/worker/mail/import-routes.ts +313 -0
  150. package/worker/mail/inbound-delivery.ts +19 -9
  151. package/worker/mail/inbound-threading.ts +18 -8
  152. package/worker/mail/inbound.ts +82 -40
  153. package/worker/mail/ip-intel.ts +110 -27
  154. package/worker/mail/isolate-cache.ts +35 -0
  155. package/worker/mail/link-domains.ts +29 -7
  156. package/worker/mail/mailbox-deletion.ts +10 -4
  157. package/worker/mail/mailbox-directory.ts +16 -6
  158. package/worker/mail/mailing-list.ts +94 -39
  159. package/worker/mail/message-security.ts +90 -15
  160. package/worker/mail/message-view.ts +18 -6
  161. package/worker/mail/office-conversion.ts +31 -9
  162. package/worker/mail/office-preview-container.ts +40 -13
  163. package/worker/mail/office-preview-queue.ts +76 -32
  164. package/worker/mail/org-domain.ts +8 -1
  165. package/worker/mail/outbound-content.ts +71 -26
  166. package/worker/mail/outbound-delivery.ts +31 -17
  167. package/worker/mail/outbound-service.ts +48 -30
  168. package/worker/mail/outbound-threading.ts +30 -17
  169. package/worker/mail/outbound.ts +97 -70
  170. package/worker/mail/outgoing-context.ts +25 -15
  171. package/worker/mail/participants.ts +44 -29
  172. package/worker/mail/push-notifications.ts +283 -171
  173. package/worker/mail/quote-parser.ts +21 -10
  174. package/worker/mail/r2-presigned-urls.ts +31 -25
  175. package/worker/mail/receive.ts +23 -11
  176. package/worker/mail/recipients.ts +6 -1
  177. package/worker/mail/remote-proxy.ts +187 -31
  178. package/worker/mail/remote-routes.ts +87 -0
  179. package/worker/mail/remote-token.ts +104 -0
  180. package/worker/mail/repeat.ts +19 -0
  181. package/worker/mail/reply-plan.ts +62 -33
  182. package/worker/mail/rfc.ts +32 -7
  183. package/worker/mail/routes.ts +871 -542
  184. package/worker/mail/safety-routes.ts +329 -202
  185. package/worker/mail/schemas.ts +84 -105
  186. package/worker/mail/search.ts +1 -0
  187. package/worker/mail/security-settings.ts +41 -9
  188. package/worker/mail/sender-intel.ts +206 -51
  189. package/worker/mail/spamhaus.ts +92 -45
  190. package/worker/mail/unsubscribe.ts +76 -18
  191. package/worker/mail/uploads.ts +153 -91
  192. package/worker/mail/webhook-source.ts +35 -12
  193. package/worker/mail/workspace-safety.ts +97 -38
  194. package/worker/mailbox/demo-html.ts +7 -7
  195. package/worker/mailbox/demo-seed.ts +10 -44
  196. package/worker/mailbox/demo.ts +597 -227
  197. package/worker/mailbox/email-index.ts +53 -0
  198. package/worker/mailbox/folder-model.ts +53 -17
  199. package/worker/mailbox/import-placement.ts +88 -0
  200. package/worker/mailbox/inbox-counts.ts +106 -0
  201. package/worker/mailbox/index.ts +1761 -737
  202. package/worker/mailbox/jmap-store.ts +139 -35
  203. package/worker/mailbox/model.ts +7 -14
  204. package/worker/mailbox/office-preview-jobs.ts +56 -25
  205. package/worker/mailbox/schema.ts +87 -66
  206. package/worker/mailbox/senders.ts +176 -70
  207. package/worker/mcp/mail-action-tools.ts +128 -87
  208. package/worker/mcp/mail-compose-tools.ts +133 -82
  209. package/worker/mcp/mail-query-tools.ts +120 -71
  210. package/worker/mcp/mail-safety-tools.ts +321 -248
  211. package/worker/mcp/schemas.ts +43 -0
  212. package/worker/mcp/tools.ts +13 -10
  213. package/worker/module.ts +43 -18
  214. package/worker/sql.d.ts +8 -0
  215. package/alchemy.ts +0 -126
  216. package/containers/office-preview/Dockerfile +0 -10
  217. package/migrations/0000_email.sql +0 -53
  218. package/shared/mail-rules.ts +0 -156
  219. package/worker/admin/report-routes.ts +0 -164
  220. package/worker/mail/reported-messages.ts +0 -68
  221. package/worker/mailbox/legacy-migrations.ts +0 -41
  222. package/worker/mailbox/migrations.ts +0 -10
  223. 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 = 5_000;
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({ pattern: blockedSenders.pattern, createdAt: blockedSenders.createdAt })
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, phishing or not-spam verdict with the rest of the workspace. */
24
- export async function recordWorkspaceFeedback(binding: D1Database, input: {
25
- mailboxId: string;
26
- emailId: string;
27
- address: string;
28
- label: FeedbackLabel;
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 = input.label === "not_spam"
43
- ? ne(senderReports.label, "not_spam")
44
- : eq(senderReports.label, "not_spam");
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.delete(senderReports).where(and(
47
- eq(senderReports.mailboxId, input.mailboxId),
48
- eq(senderReports.address, address),
49
- opposite,
50
- )),
51
- db.insert(senderReports).values(row).onConflictDoUpdate({
52
- target: [senderReports.mailboxId, senderReports.emailId],
53
- set: { label: row.label, createdAt: row.createdAt },
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(binding: D1Database, mailboxId: string, address: string) {
98
+ export async function workspaceFeedbackSummary(
99
+ binding: D1Database,
100
+ mailboxId: string,
101
+ address: string
102
+ ) {
60
103
  const value = address.toLocaleLowerCase();
61
- const [groups, reporters] = await binding.batch<{
62
- label: FeedbackLabel;
63
- same_address: number;
64
- count: number;
65
- } & { mailboxes: number }>([
66
- binding.prepare(`
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
- `).bind(value, addressDomain(value), mailboxId),
72
- binding.prepare(`
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
- `).bind(value, mailboxId),
125
+ `)
126
+ .bind(value, mailboxId),
77
127
  ]);
128
+
78
129
  const rows = groups?.results ?? [];
79
- const count = (labels: FeedbackLabel[], sameAddress: boolean) => rows
80
- .filter((row) => labels.includes(row.label) && Boolean(row.same_address) === sameAddress)
81
- .reduce((total, row) => total + Number(row.count), 0);
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", "phishing"], false),
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<ReturnType<typeof workspaceFeedbackSummary>>;
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 denseDiscoveryHtml = `<!doctype html>
6
- <html><head><meta charset="utf-8"><title>Dense Discovery 341</title></head>
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">Dense Discovery · Issue 341</td></tr>
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 Dense Discovery.<br>
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 figmaInvoiceHtml = `<!doctype html>
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">Figma</td>
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 Ilya, thanks for working with us. No action is required — the card on file was charged automatically.</td></tr>
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 ? [{ pattern: sender.address, at: sender.blockedAt.getTime() }] : []
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
- /** The pre-seeded phishing report in Administration; kept once created. */
43
- async function seedDemoReport(env: Env, reporterUserId: string) {
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: "customMetadata" in object ? object.customMetadata : undefined,
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
  }