@bobfrankston/mailx-types 0.1.69 → 0.1.73

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 (3) hide show
  1. package/package.json +1 -1
  2. package/trust.d.ts +11 -0
  3. package/trust.js +50 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/mailx-types",
3
- "version": "0.1.69",
3
+ "version": "0.1.73",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/trust.d.ts CHANGED
@@ -56,6 +56,14 @@ export interface TrustInput {
56
56
  ownAddresses: string[];
57
57
  /** Sanitized HTML body, for the link-construct checks. */
58
58
  bodyHtml: string;
59
+ /** The reader has approved this sender or its domain in allowlist.jsonc —
60
+ * "Always: *@icecer.com" in the remote-content banner, or "Trust all
61
+ * senders at ‹domain›" in the address menu. It answers the only question
62
+ * a spam score cannot: is this mail WANTED. It never silences forgery
63
+ * evidence, and it counts only on a message whose sender was actually
64
+ * proved — otherwise the list would be a switch a forger could flip by
65
+ * typing a trusted address into From. */
66
+ senderTrusted?: boolean;
59
67
  /** Plain-text body, for the character-level checks. Separate from the HTML
60
68
  * because markup legitimately contains things prose does not, and the
61
69
  * zero-width test would trip over an entity or an attribute value. */
@@ -105,6 +113,9 @@ export interface SpamScore {
105
113
  * listed in the Spamhaus SBL blocklist)". A number alone is unactionable;
106
114
  * this can be judged in a second. */
107
115
  reasons: string[];
116
+ /** The reader approved this sender AND the sender is proved: the score is
117
+ * still true, and no longer worth showing. The viewer hides the chip. */
118
+ trusted: boolean;
108
119
  }
109
120
  export declare function spamScoreOf(input: TrustInput): SpamScore;
110
121
  //# sourceMappingURL=trust.d.ts.map
package/trust.js CHANGED
@@ -77,6 +77,15 @@ const ASSOCIATION_RULES = [
77
77
  /^SEM_URIBL/,
78
78
  /^SPAMHAUS_/,
79
79
  /^RCVD_IN_(SBL|XBL|PBL|BL_SPAMCOP|SORBS|BRBL|VALIDITY|MSPIKE_[LZ])/,
80
+ // Blocklist rules that happen to live under other prefixes. KAM_*URIBL_*
81
+ // ("Body contains URI listed in PCCC WILD RBL", 9.0) and SH_HBL_EMAILS
82
+ // ("Email address listed in email blocklist", 8.0) are the same kind of
83
+ // evidence as URIBL_SBL — somebody else's list, about a host or address
84
+ // the message mentions — and they were the bulk of what still cautioned a
85
+ // proved sender: a Business Insider newsletter, an MIT cancer-center
86
+ // invitation, a campaign mailing. KAM_INFOUSMEBIZ judges the TLD a domain
87
+ // lives in, which is guilt by neighbourhood.
88
+ /^KAM_(BODY_|FROM_)?URIBL/, /^SH_HBL/, /^KAM_INFOUSMEBIZ$/,
80
89
  ];
81
90
  /** The shape of mass mailing: bulk-detection networks, marketing markup, list
82
91
  * plumbing. A score built entirely from these is a bulk verdict however high
@@ -94,6 +103,10 @@ const BULK_RULES = [
94
103
  /^URIBL_(GREY|CSS|BLOCKED|CT_SURBL)/, /^SH_BODYURI/,
95
104
  /^HEADER_FROM_DIFFERENT_DOMAINS$/, // every ESP on earth trips this
96
105
  /^MPART_ALT_DIFF/, /^TVD_/, /^T_REMOTE_IMAGE$/, /^UNPARSEABLE_RELAY$/,
106
+ // Branded ESP click-trackers. Not open redirectors (URI_PHP_REDIR and
107
+ // friends stay unclassified): these are the sending platform's own
108
+ // tracking domain, which is mass-mail machinery by definition.
109
+ /^GB_AWSTRACK/, /AWSTRACK/, /^GB_SENDGRID/, /^GB_MAILCHIMP/,
97
110
  ];
98
111
  /** Passes, whitelistings, and Bayes' own opinion — informational, and in
99
112
  * BAYES_00's case exculpatory. `DKIM_INVALID` lives here rather than in the
@@ -237,9 +250,27 @@ function analyzeServerSpam(input) {
237
250
  // of a report is not evidence the rule was free.
238
251
  const scored = (r) => !(r.score <= 0);
239
252
  const present = (cls) => rules.some(r => r.cls === cls && scored(r));
253
+ // An unknown rule keeps a proved sender at caution only if it could have
254
+ // flagged the message BY ITSELF. Presence was too crude: an IEEE
255
+ // conference announcement (Bob 2026-08-28) scored 4.5 of 4.5 on DCC 3.0 +
256
+ // marketing 1.0 + 1.5 for GB_AWSTRACK_REDIR — Amazon SES's click-tracker,
257
+ // which every bulk mailer on earth routes through — and the 1.5 alone
258
+ // pushed a DMARC-proved announcement into "check this message before
259
+ // acting on it". Meanwhile KAM_BENEFICIARY, the case this rule exists for,
260
+ // is worth 10.0 on its own.
261
+ //
262
+ // The comparison is against the SERVER'S OWN threshold, so this adds no
263
+ // constant to tune: "enough to condemn" already has a number, and it is
264
+ // the one the server used. Unscored rules (no X-Spam-Report) make the sum
265
+ // unknown, and unknown stays cautious.
266
+ const unknown = rules.filter(r => r.cls === "other" && scored(r));
267
+ const unknownWeight = unknown.reduce((sum, r) => sum + r.score, 0);
268
+ const unknownCouldFlagAlone = !unknown.length ? false
269
+ : !Number.isFinite(unknownWeight) || !Number.isFinite(threshold) ? true
270
+ : unknownWeight >= threshold;
240
271
  const kind = (dmarc.authFailures.length || present("forgery")) ? "forgery"
241
272
  : present("association") ? "association"
242
- : present("other") ? "unclassified"
273
+ : unknownCouldFlagAlone ? "unclassified"
243
274
  : rules.length ? "bulk"
244
275
  : "unclassified";
245
276
  // Two proofs SpamAssassin states in its own rule list, which mail that
@@ -323,6 +354,16 @@ function serverSpamVerdict(input) {
323
354
  const a = analyzeServerSpam(input);
324
355
  if (!a || !a.flagged)
325
356
  return null;
357
+ // Mail from a sender the reader has approved, whose identity is proved,
358
+ // and which nothing accuses of forgery: say nothing at all. The server's
359
+ // score answers "is this bulk", the reader has already answered "is it
360
+ // wanted", and repeating the first after the second is how a banner turns
361
+ // into furniture. (Bob 2026-08-28, having just clicked "Always:
362
+ // *@icecer.com" on a conference announcement: "I accepted the server so
363
+ // shouldn't this be considered safe?")
364
+ const trustedAndProved = input.senderTrusted && a.proved;
365
+ if (trustedAndProved && a.kind !== "forgery" && !a.authFailures.length)
366
+ return null;
326
367
  const numbers = Number.isFinite(a.score) && Number.isFinite(a.threshold)
327
368
  ? `SpamAssassin score ${a.score} of ${a.threshold}`
328
369
  : "flagged by SpamAssassin";
@@ -354,6 +395,13 @@ function serverSpamVerdict(input) {
354
395
  detail: `${numbers}${why}${bayes}`,
355
396
  };
356
397
  const proof = a.proved ? `${provedNote(a)} ` : "";
398
+ if (input.senderTrusted && !a.proved)
399
+ return {
400
+ id: "server-spam-verdict",
401
+ severity: "caution",
402
+ text: "This claims to be a sender you trust, but nothing proves it is.",
403
+ detail: `No DMARC pass, no valid signature from the sending domain, and it passed through hosts your server does not trust. ${numbers}${why}`,
404
+ };
357
405
  return {
358
406
  id: "server-spam-verdict",
359
407
  severity: "caution",
@@ -627,6 +675,7 @@ export function spamScoreOf(input) {
627
675
  kind: a.kind,
628
676
  proved: a.proved,
629
677
  provedBy: a.provedBy,
678
+ trusted: !!input.senderTrusted && a.proved && a.kind !== "forgery" && !a.authFailures.length,
630
679
  reasons: a.reasons,
631
680
  };
632
681
  }