@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.
Files changed (221) hide show
  1. package/README.md +22 -22
  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_email.sql → 0000_dry_moon_knight.sql} +26 -20
  11. package/migrations/meta/0000_snapshot.json +125 -109
  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 +77 -28
  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 +63 -40
  127. package/worker/jmap/eventsource.ts +84 -16
  128. package/worker/jmap/methods.ts +1630 -524
  129. package/worker/jmap/push-types.ts +27 -0
  130. package/worker/jmap/push.ts +140 -56
  131. package/worker/jmap/routes.ts +366 -105
  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 +88 -22
  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 +271 -173
  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 +870 -541
  184. package/worker/mail/safety-routes.ts +328 -200
  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 +126 -93
  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 +595 -225
  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 +1734 -721
  202. package/worker/mailbox/jmap-store.ts +139 -35
  203. package/worker/mailbox/model.ts +8 -6
  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 -142
  216. package/containers/office-preview/Dockerfile +0 -10
  217. package/shared/mail-rules.ts +0 -156
  218. package/worker/admin/report-routes.ts +0 -164
  219. package/worker/mail/reported-messages.ts +0 -68
  220. package/worker/mailbox/migrations.ts +0 -10
  221. package/worker/mailbox/rules.ts +0 -110
@@ -1,14 +1,12 @@
1
- import {
2
- authResults,
3
- type ArcSealer,
4
- type AuthResult,
5
- type DkimResult,
6
- type DmarcPolicy,
7
- type InboundAuthentication,
8
- type ListUnsubscribe,
9
- type SenderVerdict,
10
- type SenderVerdictReason,
11
- type UpstreamAuthenticationClaim,
1
+ import { authResults } from "../../shared/mail-authentication";
2
+ import type {
3
+ ArcSealer,
4
+ AuthResult,
5
+ DkimResult,
6
+ DmarcPolicy,
7
+ InboundAuthentication,
8
+ ListUnsubscribe,
9
+ UpstreamAuthenticationClaim,
12
10
  } from "../../shared/mail-authentication";
13
11
  import {
14
12
  addressDomain,
@@ -16,8 +14,8 @@ import {
16
14
  scanComments,
17
15
  splitTopLevel,
18
16
  unquote,
19
- type HeaderField,
20
17
  } from "../../shared/mail-headers";
18
+ import type { HeaderField } from "../../shared/mail-headers";
21
19
  import {
22
20
  isCloudflareHop,
23
21
  normalizeIp,
@@ -27,7 +25,8 @@ import { relaxedAligned } from "./org-domain";
27
25
 
28
26
  export const CLOUDFLARE_AUTHSERV_ID = "mx.cloudflare.net";
29
27
  const CLOUDFLARE_ARC_DOMAIN = "cloudflare-email.net";
30
- const MAX_TRUSTED_HEADER_LENGTH = 4_096;
28
+ const MAX_TRUSTED_HEADER_LENGTH = 4096;
29
+
31
30
  /** Cloudflare prepends 7 headers; the cap only matters when the score header is missing. */
32
31
  const MAX_TRUSTED_BLOCK_WITHOUT_SCORE = 10;
33
32
  const MAX_UPSTREAM_CLAIMS = 5;
@@ -70,22 +69,38 @@ const VALUE = String.raw`"(?:[^"\\]|\\.)*"|[^\s;]+`;
70
69
  function parseResInfo(segment: string): AuthResInfo | null {
71
70
  const { text, comments } = scanComments(segment);
72
71
  const method = /^\s*([a-z0-9_-]+)(?:\/\d+)?\s*=\s*([a-z0-9_-]+)/iu.exec(text);
72
+
73
73
  if (!method) return null;
74
74
  let rest = text.slice(method[0].length);
75
75
  let reason: string | null = null;
76
- const reasonMatch = new RegExp(String.raw`\breason\s*=\s*(${VALUE})`, "iu").exec(rest);
76
+
77
+ const reasonMatch = new RegExp(
78
+ String.raw`\breason\s*=\s*(${VALUE})`,
79
+ "iu"
80
+ ).exec(rest);
81
+
77
82
  if (reasonMatch) {
78
- reason = unquote(reasonMatch[1]!);
79
- rest = rest.slice(0, reasonMatch.index) + rest.slice(reasonMatch.index + reasonMatch[0].length);
83
+ reason = unquote(reasonMatch[1]);
84
+ rest =
85
+ rest.slice(0, reasonMatch.index) +
86
+ rest.slice(reasonMatch.index + reasonMatch[0].length);
80
87
  }
88
+
81
89
  const props: Record<string, string> = {};
82
- for (const match of rest.matchAll(new RegExp(String.raw`([a-z0-9_-]+)\s*\.\s*([a-z0-9_-]+)\s*=\s*(${VALUE})`, "giu"))) {
90
+
91
+ for (const match of rest.matchAll(
92
+ new RegExp(
93
+ String.raw`([a-z0-9_-]+)\s*\.\s*([a-z0-9_-]+)\s*=\s*(${VALUE})`,
94
+ "giu"
95
+ )
96
+ )) {
83
97
  const key = `${match[1]}.${match[2]}`.toLocaleLowerCase();
84
- props[key] ??= unquote(match[3]!);
98
+ props[key] ??= unquote(match[3]);
85
99
  }
100
+
86
101
  return {
87
- method: method[1]!.toLocaleLowerCase(),
88
- result: method[2]!.toLocaleLowerCase(),
102
+ method: method[1].toLocaleLowerCase(),
103
+ result: method[2].toLocaleLowerCase(),
89
104
  reason,
90
105
  comments,
91
106
  props,
@@ -93,14 +108,23 @@ function parseResInfo(segment: string): AuthResInfo | null {
93
108
  }
94
109
 
95
110
  /** Parses an Authentication-Results value (RFC 8601 §2.2), comments and all. */
96
- export function parseAuthenticationResults(value: string): ParsedAuthenticationResults | null {
111
+ export function parseAuthenticationResults(
112
+ value: string
113
+ ): ParsedAuthenticationResults | null {
97
114
  const segments = splitTopLevel(value, ";");
98
- const authservId = scanComments(segments[0] ?? "").text.trim().split(/\s+/u)[0]?.toLocaleLowerCase();
115
+
116
+ const authservId = scanComments(segments[0] ?? "")
117
+ .text.trim()
118
+ .split(/\s+/u)[0]
119
+ ?.toLocaleLowerCase();
120
+
99
121
  if (!authservId) return null;
122
+
100
123
  return {
101
124
  authservId,
102
125
  results: segments.slice(1).flatMap((segment) => {
103
126
  const info = parseResInfo(segment);
127
+
104
128
  return info ? [info] : [];
105
129
  }),
106
130
  };
@@ -109,8 +133,10 @@ export function parseAuthenticationResults(value: string): ParsedAuthenticationR
109
133
  /** ARC-Authentication-Results carries `i=N;` before the A-R payload. */
110
134
  export function parseArcAuthenticationResults(value: string) {
111
135
  const instance = /^\s*i\s*=\s*(\d+)\s*;/u.exec(value);
136
+
112
137
  if (!instance) return null;
113
138
  const parsed = parseAuthenticationResults(value.slice(instance[0].length));
139
+
114
140
  return parsed ? { instance: Number(instance[1]), ...parsed } : null;
115
141
  }
116
142
 
@@ -124,15 +150,22 @@ export type ParsedReceivedSpf = {
124
150
 
125
151
  export function parseReceivedSpf(value: string): ParsedReceivedSpf | null {
126
152
  const result = /^\s*([a-z]+)/iu.exec(value);
153
+
127
154
  if (!result) return null;
128
155
  const { text, comments } = scanComments(value.slice(result[0].length));
129
156
  const pairs: Record<string, string> = {};
157
+
130
158
  for (const part of splitTopLevel(text, ";")) {
131
- const pair = new RegExp(String.raw`^\s*([a-z-]+)\s*=\s*(${VALUE})\s*$`, "iu").exec(part);
132
- if (pair) pairs[pair[1]!.toLocaleLowerCase()] ??= unquote(pair[2]!);
159
+ const pair = new RegExp(
160
+ String.raw`^\s*([a-z-]+)\s*=\s*(${VALUE})\s*$`,
161
+ "iu"
162
+ ).exec(part);
163
+
164
+ if (pair) pairs[pair[1].toLocaleLowerCase()] ??= unquote(pair[2]);
133
165
  }
166
+
134
167
  return {
135
- result: result[1]!.toLocaleLowerCase(),
168
+ result: result[1].toLocaleLowerCase(),
136
169
  comment: comments[0] ?? null,
137
170
  pairs,
138
171
  };
@@ -142,33 +175,49 @@ export function parseReceivedSpf(value: string): ParsedReceivedSpf | null {
142
175
 
143
176
  export function parseTagList(value: string) {
144
177
  const tags: Record<string, string> = {};
178
+
145
179
  for (const part of value.split(";")) {
146
180
  const equals = part.indexOf("=");
181
+
147
182
  if (equals < 1) continue;
148
183
  const name = part.slice(0, equals).trim().toLocaleLowerCase();
184
+
149
185
  if (!/^[a-z][a-z0-9_]*$/u.test(name) || name in tags) continue;
150
- tags[name] = part.slice(equals + 1).replace(/\s+/gu, name === "h" ? "" : " ").trim();
186
+ tags[name] = part
187
+ .slice(equals + 1)
188
+ .replaceAll(/\s+/gu, name === "h" ? "" : " ")
189
+ .trim();
151
190
  }
191
+
152
192
  return tags;
153
193
  }
154
194
 
155
- type DkimSignatureTags = { domain: string; selector: string | null; b: string; signedHeaders: string[] };
195
+ type DkimSignatureTags = {
196
+ domain: string;
197
+ selector: string | null;
198
+ b: string;
199
+ signedHeaders: string[];
200
+ };
156
201
 
157
202
  function dkimSignatureTags(fields: HeaderField[]): DkimSignatureTags[] {
158
203
  return fields.flatMap((field) => {
159
204
  if (field.name !== "dkim-signature") return [];
160
205
  const tags = parseTagList(field.value);
161
206
  const domain = addressDomain(tags.d);
207
+
162
208
  if (!domain) return [];
163
- return [{
164
- domain,
165
- selector: tags.s?.trim() ?? null,
166
- b: (tags.b ?? "").replace(/\s+/gu, ""),
167
- signedHeaders: (tags.h ?? "")
168
- .split(":")
169
- .map((name) => name.trim().toLocaleLowerCase())
170
- .filter(Boolean),
171
- }];
209
+
210
+ return [
211
+ {
212
+ domain,
213
+ selector: tags.s?.trim() ?? null,
214
+ b: (tags.b ?? "").replaceAll(/\s+/gu, ""),
215
+ signedHeaders: (tags.h ?? "")
216
+ .split(":")
217
+ .map((name) => name.trim().toLocaleLowerCase())
218
+ .filter(Boolean),
219
+ },
220
+ ];
172
221
  });
173
222
  }
174
223
 
@@ -180,26 +229,50 @@ function dkimSignatureTags(fields: HeaderField[]): DkimSignatureTags[] {
180
229
  */
181
230
  export function trustedHeaderBlock(fields: HeaderField[]) {
182
231
  const first = fields[0];
183
- if (first?.name !== "received" || !isCloudflareHop(parseReceived(first.value))) return null;
232
+
233
+ if (first?.name !== "received") return null;
234
+ const hop = parseReceived(first.value);
235
+
236
+ if (!isCloudflareHop(hop)) return null;
237
+
184
238
  const score = fields.findIndex((field) => field.name === "x-cf-spamh-score");
185
- if (score >= 0) return { trusted: fields.slice(0, score + 1), below: fields.slice(score + 1) };
186
- const nextReceived = fields.findIndex((field, index) => index > 0 && field.name === "received");
239
+
240
+ if (score !== -1) {
241
+ return {
242
+ hop,
243
+ trusted: fields.slice(0, score + 1),
244
+ below: fields.slice(score + 1),
245
+ };
246
+ }
247
+
248
+ const nextReceived = fields.findIndex(
249
+ (field, index) => index > 0 && field.name === "received"
250
+ );
251
+
187
252
  const end = Math.min(
188
- nextReceived >= 0 ? nextReceived : fields.length,
189
- MAX_TRUSTED_BLOCK_WITHOUT_SCORE,
253
+ nextReceived === -1 ? fields.length : nextReceived,
254
+ MAX_TRUSTED_BLOCK_WITHOUT_SCORE
190
255
  );
191
- return { trusted: fields.slice(0, end), below: fields.slice(end) };
256
+
257
+ return { hop, trusted: fields.slice(0, end), below: fields.slice(end) };
192
258
  }
193
259
 
194
260
  function authResult(value: string | null | undefined): AuthResult | null {
195
261
  return authResults.find((result) => result === value) ?? null;
196
262
  }
197
263
 
198
- function claimFrom(parsed: ParsedAuthenticationResults): UpstreamAuthenticationClaim {
264
+ function claimFrom(
265
+ parsed: ParsedAuthenticationResults
266
+ ): UpstreamAuthenticationClaim {
199
267
  const first = (method: string) =>
200
- authResult(parsed.results.find((result) =>
201
- result.method === method && (method !== "spf" || !result.props["smtp.helo"])
202
- )?.result);
268
+ authResult(
269
+ parsed.results.find(
270
+ (result) =>
271
+ result.method === method &&
272
+ (method !== "spf" || !result.props["smtp.helo"])
273
+ )?.result
274
+ );
275
+
203
276
  return {
204
277
  authservId: parsed.authservId,
205
278
  spf: first("spf"),
@@ -210,53 +283,83 @@ function claimFrom(parsed: ParsedAuthenticationResults): UpstreamAuthenticationC
210
283
 
211
284
  function dmarcPolicy(value: string | undefined): DmarcPolicy | null {
212
285
  const normalized = value?.toLocaleLowerCase();
213
- return normalized === "none" || normalized === "quarantine" || normalized === "reject"
286
+
287
+ return normalized === "none" ||
288
+ normalized === "quarantine" ||
289
+ normalized === "reject"
214
290
  ? normalized
215
291
  : null;
216
292
  }
217
293
 
218
- function matchSignature(result: AuthResInfo, domain: string, signatures: DkimSignatureTags[]) {
219
- const bPrefix = result.props["header.b"]?.replace(/\s+/gu, "");
294
+ function matchSignature(
295
+ result: AuthResInfo,
296
+ domain: string,
297
+ signatures: DkimSignatureTags[]
298
+ ) {
299
+ const bPrefix = result.props["header.b"]?.replaceAll(/\s+/gu, "");
220
300
  const selector = result.props["header.s"];
301
+
221
302
  const sameDomain = (signature: DkimSignatureTags) =>
222
303
  signature.domain === domain || domain.endsWith(`.${signature.domain}`);
304
+
223
305
  if (bPrefix) {
224
- const match = signatures.find((signature) => sameDomain(signature) && signature.b.startsWith(bPrefix));
306
+ const match = signatures.find(
307
+ (signature) => sameDomain(signature) && signature.b.startsWith(bPrefix)
308
+ );
309
+
225
310
  if (match) return match;
226
311
  }
227
- return signatures.find((signature) =>
228
- sameDomain(signature) && (!selector || signature.selector === selector)
229
- ) ?? null;
312
+
313
+ return (
314
+ signatures.find(
315
+ (signature) =>
316
+ sameDomain(signature) && (!selector || signature.selector === selector)
317
+ ) ?? null
318
+ );
230
319
  }
231
320
 
232
- function verdictFor(input: Pick<InboundAuthentication, "spf" | "dkim" | "dmarc" | "arc">): {
233
- verdict: SenderVerdict;
234
- verdictReason: SenderVerdictReason;
235
- } {
236
- const alignedDkimPass = input.dkim.some((dkim) => dkim.result === "pass" && dkim.aligned);
321
+ type Verdict = Pick<InboundAuthentication, "verdict" | "verdictReason">;
322
+
323
+ function verdictFor(
324
+ input: Pick<InboundAuthentication, "spf" | "dkim" | "dmarc" | "arc">
325
+ ): Verdict {
326
+ const alignedDkimPass = input.dkim.some(
327
+ (dkim) => dkim.result === "pass" && dkim.aligned
328
+ );
329
+
237
330
  const alignedSpfPass = input.spf?.result === "pass" && input.spf.aligned;
238
- if (input.dmarc?.result === "pass") return { verdict: "verified", verdictReason: "dmarc_pass" };
239
- const failing = input.dmarc?.result === "fail"
240
- ? "dmarc_fail" as const
241
- : !alignedDkimPass && !alignedSpfPass
242
- ? "no_aligned_pass" as const
243
- : null;
331
+
332
+ if (input.dmarc?.result === "pass") {
333
+ return { verdict: "verified", verdictReason: "dmarc_pass" };
334
+ }
335
+
336
+ const failing =
337
+ input.dmarc?.result === "fail"
338
+ ? ("dmarc_fail" as const)
339
+ : !alignedDkimPass && !alignedSpfPass
340
+ ? ("no_aligned_pass" as const)
341
+ : null;
342
+
244
343
  if (failing) {
245
- const arc = input.arc;
344
+ const { arc } = input;
246
345
  const oldestSealer = arc?.sealers[0]?.domain;
346
+
247
347
  if (
248
- arc?.result === "pass"
249
- && arc.oldest?.dmarc === "pass"
250
- && oldestSealer
251
- && TRUSTED_ARC_SEALERS.has(oldestSealer)
348
+ arc?.result === "pass" &&
349
+ arc.oldest?.dmarc === "pass" &&
350
+ oldestSealer &&
351
+ TRUSTED_ARC_SEALERS.has(oldestSealer)
252
352
  ) {
253
353
  return { verdict: "unverified", verdictReason: "forwarded_arc" };
254
354
  }
355
+
255
356
  return { verdict: "suspicious", verdictReason: failing };
256
357
  }
358
+
257
359
  if (alignedDkimPass && (!input.dmarc || input.dmarc.result === "none")) {
258
360
  return { verdict: "verified", verdictReason: "aligned_dkim" };
259
361
  }
362
+
260
363
  return { verdict: "unverified", verdictReason: "partial" };
261
364
  }
262
365
 
@@ -264,7 +367,7 @@ function emptyAuthentication(
264
367
  now: number,
265
368
  fromDomain: string | null,
266
369
  reason: "not_cloudflare" | "missing_results",
267
- envelopeFrom: string | null,
370
+ envelopeFrom: string | null
268
371
  ): InboundAuthentication {
269
372
  return {
270
373
  source: "headers",
@@ -291,57 +394,98 @@ function emptyAuthentication(
291
394
 
292
395
  function claimsCloudflare(field: HeaderField) {
293
396
  if (field.name === "authentication-results") {
294
- return parseAuthenticationResults(field.value)?.authservId === CLOUDFLARE_AUTHSERV_ID;
397
+ return (
398
+ parseAuthenticationResults(field.value)?.authservId ===
399
+ CLOUDFLARE_AUTHSERV_ID
400
+ );
295
401
  }
402
+
296
403
  if (field.name === "arc-authentication-results") {
297
- return parseArcAuthenticationResults(field.value)?.authservId === CLOUDFLARE_AUTHSERV_ID;
404
+ return (
405
+ parseArcAuthenticationResults(field.value)?.authservId ===
406
+ CLOUDFLARE_AUTHSERV_ID
407
+ );
298
408
  }
409
+
299
410
  if (field.name === "received-spf") {
300
- return parseReceivedSpf(field.value)?.pairs.receiver?.toLocaleLowerCase() === CLOUDFLARE_AUTHSERV_ID;
411
+ return (
412
+ parseReceivedSpf(field.value)?.pairs.receiver?.toLocaleLowerCase() ===
413
+ CLOUDFLARE_AUTHSERV_ID
414
+ );
301
415
  }
416
+
302
417
  if (field.name === "x-cf-spamh-score") return true;
418
+
303
419
  return false;
304
420
  }
305
421
 
306
422
  function arcSummary(
307
423
  trusted: HeaderField[],
308
424
  all: HeaderField[],
309
- arcResult: AuthResInfo | undefined,
425
+ arcResult: AuthResInfo | undefined
310
426
  ): InboundAuthentication["arc"] {
311
- const ownSeal = trusted.find((field) =>
312
- field.name === "arc-seal" && addressDomain(parseTagList(field.value).d) === CLOUDFLARE_ARC_DOMAIN
427
+ const ownSeal = trusted.find(
428
+ (field) =>
429
+ field.name === "arc-seal" &&
430
+ addressDomain(parseTagList(field.value).d) === CLOUDFLARE_ARC_DOMAIN
313
431
  );
314
- const ownInstance = Number(ownSeal ? parseTagList(ownSeal.value).i : Number.NaN);
315
- const result = arcResult?.result === "pass" || arcResult?.result === "fail"
316
- ? arcResult.result
317
- : "none";
432
+
433
+ const ownInstance = Number(
434
+ ownSeal ? parseTagList(ownSeal.value).i : Number.NaN
435
+ );
436
+
437
+ const result =
438
+ arcResult?.result === "pass" || arcResult?.result === "fail"
439
+ ? arcResult.result
440
+ : "none";
441
+
318
442
  if (!arcResult && !ownSeal) return null;
319
- const chainLength = Number.isInteger(ownInstance) && ownInstance > 0 ? ownInstance : 1;
443
+
444
+ const chainLength =
445
+ Number.isInteger(ownInstance) && ownInstance > 0 ? ownInstance : 1;
446
+
320
447
  const sealers = new Map<number, ArcSealer>();
448
+
321
449
  for (const field of all) {
322
450
  if (field.name !== "arc-seal") continue;
323
451
  const tags = parseTagList(field.value);
324
452
  const instance = Number(tags.i);
325
- if (!Number.isInteger(instance) || instance < 1 || instance >= chainLength || sealers.has(instance)) continue;
453
+
454
+ if (
455
+ !Number.isInteger(instance) ||
456
+ instance < 1 ||
457
+ instance >= chainLength ||
458
+ sealers.has(instance)
459
+ ) {
460
+ continue;
461
+ }
462
+
326
463
  sealers.set(instance, {
327
464
  instance,
328
465
  domain: addressDomain(tags.d),
329
466
  cv: tags.cv?.toLocaleLowerCase() ?? null,
330
467
  });
331
468
  }
469
+
332
470
  let oldest: UpstreamAuthenticationClaim | null = null;
471
+
333
472
  if (result === "pass" && chainLength > 1) {
334
473
  const first = all.flatMap((field) => {
335
474
  if (field.name !== "arc-authentication-results") return [];
336
475
  const parsed = parseArcAuthenticationResults(field.value);
476
+
337
477
  return parsed?.instance === 1 ? [parsed] : [];
338
478
  })[0];
479
+
339
480
  oldest = first ? claimFrom(first) : null;
340
481
  }
482
+
341
483
  return {
342
484
  result,
343
485
  chainLength,
344
- sealers: [...sealers.values()].sort((left, right) => left.instance - right.instance),
486
+ sealers: [...sealers.values()].sort(
487
+ (left, right) => left.instance - right.instance
488
+ ),
345
489
  oldest,
346
490
  };
347
491
  }
@@ -361,37 +505,69 @@ export function parseInboundAuthentication(input: {
361
505
  const fields = headerFields(input.raw);
362
506
  const block = trustedHeaderBlock(fields);
363
507
  const fromDomainHint = addressDomain(input.fromAddress);
508
+
364
509
  if (!block) {
365
- return emptyAuthentication(now, fromDomainHint, "not_cloudflare", input.envelopeFrom ?? null);
510
+ return emptyAuthentication(
511
+ now,
512
+ fromDomainHint,
513
+ "not_cloudflare",
514
+ input.envelopeFrom ?? null
515
+ );
366
516
  }
517
+
367
518
  const authenticationResults = block.trusted.flatMap((field) => {
368
519
  if (field.name !== "authentication-results") return [];
369
520
  const parsed = parseAuthenticationResults(field.value);
370
- return parsed?.authservId === CLOUDFLARE_AUTHSERV_ID ? [{ field, parsed }] : [];
521
+
522
+ return parsed?.authservId === CLOUDFLARE_AUTHSERV_ID
523
+ ? [{ field, parsed }]
524
+ : [];
371
525
  })[0];
526
+
372
527
  const receivedSpf = block.trusted.flatMap((field) => {
373
528
  if (field.name !== "received-spf") return [];
374
529
  const parsed = parseReceivedSpf(field.value);
375
- return parsed?.pairs.receiver?.toLocaleLowerCase() === CLOUDFLARE_AUTHSERV_ID ? [parsed] : [];
530
+
531
+ return parsed?.pairs.receiver?.toLocaleLowerCase() ===
532
+ CLOUDFLARE_AUTHSERV_ID
533
+ ? [parsed]
534
+ : [];
376
535
  })[0];
377
- const scoreField = block.trusted.find((field) => field.name === "x-cf-spamh-score");
378
- const score = scoreField && /^\s*\d+(?:\.\d+)?\s*$/u.test(scoreField.value)
379
- ? Number(scoreField.value)
380
- : null;
381
- const upstream = block.below.flatMap((field) => {
382
- if (field.name !== "authentication-results") return [];
383
- const parsed = parseAuthenticationResults(field.value);
384
- return parsed ? [claimFrom(parsed)] : [];
385
- }).slice(0, MAX_UPSTREAM_CLAIMS);
536
+
537
+ const scoreField = block.trusted.find(
538
+ (field) => field.name === "x-cf-spamh-score"
539
+ );
540
+
541
+ const score =
542
+ scoreField && /^\s*\d+(?:\.\d+)?\s*$/u.test(scoreField.value)
543
+ ? Number(scoreField.value)
544
+ : null;
545
+
546
+ const upstream = block.below
547
+ .flatMap((field) => {
548
+ if (field.name !== "authentication-results") return [];
549
+ const parsed = parseAuthenticationResults(field.value);
550
+
551
+ return parsed ? [claimFrom(parsed)] : [];
552
+ })
553
+ .slice(0, MAX_UPSTREAM_CLAIMS);
554
+
386
555
  const ignoredCloudflareClaims = block.below.filter(claimsCloudflare).length;
387
- const cloudflareHop = parseReceived(fields[0]!.value);
556
+ const cloudflareHop = block.hop;
388
557
 
389
558
  if (!authenticationResults) {
390
559
  return {
391
- ...emptyAuthentication(now, fromDomainHint, "missing_results", input.envelopeFrom ?? null),
392
- remoteIp: normalizeIp(receivedSpf?.pairs["client-ip"]) ?? cloudflareHop.ip,
560
+ ...emptyAuthentication(
561
+ now,
562
+ fromDomainHint,
563
+ "missing_results",
564
+ input.envelopeFrom ?? null
565
+ ),
566
+ remoteIp:
567
+ normalizeIp(receivedSpf?.pairs["client-ip"]) ?? cloudflareHop.ip,
393
568
  helo: receivedSpf?.pairs.helo ?? cloudflareHop.from,
394
- envelopeFrom: receivedSpf?.pairs["envelope-from"] || input.envelopeFrom || null,
569
+ envelopeFrom:
570
+ receivedSpf?.pairs["envelope-from"] || input.envelopeFrom || null,
395
571
  spamScore: score,
396
572
  upstream,
397
573
  ignoredCloudflareClaims,
@@ -400,88 +576,138 @@ export function parseInboundAuthentication(input: {
400
576
 
401
577
  const { results } = authenticationResults.parsed;
402
578
  const dmarcResult = results.find((result) => result.method === "dmarc");
403
- const fromDomain = fromDomainHint ?? addressDomain(dmarcResult?.props["header.from"]);
579
+
580
+ const fromDomain =
581
+ fromDomainHint ?? addressDomain(dmarcResult?.props["header.from"]);
582
+
404
583
  const spfResults = results.filter((result) => result.method === "spf");
405
- const spfMailFrom = spfResults.find((result) => result.props["smtp.mailfrom"])
406
- ?? spfResults.find((result) => !result.props["smtp.helo"]);
584
+
585
+ const spfMailFrom =
586
+ spfResults.find((result) => result.props["smtp.mailfrom"]) ??
587
+ spfResults.find((result) => !result.props["smtp.helo"]);
588
+
407
589
  const spfHelo = spfResults.find((result) => result.props["smtp.helo"]);
408
- const envelopeFrom = spfMailFrom?.props["smtp.mailfrom"]
409
- || receivedSpf?.pairs["envelope-from"]
410
- || input.envelopeFrom
411
- || null;
412
- const remoteIp = normalizeIp(
413
- results.find((result) => result.props["smtp.remote-ip"])?.props["smtp.remote-ip"],
414
- ) ?? normalizeIp(receivedSpf?.pairs["client-ip"]) ?? cloudflareHop.ip;
590
+
591
+ const envelopeFrom =
592
+ spfMailFrom?.props["smtp.mailfrom"] ||
593
+ receivedSpf?.pairs["envelope-from"] ||
594
+ input.envelopeFrom ||
595
+ null;
596
+
597
+ const remoteIp =
598
+ normalizeIp(
599
+ results.find((result) => result.props["smtp.remote-ip"])?.props[
600
+ "smtp.remote-ip"
601
+ ]
602
+ ) ??
603
+ normalizeIp(receivedSpf?.pairs["client-ip"]) ??
604
+ cloudflareHop.ip;
415
605
 
416
606
  const signatures = dkimSignatureTags(fields);
607
+
417
608
  const dkim: DkimResult[] = results.flatMap((result) => {
418
609
  if (result.method !== "dkim") return [];
419
610
  const verdict = authResult(result.result);
420
611
  const identity = result.props["header.i"] ?? null;
421
- const domain = addressDomain(result.props["header.d"]) ?? addressDomain(identity);
612
+
613
+ const domain =
614
+ addressDomain(result.props["header.d"]) ?? addressDomain(identity);
615
+
422
616
  if (!verdict || !domain) return [];
423
617
  const signature = matchSignature(result, domain, signatures);
424
- return [{
425
- result: verdict,
426
- domain,
427
- identity,
428
- selector: result.props["header.s"] ?? null,
429
- bPrefix: result.props["header.b"] ?? null,
430
- aligned: relaxedAligned(domain, fromDomain),
431
- signedHeaders: signature?.signedHeaders ?? null,
432
- }];
618
+
619
+ return [
620
+ {
621
+ result: verdict,
622
+ domain,
623
+ identity,
624
+ selector: result.props["header.s"] ?? null,
625
+ bPrefix: result.props["header.b"] ?? null,
626
+ aligned: relaxedAligned(domain, fromDomain),
627
+ signedHeaders: signature?.signedHeaders ?? null,
628
+ },
629
+ ];
433
630
  });
434
631
 
435
632
  const spfVerdict = authResult(spfMailFrom?.result);
436
633
  const spfDomain = addressDomain(envelopeFrom);
634
+
437
635
  const spf = spfVerdict
438
- ? { result: spfVerdict, domain: spfDomain, aligned: relaxedAligned(spfDomain, fromDomain) }
636
+ ? {
637
+ result: spfVerdict,
638
+ domain: spfDomain,
639
+ aligned: relaxedAligned(spfDomain, fromDomain),
640
+ }
439
641
  : null;
642
+
440
643
  const spfHeloVerdict = authResult(spfHelo?.result);
441
644
  const dmarcVerdict = authResult(dmarcResult?.result);
645
+
442
646
  const dmarc = dmarcVerdict
443
647
  ? {
444
648
  result: dmarcVerdict,
445
649
  headerFrom: addressDomain(dmarcResult?.props["header.from"]),
446
650
  policy: dmarcPolicy(dmarcResult?.props["policy.dmarc"]),
447
651
  alignedVia: [
448
- ...(dkim.some((item) => item.result === "pass" && item.aligned) ? ["dkim" as const] : []),
652
+ ...(dkim.some((item) => item.result === "pass" && item.aligned)
653
+ ? ["dkim" as const]
654
+ : []),
449
655
  ...(spf?.result === "pass" && spf.aligned ? ["spf" as const] : []),
450
656
  ],
451
657
  }
452
658
  : null;
453
- const arc = arcSummary(block.trusted, fields, results.find((result) => result.method === "arc"));
659
+
660
+ const arc = arcSummary(
661
+ block.trusted,
662
+ fields,
663
+ results.find((result) => result.method === "arc")
664
+ );
665
+
454
666
  const parts = { spf, dkim, dmarc, arc };
667
+
455
668
  return {
456
669
  source: "headers",
457
670
  version: 1,
458
671
  authservId: CLOUDFLARE_AUTHSERV_ID,
459
672
  parsedAt: now,
460
673
  remoteIp,
461
- helo: spfHelo?.props["smtp.helo"] ?? receivedSpf?.pairs.helo ?? cloudflareHop.from,
674
+ helo:
675
+ spfHelo?.props["smtp.helo"] ??
676
+ receivedSpf?.pairs.helo ??
677
+ cloudflareHop.from,
462
678
  envelopeFrom,
463
679
  fromDomain,
464
680
  ...parts,
465
681
  spfHelo: spfHeloVerdict
466
- ? { result: spfHeloVerdict, domain: addressDomain(spfHelo?.props["smtp.helo"]) }
682
+ ? {
683
+ result: spfHeloVerdict,
684
+ domain: addressDomain(spfHelo?.props["smtp.helo"]),
685
+ }
467
686
  : null,
468
687
  spamScore: score,
469
688
  ...verdictFor(parts),
470
689
  upstream,
471
690
  ignoredCloudflareClaims,
472
- trustedHeader: authenticationResults.field.value.slice(0, MAX_TRUSTED_HEADER_LENGTH),
691
+ trustedHeader: authenticationResults.field.value.slice(
692
+ 0,
693
+ MAX_TRUSTED_HEADER_LENGTH
694
+ ),
473
695
  };
474
696
  }
475
697
 
476
698
  // --- List-Unsubscribe (RFC 2369 / RFC 8058) --------------------------------
477
699
 
478
700
  function httpsUnsubscribeUrl(value: string) {
479
- if (value.length > 2_048) return null;
701
+ if (value.length > 2048) return null;
702
+
480
703
  try {
481
704
  const url = new URL(value);
705
+
482
706
  if (url.protocol !== "https:" || url.username || url.password) return null;
483
- const host = url.hostname.replace(/^\[|\]$/gu, "");
707
+ const host = url.hostname.replaceAll(/^\[|\]$/gu, "");
708
+
484
709
  if (normalizeIp(host) || !host.includes(".")) return null;
710
+
485
711
  return url.toString();
486
712
  } catch {
487
713
  return null;
@@ -489,11 +715,15 @@ function httpsUnsubscribeUrl(value: string) {
489
715
  }
490
716
 
491
717
  function mailtoUnsubscribeUrl(value: string) {
492
- if (value.length > 2_048 || !/^mailto:/iu.test(value)) return null;
718
+ if (value.length > 2048 || !/^mailto:/iu.test(value)) return null;
719
+
493
720
  try {
494
721
  const url = new URL(value);
495
722
  const recipient = decodeURIComponent(url.pathname);
496
- return /^[^\s@,]+@[^\s@,]+\.[^\s@,]+$/u.test(recipient) ? url.toString() : null;
723
+
724
+ return /^[^\s@,]+@[^\s@,]+\.[^\s@,]+$/u.test(recipient)
725
+ ? url.toString()
726
+ : null;
497
727
  } catch {
498
728
  return null;
499
729
  }
@@ -506,35 +736,62 @@ function mailtoUnsubscribeUrl(value: string) {
506
736
  */
507
737
  export function parseListUnsubscribe(
508
738
  raw: string,
509
- authentication: Pick<InboundAuthentication, "dkim">,
739
+ authentication: Pick<InboundAuthentication, "dkim">
510
740
  ): ListUnsubscribe | null {
511
741
  const fields = headerFields(raw);
512
- const header = fields.find((field) => field.name === "list-unsubscribe")?.value;
742
+
743
+ const header = fields.find(
744
+ (field) => field.name === "list-unsubscribe"
745
+ )?.value;
746
+
513
747
  if (!header) return null;
514
- const uris = [...header.matchAll(/<([^>]*)>/gu)].map((match) => match[1]!.replace(/\s+/gu, ""));
748
+
749
+ const uris = [...header.matchAll(/<([^>]*)>/gu)].map((match) =>
750
+ match[1].replaceAll(/\s+/gu, "")
751
+ );
752
+
515
753
  const httpsUrl = uris.map(httpsUnsubscribeUrl).find(Boolean) ?? null;
516
754
  const mailto = uris.map(mailtoUnsubscribeUrl).find(Boolean) ?? null;
755
+
517
756
  const result = (reason: ListUnsubscribe["reason"]): ListUnsubscribe => ({
518
757
  httpsUrl,
519
758
  mailto,
520
759
  oneClick: reason === null,
521
760
  reason,
522
761
  });
762
+
523
763
  if (!httpsUrl && !mailto) return result("invalid-uri");
764
+
524
765
  if (!httpsUrl) return result("no-https");
525
- const post = fields.find((field) => field.name === "list-unsubscribe-post")?.value;
526
- if (post?.replace(/\s+/gu, "").toLocaleLowerCase() !== "list-unsubscribe=one-click") {
766
+
767
+ const post = fields.find(
768
+ (field) => field.name === "list-unsubscribe-post"
769
+ )?.value;
770
+
771
+ if (
772
+ post?.replaceAll(/\s+/gu, "").toLocaleLowerCase() !==
773
+ "list-unsubscribe=one-click"
774
+ ) {
527
775
  return result("no-post");
528
776
  }
529
- const covering = authentication.dkim.filter((signature) =>
530
- signature.result === "pass" && signature.signedHeaders?.includes("list-unsubscribe")
777
+
778
+ const covering = authentication.dkim.filter(
779
+ (signature) =>
780
+ signature.result === "pass" &&
781
+ signature.signedHeaders?.includes("list-unsubscribe")
531
782
  );
783
+
532
784
  if (!covering.length) return result("unsigned");
785
+
533
786
  const coveringBoth = covering.filter((signature) =>
534
787
  signature.signedHeaders?.includes("list-unsubscribe-post")
535
788
  );
789
+
536
790
  if (!coveringBoth.length) return result("post-not-signed");
537
- return result(coveringBoth.some((signature) => signature.aligned) ? null : "unaligned");
791
+
792
+ return result(
793
+ coveringBoth.some((signature) => signature.aligned) ? null : "unaligned"
794
+ );
538
795
  }
539
796
 
540
797
  /** Header-derived authentication and unsubscribe data stored on the email row. */
@@ -550,6 +807,7 @@ export function inboundHeaderMetadata(input: {
550
807
  envelopeFrom: input.envelopeFrom,
551
808
  now: input.now,
552
809
  });
810
+
553
811
  return {
554
812
  authenticationResultsJson: authentication,
555
813
  listUnsubscribeJson: parseListUnsubscribe(input.rawHeaders, authentication),