Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.Mail.SpamChecks

Feature notes: Mail subsystem notes (SMTP / POP3 / IMAP)

Classes, interfaces and records

classeSpamCheckError

inherits from Exception

(no public members)

classtSpamPeerTable

inherits from TObject

THE SHARED STATE BEHIND THE RATE AND GREYLIST CHECKS. One instance, handed to both, so a deployment has one object to size, prune and (if it ever matters) replace. Safe from several connection threads at once.

constructor Create; destructor Destroy; override; function NoteConnection(const aIP: string): Integer;
Records one event and answers how many fall inside the current window.
function NoteMessage(const aIP: string): Integer; function NoteFailure(const aIP: string): Integer;
CALLED BY THE HOST when a recipient is refused - an unknown mailbox, a relay attempt. It is the cheapest dictionary-attack signal there is: a peer working through a name list produces almost nothing but these, and it does so before any message body exists to examine. The table only counts; tSpamRateCheck.MaxFailures decides what the count is worth.
function FailureCount(const aIP: string): Integer;
How many failures stand against this peer inside the window, without recording another.
function GreylistPasses(const aIP, aSender, aRecipient: string; out aWaitMs: Cardinal): Boolean;
THE GREYLIST DECISION. False means "not yet" - the triplet has been seen but not for long enough. aWaitMs reports how much longer, so a check can tell the sender something true instead of a bare 451.

A triplet that has passed often enough stops being asked at all: that is what keeps greylisting from taxing the correspondents a host actually has.
procedure Clear;
Everything, discarded. For an operator command, and for the self-test.
function PeerCount: Integer;
How many peers and triplets are held right now.
function GreylistCount: Integer; property WindowMs: Cardinal read fWindowMs write fWindowMs;
HOW LONG THE RATE COUNTERS ACCUMULATE BEFORE STARTING AGAIN. Not a limit: the limits live on tSpamRateCheck. Full description »
property GreyMinWaitMs: Cardinal read fGreyMinWaitMs write fGreyMinWaitMs;
HOW LONG A NEWLY SEEN TRIPLET IS ASKED TO WAIT. NO DEFAULT: zero means greylisting is OFF, and tSpamGreylistCheck does nothing at all. Full description »
property GreyLifetimeMs: Cardinal read fGreyLifetimeMs write fGreyLifetimeMs;
How long an idle triplet is remembered. Defaulted, because it bounds the table rather than judging mail: too short and regular correspondents are greylisted again, too long and the table fills with strangers.
property GreyPassesToTrust: Integer read fGreyPassesToTrust write fGreyPassesToTrust;
HOW MANY SUCCESSFUL RETRIES BEFORE A TRIPLET IS TRUSTED AND NEVER ASKED AGAIN. NO DEFAULT: zero or less means never auto-trust, which is safe - every triplet is judged on its own age, as it was the first time. Full description »
property MaxPeers: Integer read fMaxPeers write fMaxPeers; property MaxGreylist: Integer read fMaxGrey write fMaxGrey;

classtSpamHeloCheck

inherits from TInterfacedObject

implements iSpamCheck

WHAT THE PEER CALLED ITSELF. Runs at sstHelo and costs nothing - no lookup, no state, just the string the peer supplied.

constructor Create(const aLocalName: string); destructor Destroy; override; function CheckName: string;
Always returns the string 'helo'.
function Stages: tSpamStages; function Evaluate(aContext: tSpamContext; aStage: tSpamStage; out aFinding: tSpamFinding): Boolean; property LocalName: string read fLocalName write fLocalName;
The name this host greets with. A peer claiming it is either us, or is lying.
property LocalAddresses: TStringList read fLocalAddresses;
Addresses this host answers on, so a peer claiming one is caught too.
property NotFqdnPoints: Integer read fNotFqdnPoints write fNotFqdnPoints;
A GREETING THAT IS NOT A DOMAIN NAME AT ALL. NO DEFAULT: zero ignores it. RFC 5321 sec.4.1.1.1 requires a fully-qualified name or an address literal, so anything else is a protocol violation - but a mild one, and badly configured appliances, print servers and small office boxes commit it constantly. Full description »
property IsUsPoints: Integer read fIsUsPoints write fIsUsPoints;
THE PEER GREETS WITH OUR OWN NAME OR ADDRESS. NO DEFAULT: zero ignores it. This is the strongest of the three and the safest to weight heavily. Full description »
property LiteralPoints: Integer read fLiteralPoints write fLiteralPoints;
THE GREETING IS A BARE ADDRESS LITERAL. NO DEFAULT: zero ignores it. Permitted by the RFC, and normal from hosts with no name of their own, so this is the WEAKEST of the three signals - a token weight or nothing at all. Full description »

classtSpamReverseDnsCheck

inherits from TInterfacedObject

implements iSpamCheck

FORWARD-CONFIRMED REVERSE DNS. PTR on the peer's address, then the address records of whatever came back, and the peer's own address must be among them. Both halves are needed: a PTR alone proves nothing, because whoever controls an address block can point it anywhere.

WITH ALL THREE WEIGHTS AT ZERO THIS CHECK ASKS DNS NOTHING - worth knowing, because on a resolver that opens a TCP connection per query the lookups are the expensive part, not the arithmetic.

constructor Create(const aResolver: iDnsResolver); function CheckName: string;
Always returns the string 'fcrdns'.
function Stages: tSpamStages; function Evaluate(aContext: tSpamContext; aStage: tSpamStage; out aFinding: tSpamFinding): Boolean; property NoReversePoints: Integer read fNoReversePoints write fNoReversePoints;
NO PTR RECORD AT ALL. NO DEFAULT: zero ignores it. The strongest of this check's three signals. A machine sending mail from an address with no reverse record is either a consumer connection or a host whose operator never configured one, and large receivers have refused such mail for years - which... Full description »
property NoForwardPoints: Integer read fNoForwardPoints write fNoForwardPoints;
A PTR EXISTS BUT DOES NOT RESOLVE BACK. NO DEFAULT: zero ignores it. Weaker than a missing record, and it should be weighted lower. Full description »
property ConfirmedCredit: Integer read fConfirmedCredit write fConfirmedCredit;
THE PEER CONFIRMS BOTH WAYS. NO DEFAULT: zero gives no credit. Set it NEGATIVE or leave it alone; a positive value here would punish the peers that did everything right. Full description »

classtSpamDnsblCheck

inherits from TInterfacedObject

implements iSpamCheck

A DNS BLOCKLIST OR ALLOWLIST. The peer's address is reversed under the zone and looked up as an address record; anything in 127.0.0.0/8 is an answer, and the code in the last octet is the zone's own vocabulary.

ONE ANSWER IS NOT A LISTING, and getting this wrong blocks the world: by long convention a zone returns 127.255.255.x - and Spamhaus in particular 127.255.255.252 upward - to say "your query was refused", because the querier is unregistered, over quota, or using a public resolver the zone declines to serve. Read as a listing it condemns every sender at once. Those codes are reported through OnProblem and score nothing.

BEFORE USING A PUBLIC ZONE, READ ITS TERMS. Most forbid commercial or high-volume use without a subscription, and several refuse queries that arrive via a large public resolver - which is what the refusal codes above are telling you.

constructor Create(const aResolver: iDnsResolver; const aZone: string; aAllowList: Boolean = False); destructor Destroy; override; function CheckName: string; function Stages: tSpamStages; function Evaluate(aContext: tSpamContext; aStage: tSpamStage; out aFinding: tSpamFinding): Boolean; property Zone: string read fZone;
The zone, e.g. 'zen.example.org'.
property Points: Integer read fPoints write fPoints;
WHAT A LISTING IS WORTH. NO DEFAULT: zero means this zone is consulted not at all - no query is sent. Full description »
property AllowList: Boolean read fAllowList; property CacheMs: Cardinal read fCacheMs write fCacheMs;
How long an answer is believed. Defaulted - a traffic bound, not a policy.
property OnProblem: TGetStrProc read fOnProblem write fOnProblem;
Told when a zone answers "I will not serve you". Not a listing, and worth an operator's attention: it means the queries are being wasted.

classtSpamRateCheck

inherits from TInterfacedObject

implements iSpamCheck

HOW MUCH, HOW FAST, FROM ONE ADDRESS. Defers; never refuses.

constructor Create(aTable: tSpamPeerTable); function CheckName: string;
Always returns the string 'rate'.
function Stages: tSpamStages; function Evaluate(aContext: tSpamContext; aStage: tSpamStage; out aFinding: tSpamFinding): Boolean; property MaxConnections: Integer read fMaxConnections write fMaxConnections;
CONNECTIONS FROM ONE ADDRESS PER WINDOW. NO DEFAULT: zero or less means unlimited, which is the only safe reading of "nobody has decided yet" - a limit of zero would defer every connection ever made. Full description »
property MaxMessages: Integer read fMaxMessages write fMaxMessages;
MESSAGES FROM ONE ADDRESS PER WINDOW. NO DEFAULT: zero or less means unlimited.

The same reasoning as MaxConnections, with one difference: a message is a more meaningful unit than a connection, because a well-behaved sender pipelines many messages down one connection and a crude one opens a connection each time. If only one of the two is set, this is the better one.
property MaxFailures: Integer read fMaxFailures write fMaxFailures;
REFUSED RECIPIENTS FROM ONE ADDRESS PER WINDOW. NO DEFAULT: zero or less means unlimited. The host reports each refusal through tSpamPeerTable.NoteFailure; this decides when the count is too high. Full description »

classtSpamGreylistCheck

inherits from TInterfacedObject

implements iSpamCheck

GREYLISTING. The first time a triplet of (address, sender, recipient) is seen it is asked to come back; a sender that does is remembered.

IT DEFERS, IT NEVER REFUSES - that is what makes it safe. Every RFC 5321 sender must retry a 4xx, so the only mail it can lose is mail from something that does not implement a queue, which is most of what a filter is for.

Off until tSpamPeerTable.GreyMinWaitMs is set.

constructor Create(aTable: tSpamPeerTable); function CheckName: string;
Always returns the string 'greylist'.
function Stages: tSpamStages; function Evaluate(aContext: tSpamContext; aStage: tSpamStage; out aFinding: tSpamFinding): Boolean; property SkipAuthenticated: Boolean read fSkipAuthenticated write fSkipAuthenticated;
A session that authenticated is the host's own user and is never greylisted. True by default: this one is not a guess, it is the same rule the pipeline applies to submission as a whole.

Routines