@open-workspace/email 0.0.0-stage → 0.1.1

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 (96) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +29 -2
  3. package/alchemy.ts +126 -0
  4. package/containers/office-preview/Dockerfile +10 -0
  5. package/index.ts +3 -0
  6. package/migrations/0000_email.sql +53 -0
  7. package/migrations/meta/0000_snapshot.json +408 -0
  8. package/migrations/meta/_journal.json +13 -0
  9. package/package.json +91 -4
  10. package/shared/attachment-preview.ts +67 -0
  11. package/shared/mail-authentication.ts +145 -0
  12. package/shared/mail-feedback.ts +90 -0
  13. package/shared/mail-headers.ts +250 -0
  14. package/shared/mail-received.ts +298 -0
  15. package/shared/mail-remote.ts +17 -0
  16. package/shared/mail-rules.ts +156 -0
  17. package/shared/mail-sender-intel.ts +125 -0
  18. package/shared/mail-translation.ts +2 -0
  19. package/shared/mail.ts +179 -0
  20. package/shared/office-preview.ts +26 -0
  21. package/worker/admin/report-routes.ts +164 -0
  22. package/worker/bindings.d.ts +11 -0
  23. package/worker/db/schema.ts +97 -0
  24. package/worker/mail/access.ts +30 -0
  25. package/worker/mail/ai-classification.ts +119 -0
  26. package/worker/mail/ai-translation.ts +31 -0
  27. package/worker/mail/auth-headers.ts +557 -0
  28. package/worker/mail/bimi.ts +172 -0
  29. package/worker/mail/classification-signals.ts +116 -0
  30. package/worker/mail/conversation-cursor.ts +43 -0
  31. package/worker/mail/delivery-events.ts +99 -0
  32. package/worker/mail/delivery-facts.ts +122 -0
  33. package/worker/mail/demo-routes.ts +33 -0
  34. package/worker/mail/doh.ts +74 -0
  35. package/worker/mail/downloads.ts +47 -0
  36. package/worker/mail/header-metadata.ts +77 -0
  37. package/worker/mail/impersonation.ts +175 -0
  38. package/worker/mail/inbound-delivery.ts +22 -0
  39. package/worker/mail/inbound-threading.ts +48 -0
  40. package/worker/mail/inbound.ts +255 -0
  41. package/worker/mail/ip-intel.ts +135 -0
  42. package/worker/mail/link-domains.ts +57 -0
  43. package/worker/mail/mailbox-deletion.ts +18 -0
  44. package/worker/mail/mailbox-directory.ts +73 -0
  45. package/worker/mail/mailing-list.ts +120 -0
  46. package/worker/mail/message-security.ts +190 -0
  47. package/worker/mail/message-view.ts +63 -0
  48. package/worker/mail/office-conversion.ts +38 -0
  49. package/worker/mail/office-preview-container.ts +57 -0
  50. package/worker/mail/office-preview-queue.ts +49 -0
  51. package/worker/mail/org-domain.ts +15 -0
  52. package/worker/mail/outbound-content.ts +208 -0
  53. package/worker/mail/outbound-delivery.ts +83 -0
  54. package/worker/mail/outbound-service.ts +145 -0
  55. package/worker/mail/outbound-threading.ts +70 -0
  56. package/worker/mail/outbound.ts +446 -0
  57. package/worker/mail/outgoing-context.ts +122 -0
  58. package/worker/mail/participants.ts +115 -0
  59. package/worker/mail/push-notifications.ts +484 -0
  60. package/worker/mail/quote-parser.ts +50 -0
  61. package/worker/mail/r2-presigned-urls.ts +69 -0
  62. package/worker/mail/receive.ts +59 -0
  63. package/worker/mail/recipients.ts +34 -0
  64. package/worker/mail/remote-proxy.ts +140 -0
  65. package/worker/mail/reply-plan.ts +136 -0
  66. package/worker/mail/reported-messages.ts +68 -0
  67. package/worker/mail/rfc.ts +73 -0
  68. package/worker/mail/routes.ts +1434 -0
  69. package/worker/mail/safety-routes.ts +350 -0
  70. package/worker/mail/schemas.ts +339 -0
  71. package/worker/mail/search.ts +14 -0
  72. package/worker/mail/security-settings.ts +38 -0
  73. package/worker/mail/sender-intel.ts +189 -0
  74. package/worker/mail/spamhaus.ts +97 -0
  75. package/worker/mail/unsubscribe.ts +118 -0
  76. package/worker/mail/uploads.ts +537 -0
  77. package/worker/mail/webhook-source.ts +71 -0
  78. package/worker/mail/workspace-safety.ts +92 -0
  79. package/worker/mailbox/demo-html.ts +136 -0
  80. package/worker/mailbox/demo-seed.ts +79 -0
  81. package/worker/mailbox/demo.ts +978 -0
  82. package/worker/mailbox/folder-model.ts +72 -0
  83. package/worker/mailbox/index.ts +2508 -0
  84. package/worker/mailbox/legacy-migrations.ts +41 -0
  85. package/worker/mailbox/migrations.ts +10 -0
  86. package/worker/mailbox/model.ts +65 -0
  87. package/worker/mailbox/office-preview-jobs.ts +73 -0
  88. package/worker/mailbox/rules.ts +110 -0
  89. package/worker/mailbox/schema.ts +353 -0
  90. package/worker/mailbox/senders.ts +240 -0
  91. package/worker/mcp/mail-action-tools.ts +210 -0
  92. package/worker/mcp/mail-compose-tools.ts +196 -0
  93. package/worker/mcp/mail-query-tools.ts +196 -0
  94. package/worker/mcp/mail-safety-tools.ts +452 -0
  95. package/worker/mcp/tools.ts +15 -0
  96. package/worker/module.ts +59 -0
@@ -0,0 +1,72 @@
1
+ export {
2
+ mailboxStates,
3
+ type MailboxState,
4
+ } from "../../shared/mail";
5
+
6
+ export const systemFolderTypes = [
7
+ "inbox",
8
+ "sent",
9
+ "archive",
10
+ "spam",
11
+ "trash",
12
+ ] as const;
13
+ export type SystemFolderType = (typeof systemFolderTypes)[number];
14
+
15
+ function inboxDistributionPredicate(conversationAlias: string) {
16
+ return `${conversationAlias}.has_incoming = 1 and ${conversationAlias}.mailbox_state = 'active'`;
17
+ }
18
+
19
+ const systemFolderPredicateBuilders: Record<
20
+ SystemFolderType,
21
+ (conversationAlias: string) => string
22
+ > = {
23
+ inbox: inboxDistributionPredicate,
24
+ sent: (alias) => `${alias}.has_outgoing = 1 and ${alias}.mailbox_state <> 'trash'`,
25
+ archive: (alias) => `${alias}.mailbox_state = 'archive'`,
26
+ spam: (alias) => `${alias}.mailbox_state = 'spam'`,
27
+ trash: (alias) => `${alias}.mailbox_state = 'trash'`,
28
+ };
29
+
30
+ export function systemFolderPredicate(
31
+ systemType: SystemFolderType,
32
+ conversationAlias: string,
33
+ ) {
34
+ return systemFolderPredicateBuilders[systemType](conversationAlias);
35
+ }
36
+
37
+ export function customFolderPredicate(conversationAlias: string) {
38
+ return inboxDistributionPredicate(conversationAlias);
39
+ }
40
+
41
+ export function folderAggregateJoinPredicate(
42
+ folderAlias: string,
43
+ conversationAlias: string,
44
+ ) {
45
+ const custom = `(
46
+ ${folderAlias}.kind = 'custom'
47
+ and ${conversationAlias}.folder_id = ${folderAlias}.id
48
+ and ${customFolderPredicate(conversationAlias)}
49
+ )`;
50
+ const system = systemFolderTypes.map((systemType) => `(
51
+ ${folderAlias}.system_type = '${systemType}'
52
+ and ${systemFolderPredicate(systemType, conversationAlias)}
53
+ )`);
54
+ return [custom, ...system].join("\n or ");
55
+ }
56
+
57
+ /**
58
+ * System folders are views over conversations, not stored folder records.
59
+ * Only user-defined classification folders live in SQLite.
60
+ */
61
+ export const systemFolderDefinitions = [
62
+ { id: "inbox", name: "Inbox", systemType: "inbox", sortOrder: 0 },
63
+ { id: "sent", name: "Sent", systemType: "sent", sortOrder: 1_000 },
64
+ { id: "archive", name: "Archive", systemType: "archive", sortOrder: 1_010 },
65
+ { id: "spam", name: "Spam", systemType: "spam", sortOrder: 1_020 },
66
+ { id: "trash", name: "Trash", systemType: "trash", sortOrder: 1_030 },
67
+ ] as const satisfies ReadonlyArray<{
68
+ id: string;
69
+ name: string;
70
+ systemType: SystemFolderType;
71
+ sortOrder: number;
72
+ }>;