WHY THIS EXISTS AND WHY IT IS OVER TCP. Delivering mail without a smarthost needs the recipient domain's MX RRset, and nothing in this library could ask for a typed DNS record. There was also no way to build the usual answer: THE SOCKET ABSTRACTION HAS NO UDP AT ALL - tAbstractSocket is SOCK_STREAM in both backends - so a UDP resolver would have cost a new socket abstraction and two platform backends before a line of DNS. RFC 7766 makes DNS over TCP a first-class transport: the identical wire message behind a two-octet big-endian length prefix. That gives one code path, no dnsapi.dll, no libresolv (three different external targets, and absent from bionic), no 512-octet truncation dance, and a parser that can be driven from canned packets with no socket at all - which is how the vectors at the bottom test it. THE PARSER IS THE ATTACK SURFACE. Everything it reads came off the network from something that may not be a resolver at all, so every read is bounds-checked against the buffer, names are capped at 255 octets and labels at 63, and compression pointers are followed at most cDnsMaxPtrHops times - a pointer that points at itself is the classic way to hang a DNS parser for ever. A malformed message is rejected whole; nothing is returned "as far as it parsed". WHAT IT DOES NOT DO: no DNSSEC, so it reports no security status and cannot support DANE. A caller must treat every answer as UNAUTHENTICATED - which for MX delivery is exactly why the TLS policy there is unauthenticated too. SUBSTITUTABLE. Resolution goes through iDnsResolver, so DoH, DnsQuery_W or a validating stub can replace this without touching a caller, and a scripted resolver is what the delivery tests run against.
Feature notes: Mail subsystem notes (SMTP / POP3 / IMAP)
inherits from Exception
(no public members)
One MX RR. Exchange is absolute with the trailing dot stripped. AN EMPTY Exchange IS THE ROOT LABEL, i.e. a NULL MX (RFC 7505): the domain has published that it accepts no mail. Test it with DnsIsNullMx - an empty string here means something very specific and is not "missing".
Preference: Word;
Exchange: string;
THE RESOLUTION SEAM. Substitute DoH, DnsQuery_W or a DNSSEC-validating stub without touching a caller; a scripted implementation is what lets the mail delivery tests run with no network. Every out-parameter is cleared before use. aDest lists are APPENDED to, never cleared, so several lookups can accumulate.
function LookupMx(const aDomain: string; out aRecords: tDnsMxArray): tDnsStatus;
function LookupAddresses(const aHost: string; aWantIPv6: Boolean; aDest: TStrings): tDnsStatus;
function LookupText(const aName: string; aDest: TStrings): tDnsStatus;
function LookupNames(const aAddress: string; aDest: TStrings): tDnsStatus;
inherits from TInterfacedObject
implements iDnsResolver
A resolver whose answers come from a SCRIPT rather than the network, so a policy test can pin every lookup and run with no DNS at all. Entries are 'TYPE:name=value' lines: TXT:example.com=v=spf1 -all A:mail.example.com=192.0.2.1 AAAA:mail.example.com=2001:db8::1 MX:example.com=10 mail.example.com PTR:192.0.2.1=mail.example.com Repeat a key for several records of one name. Two reserved values stand for the outcomes that are not simply "no answer": __NXDOMAIN__ and __SERVFAIL__. A NAME WITH NO ENTRY ANSWERS NODATA, NOT NXDOMAIN - they are different outcomes, and a rig that cannot tell them apart cannot test the split that decides between requeueing mail and bouncing it.
constructor Create;
destructor Destroy; override;
function LookupMx(const aDomain: string; out aRecords: tDnsMxArray): tDnsStatus;
function LookupAddresses(const aHost: string; aWantIPv6: Boolean; aDest: TStrings): tDnsStatus;
function LookupText(const aName: string; aDest: TStrings): tDnsStatus;
function LookupNames(const aAddress: string; aDest: TStrings): tDnsStatus;
property Script: TStringList read fScript;
property Queries: Integer read fQueries;
inherits from TInterfacedObject
implements iDnsResolver
RFC 7766 DNS over TCP against the system - or configured - recursive resolvers, with a TTL-bounded cache. THREAD-SAFE: the spool calls it from several delivery workers at once.
constructor Create;
destructor Destroy; override;
function LookupMx(const aDomain: string; out aRecords: tDnsMxArray): tDnsStatus;
function LookupAddresses(const aHost: string; aWantIPv6: Boolean; aDest: TStrings): tDnsStatus;
function LookupText(const aName: string; aDest: TStrings): tDnsStatus;
function LookupNames(const aAddress: string; aDest: TStrings): tDnsStatus;
procedure FlushCache;
property Servers: TStrings read GetServers;
property Timeout: Cardinal read fTimeout write fTimeout;
property DeadlineTick: UInt64 read fDeadlineTick write fDeadlineTick;
property Port: Word read fPort write fPort;
property MaxCacheEntries: Integer read fMaxCacheEntries write fMaxCacheEntries;
property WantIPv6: Boolean read fWantIPv6 write fWantIPv6;
WHAT A LOOKUP CAME TO, and the 4xx/5xx split for mail lives in this enum. Conflating any two of the first three either strands mail during a resolver outage or bounces mail that would have been deliverable.