mailrs-shield
SMTP server anti-spam primitives in three modules: DNSBL lookups, greylisting policy, and FCrDNS (forward-confirmed reverse DNS) checks — async, transport-agnostic, mostly zero-I/O.
Extracted from mailrs so any Rust mail server can drop these in without re-implementing the same DNS-walking patterns. The Rust ecosystem currently has no dedicated crates for any of these three primitives.
What's inside
shield::dnsbl — DNS blocklist queries
Look up an inbound client IP against zones like Spamhaus ZEN, Barracuda, etc. Comes with an in-process TTL cache so repeat connections don't re-query.
use TokioResolver;
use check_dnsbl;
use IpAddr;
# async
shield::greylist — Greylisting policy
Pure policy (Harris 2003 / RFC 6647): defer the first time you see a (client_ip, sender, recipient) triplet, accept after the configured delay if the sender retries. Legitimate MTAs queue and retry; most spam bots don't.
use ;
let cfg = default; // 5-minute initial delay, 36-day pass window
assert_eq!;
assert_eq!;
assert_eq!;
The optional redis-store feature (on by default) ships a GreylistDb that combines Redis (hot cache) + Postgres (cold backup) behind a single check() call:
#
# async
Disable the feature to plug in your own store — the trait surface is just "given a key + clock, look up the first-seen timestamp."
shield::ptr — FCrDNS check
Score an inbound client by whether its IP's reverse DNS forward-resolves back to a name matching the EHLO domain. Returns 0.0 on full match, 1.0 on no match — easy to fold into a spam score.
use TokioResolver;
use check_client_ptr;
use IpAddr;
# async
Feature flags
| Flag | Default | What it enables |
|---|---|---|
redis-store |
yes | greylist::GreylistDb (Redis + optional PG cold backup) |
Disable both default features (default-features = false) if you're plugging in your own backends.
License
Licensed under either of Apache License 2.0 or MIT license at your option.