@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
package/package.json CHANGED
@@ -1,93 +1,99 @@
1
1
  {
2
2
  "name": "@open-workspace/email",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Team mail for OpenWorkspace: personal and shared inboxes, mailing lists, previews, safety, and AI.",
5
+ "keywords": [
6
+ "alchemy",
7
+ "cloudflare",
8
+ "email",
9
+ "jmap",
10
+ "self-hosted",
11
+ "workers"
12
+ ],
13
+ "homepage": "https://openworkspace.dev",
5
14
  "license": "Apache-2.0",
6
- "type": "module",
7
15
  "repository": {
8
16
  "type": "git",
9
17
  "url": "git+https://github.com/iivankin/openworkspace.git",
10
18
  "directory": "packages/email"
11
19
  },
12
- "homepage": "https://openworkspace.dev",
20
+ "files": [
21
+ "index.ts",
22
+ "alchemy",
23
+ "src",
24
+ "worker",
25
+ "shared",
26
+ "migrations",
27
+ "drizzle",
28
+ "README.md",
29
+ "LICENSE"
30
+ ],
31
+ "type": "module",
13
32
  "exports": {
14
33
  ".": "./index.ts",
15
- "./alchemy": "./alchemy.ts",
34
+ "./alchemy": "./alchemy/index.ts",
35
+ "./client": "./src/client.tsx",
16
36
  "./*": "./*"
17
37
  },
18
38
  "scripts": {
19
- "typecheck": "tsc -p tsconfig.json",
20
- "db:generate": "drizzle-kit generate && drizzle-kit generate --config=drizzle.mailbox.config.ts && bun scripts/embed-mailbox-migrations.ts"
21
- },
22
- "peerDependencies": {
23
- "@open-workspace/core": "0.2.0",
24
- "alchemy": "2.0.0-beta.84",
25
- "@alchemy.run/cloudflare": "2.0.0-beta.84",
26
- "effect": "4.0.7"
39
+ "dev": "ALLOW_MOCK_AUTH=true alchemy dev dev/alchemy.run.ts",
40
+ "test": "bun run test:unit && bun run test:stack",
41
+ "test:unit": "bun test ./test/unit",
42
+ "test:stack": "bun test --preload ./test/stack/setup.ts --timeout 60000 ./test/stack",
43
+ "test:e2e": "playwright test -c test/e2e --project=desktop && playwright test -c test/e2e --project=mobile",
44
+ "typecheck": "tsc -p tsconfig.json && tsc -p test/tsconfig.json && tsc -p test/e2e/tsconfig.json",
45
+ "db:generate": "drizzle-kit generate && drizzle-kit generate --config=drizzle.mailbox.config.ts"
27
46
  },
28
47
  "dependencies": {
29
48
  "@hono/zod-validator": "0.9.1",
30
- "@mmmike/web-push": "1.3.0",
31
- "@modelcontextprotocol/server": "2.0.0",
49
+ "@mmmike/web-push": "1.5.0",
50
+ "@modelcontextprotocol/server": "2.4.0",
51
+ "@tanstack/react-query": "5.107.1",
52
+ "@tiptap/extension-placeholder": "3.33.1",
53
+ "@tiptap/pm": "3.33.1",
54
+ "@tiptap/react": "3.33.1",
55
+ "@tiptap/starter-kit": "3.33.1",
32
56
  "aws4fetch": "1.0.20",
33
- "drizzle-orm": "0.45.2",
34
- "hono": "4.13.5",
57
+ "date-fns": "4.4.0",
58
+ "dompurify": "3.4.17",
59
+ "drizzle-orm": "0.45.4",
60
+ "hono": "4.13.17",
35
61
  "html-to-text": "10.0.1",
36
- "postal-mime": "3.0.0",
37
- "tldts": "7.4.19",
38
- "zod": "4.5.4"
62
+ "lucide-react": "1.71.0",
63
+ "pdfjs-dist": "6.5.438",
64
+ "postal-mime": "4.2.1",
65
+ "react": "19.3.1",
66
+ "react-router": "8.5.1",
67
+ "sonner": "2.0.8",
68
+ "tldts": "7.4.21",
69
+ "zod": "4.6.7"
39
70
  },
40
71
  "devDependencies": {
41
- "@alchemy.run/cloudflare": "2.0.0-beta.84",
42
- "@base-ui/react": "1.7.0",
43
- "@effect/platform-bun": "4.0.7",
44
- "@effect/platform-node": "4.0.7",
45
- "@open-workspace/core": "0.2.0",
46
- "@simplewebauthn/browser": "13.3.0",
47
- "@tanstack/react-query": "5.102.8",
48
- "@tiptap/extension-image": "3.30.5",
49
- "@tiptap/extension-placeholder": "3.30.5",
50
- "@tiptap/pm": "3.30.5",
51
- "@tiptap/react": "3.30.5",
52
- "@tiptap/starter-kit": "3.30.5",
72
+ "@alchemy.run/cloudflare": "2.0.0-beta.85",
73
+ "@alchemy.run/test": "2.0.0-beta.85",
74
+ "@effect/platform-bun": "4.1.3",
75
+ "@effect/platform-node": "4.1.3",
76
+ "@open-workspace/core": "0.4.0",
77
+ "@open-workspace/create": "0.4.0",
78
+ "@types/bun": "1.4.4",
53
79
  "@types/html-to-text": "9.0.4",
54
- "@types/node": "26.4.0",
55
- "@types/react": "19.2.18",
56
- "@types/react-dom": "19.2.5",
57
- "alchemy": "2.0.0-beta.84",
58
- "class-variance-authority": "0.7.1",
59
- "clsx": "2.1.1",
60
- "cmdk": "1.1.1",
61
- "date-fns": "4.4.0",
62
- "dompurify": "3.4.14",
63
- "drizzle-kit": "0.31.10",
64
- "effect": "4.0.7",
65
- "lucide-react": "1.38.0",
66
- "pdfjs-dist": "6.3.289",
67
- "react": "19.2.8",
68
- "react-dom": "19.2.8",
69
- "react-router": "8.3.1",
70
- "sonner": "2.0.8",
71
- "tailwind-merge": "3.6.0",
80
+ "@types/node": "26.6.6",
81
+ "@types/react": "19.3.0",
82
+ "@types/react-dom": "19.3.0",
83
+ "ai": "7.0.166",
84
+ "alchemy": "2.0.0-beta.85",
85
+ "drizzle-kit": "0.31.11",
86
+ "effect": "4.1.3",
87
+ "openid-client": "6.8.9",
88
+ "playwright": "1.65.0",
89
+ "standardwebhooks": "1.1.1",
72
90
  "typescript": "7.0.2",
73
- "vite": "8.2.2"
91
+ "vite": "8.3.7"
74
92
  },
75
- "files": [
76
- "index.ts",
77
- "alchemy.ts",
78
- "worker",
79
- "shared",
80
- "migrations",
81
- "containers",
82
- "README.md",
83
- "LICENSE"
84
- ],
85
- "keywords": [
86
- "cloudflare",
87
- "workers",
88
- "email",
89
- "jmap",
90
- "self-hosted",
91
- "alchemy"
92
- ]
93
+ "peerDependencies": {
94
+ "@alchemy.run/cloudflare": "2.0.0-beta.85",
95
+ "@open-workspace/core": "0.4.0",
96
+ "alchemy": "2.0.0-beta.85",
97
+ "effect": "4.1.3"
98
+ }
93
99
  }
@@ -1,5 +1,6 @@
1
1
  import { isComposerInlineImageContentType } from "./mail";
2
- import { officePreviewExtension, type PdfPreviewStatus } from "./office-preview";
2
+ import { officePreviewExtension } from "./office-preview";
3
+ import type { PdfPreviewStatus } from "./office-preview";
3
4
 
4
5
  const TEXT_TYPES = new Set([
5
6
  "text/plain",
@@ -13,25 +14,25 @@ const TEXT_TYPES = new Set([
13
14
  "application/yaml",
14
15
  ]);
15
16
 
16
- const EXTENSION_TYPES: Record<string, string> = {
17
- pdf: "application/pdf",
18
- png: "image/png",
19
- jpg: "image/jpeg",
20
- jpeg: "image/jpeg",
21
- gif: "image/gif",
22
- webp: "image/webp",
23
- avif: "image/avif",
24
- bmp: "image/bmp",
25
- txt: "text/plain",
26
- log: "text/plain",
27
- md: "text/markdown",
28
- csv: "text/csv",
29
- tsv: "text/tab-separated-values",
30
- json: "application/json",
31
- xml: "application/xml",
32
- yaml: "application/yaml",
33
- yml: "application/yaml",
34
- };
17
+ const EXTENSION_TYPES = new Map([
18
+ ["pdf", "application/pdf"],
19
+ ["png", "image/png"],
20
+ ["jpg", "image/jpeg"],
21
+ ["jpeg", "image/jpeg"],
22
+ ["gif", "image/gif"],
23
+ ["webp", "image/webp"],
24
+ ["avif", "image/avif"],
25
+ ["bmp", "image/bmp"],
26
+ ["txt", "text/plain"],
27
+ ["log", "text/plain"],
28
+ ["md", "text/markdown"],
29
+ ["csv", "text/csv"],
30
+ ["tsv", "text/tab-separated-values"],
31
+ ["json", "application/json"],
32
+ ["xml", "application/xml"],
33
+ ["yaml", "application/yaml"],
34
+ ["yml", "application/yaml"],
35
+ ]);
35
36
 
36
37
  export function attachmentPreview(file: {
37
38
  filename: string;
@@ -44,24 +45,33 @@ export function attachmentPreview(file: {
44
45
  if (file.pdfPreviewStatus && officePreviewExtension(file.filename)) {
45
46
  return { kind: "pdf", contentType: "application/pdf" };
46
47
  }
47
- let contentType = file.contentType.split(";", 1)[0]?.trim().toLowerCase() ?? "";
48
+
49
+ let contentType =
50
+ file.contentType.split(";", 1)[0]?.trim().toLowerCase() ?? "";
51
+
48
52
  if (!contentType || contentType === "application/octet-stream") {
49
53
  const extension = file.filename.split(".").at(-1)?.toLowerCase() ?? "";
50
- contentType = Object.hasOwn(EXTENSION_TYPES, extension) ? EXTENSION_TYPES[extension]! : "";
54
+ contentType = EXTENSION_TYPES.get(extension) ?? "";
51
55
  }
56
+
52
57
  if (contentType === "application/pdf") return { kind: "pdf", contentType };
58
+
53
59
  if (
54
- isComposerInlineImageContentType(contentType)
55
- || contentType === "image/avif"
56
- || contentType === "image/bmp"
60
+ isComposerInlineImageContentType(contentType) ||
61
+ contentType === "image/avif" ||
62
+ contentType === "image/bmp"
57
63
  ) {
58
64
  return { kind: "image", contentType };
59
65
  }
66
+
60
67
  if (TEXT_TYPES.has(contentType)) {
61
- const charset = /;\s*charset\s*=\s*"?([a-zA-Z0-9_-]+)/iu.exec(file.contentType)?.[1]
62
- ?? "utf-8";
68
+ const charset =
69
+ /;\s*charset\s*=\s*"?([a-zA-Z0-9_-]+)/iu.exec(file.contentType)?.[1] ??
70
+ "utf-8";
71
+
63
72
  // XML and other structured text must never execute as same-origin documents.
64
73
  return { kind: "text", contentType: `text/plain; charset=${charset}` };
65
74
  }
75
+
66
76
  return null;
67
77
  }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * One order for every folder of a mailbox. Inbox is pinned first; the system
3
+ * folders after it can be placed anywhere among the person's own folders.
4
+ */
5
+
6
+ /** System folders that take part in the order; Inbox is always first. */
7
+ export const MOVABLE_SYSTEM_FOLDER_IDS = [
8
+ "sent",
9
+ "archive",
10
+ "spam",
11
+ "trash",
12
+ ] as const;
13
+
14
+ export type SystemFolderId =
15
+ | "inbox"
16
+ | (typeof MOVABLE_SYSTEM_FOLDER_IDS)[number];
17
+
18
+ /** Where the system folders sit until someone moves them: before any custom folder. */
19
+ export const DEFAULT_SYSTEM_FOLDER_ORDER = {
20
+ inbox: 0,
21
+ sent: 10,
22
+ archive: 20,
23
+ spam: 30,
24
+ trash: 40,
25
+ } satisfies Record<SystemFolderId, number>;
26
+
27
+ function isSystemFolderId(id: string): id is SystemFolderId {
28
+ return Object.hasOwn(DEFAULT_SYSTEM_FOLDER_ORDER, id);
29
+ }
30
+
31
+ /** The default position of a system folder by id; undefined for custom folders. */
32
+ export function defaultSystemFolderOrder(id: string) {
33
+ return isSystemFolderId(id) ? DEFAULT_SYSTEM_FOLDER_ORDER[id] : undefined;
34
+ }
35
+
36
+ /** The gap between neighbours, so a folder created later can go after the last. */
37
+ export const FOLDER_ORDER_STEP = 10;
38
+
39
+ /**
40
+ * Whether `folderIds` is a complete order of the movable folders: every
41
+ * movable system folder and custom folder exactly once, and never Inbox.
42
+ */
43
+ export function isCompleteFolderOrder(
44
+ folderIds: readonly string[],
45
+ customFolderIds: readonly string[]
46
+ ) {
47
+ const expected = new Set<string>([
48
+ ...MOVABLE_SYSTEM_FOLDER_IDS,
49
+ ...customFolderIds,
50
+ ]);
51
+
52
+ return (
53
+ folderIds.length === expected.size &&
54
+ new Set(folderIds).size === folderIds.length &&
55
+ folderIds.every((id) => expected.has(id))
56
+ );
57
+ }
58
+
59
+ /** The stored position of each folder in a complete order, after Inbox's 0. */
60
+ export function folderOrderPositions(folderIds: readonly string[]) {
61
+ return folderIds.map((id, index) => ({
62
+ id,
63
+ sortOrder: (index + 1) * FOLDER_ORDER_STEP,
64
+ }));
65
+ }
66
+
67
+ type Orderable = { id: string; name: string; sortOrder: number };
68
+
69
+ /** Folders in display order: Inbox first, then by position, ties by name. */
70
+ export function sortFolders<T extends Orderable>(folders: readonly T[]): T[] {
71
+ return [...folders].sort(
72
+ (left, right) =>
73
+ Number(right.id === "inbox") - Number(left.id === "inbox") ||
74
+ left.sortOrder - right.sortOrder ||
75
+ left.name.localeCompare(right.name)
76
+ );
77
+ }
78
+
79
+ /**
80
+ * The order after moving one folder a step up (-1) or down (+1), as the ids
81
+ * the reorder API takes (every folder but Inbox); null when it can't move.
82
+ */
83
+ export function moveFolderInOrder<T extends Orderable>(
84
+ folders: readonly T[],
85
+ folderId: string,
86
+ direction: -1 | 1
87
+ ) {
88
+ const ids = sortFolders(folders)
89
+ .map((folder) => folder.id)
90
+ .filter((id) => id !== "inbox");
91
+
92
+ const index = ids.indexOf(folderId);
93
+ const target = index + direction;
94
+
95
+ const moving = ids[index];
96
+ const neighbour = ids[target];
97
+
98
+ if (index === -1 || moving === undefined || neighbour === undefined) {
99
+ return null;
100
+ }
101
+
102
+ ids[index] = neighbour;
103
+ ids[target] = moving;
104
+
105
+ return ids;
106
+ }
@@ -14,6 +14,7 @@ export const authResults = [
14
14
  "permerror",
15
15
  "policy",
16
16
  ] as const;
17
+
17
18
  export type AuthResult = (typeof authResults)[number];
18
19
 
19
20
  export type DmarcPolicy = "none" | "quarantine" | "reject";
@@ -46,7 +47,11 @@ export type ArcSealer = {
46
47
  cv: string | null;
47
48
  };
48
49
 
49
- export type SenderVerdict = "verified" | "unverified" | "suspicious" | "unavailable";
50
+ export type SenderVerdict =
51
+ | "verified"
52
+ | "unverified"
53
+ | "suspicious"
54
+ | "unavailable";
50
55
 
51
56
  export type SenderVerdictReason =
52
57
  | "dmarc_pass"
@@ -78,7 +83,7 @@ export type InboundAuthentication = {
78
83
  result: AuthResult;
79
84
  headerFrom: string | null;
80
85
  policy: DmarcPolicy | null;
81
- alignedVia: Array<"spf" | "dkim">;
86
+ alignedVia: ("spf" | "dkim")[];
82
87
  } | null;
83
88
  arc: {
84
89
  result: "pass" | "fail" | "none";
@@ -131,7 +136,7 @@ export type MessageSecurity = {
131
136
  via: string | null;
132
137
  /** Organization that forwarded the message to this mailbox, when evident. */
133
138
  forwardedVia: string | null;
134
- /** The From domain is not one of this workspace's domains. */
139
+ /** The From domain is not one of this workspace's mail domains. */
135
140
  external: boolean;
136
141
  listUnsubscribe: ListUnsubscribe | null;
137
142
  /** Most serious first; the reader merges them into one banner. */
@@ -3,9 +3,8 @@
3
3
  * records, as returned with every incoming message.
4
4
  */
5
5
 
6
- export type ReportKind = "spam" | "phishing";
7
-
8
- export type FeedbackLabel = ReportKind | "not_spam";
6
+ /** What a person said about a sender: "Report spam" or "Not spam". */
7
+ export type FeedbackLabel = "spam" | "not_spam";
9
8
 
10
9
  export type SenderBlock = {
11
10
  /** The stored pattern: an address, or `@domain` for the whole domain. */
@@ -42,26 +41,8 @@ export type Unsubscription = {
42
41
  at: number;
43
42
  };
44
43
 
45
- export type ReportedMessageStatus = "open" | "resolved" | "dismissed";
46
-
47
- /** Point-in-time copy of what the reporter saw, kept with an admin report. */
48
- export type ReportSnapshot = {
49
- fromName: string | null;
50
- replyTo: string[];
51
- to: string[];
52
- verdict: string;
53
- verdictReason: string;
54
- warnings: string[];
55
- spamScore: number | null;
56
- ip: string | null;
57
- network: string | null;
58
- country: string | null;
59
- ai: { spam: boolean; spamConfidence: number; reason: string } | null;
60
- linkDomains: string[];
61
- preview: string;
62
- };
63
-
64
- const DOMAIN_PATTERN = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9-]{2,63}$/u;
44
+ const DOMAIN_PATTERN =
45
+ /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9-]{2,63}$/u;
65
46
 
66
47
  /**
67
48
  * Normalizes a block entry: `alex@x.com` stays an address, `x.com` and
@@ -69,13 +50,20 @@ const DOMAIN_PATTERN = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9-]{2,
69
50
  */
70
51
  export function normalizeBlockPattern(value: string) {
71
52
  const input = value.trim().toLocaleLowerCase();
53
+
72
54
  if (input.length > 320) return null;
73
55
  const at = input.lastIndexOf("@");
56
+
74
57
  if (at > 0) {
75
58
  const domain = input.slice(at + 1);
76
- return DOMAIN_PATTERN.test(domain) && !/[\s<>,;"]/u.test(input.slice(0, at)) ? input : null;
59
+
60
+ return DOMAIN_PATTERN.test(domain) && !/[\s<>,;"]/u.test(input.slice(0, at))
61
+ ? input
62
+ : null;
77
63
  }
64
+
78
65
  const domain = at === 0 ? input.slice(1) : input;
66
+
79
67
  return DOMAIN_PATTERN.test(domain) ? `@${domain}` : null;
80
68
  }
81
69
 
@@ -83,8 +71,13 @@ export function normalizeBlockPattern(value: string) {
83
71
  export function blockPatternsFor(address: string) {
84
72
  const value = address.trim().toLocaleLowerCase();
85
73
  const at = value.lastIndexOf("@");
74
+
86
75
  if (at <= 0) return [];
87
76
  const labels = value.slice(at + 1).split(".");
88
- const domains = labels.slice(0, -1).map((_, index) => `@${labels.slice(index).join(".")}`);
77
+
78
+ const domains = labels
79
+ .slice(0, -1)
80
+ .map((_, index) => `@${labels.slice(index).join(".")}`);
81
+
89
82
  return [value, ...domains];
90
83
  }