refactor(transport): Explicitly handle RFC7505 null MX

Signed-off-by: Jagoda Ślązak <jslazak@jslazak.com>
This commit is contained in:
Jagoda Ślązak
2026-04-28 08:24:27 +02:00
parent 21aaea0d92
commit 1b1585eb7d
+17 -8
View File
@@ -62,14 +62,23 @@ impl TransportHandler {
match dns_resolver.mx_lookup(query).await { match dns_resolver.mx_lookup(query).await {
Ok(mx_records) => { Ok(mx_records) => {
let mut hosts: Vec<(u16, String)> = mx_records let mut hosts: Vec<(u16, String)> = Vec::new();
.iter() for mx in mx_records {
.map(|mx| { // Null MX / RFC7505
let host = if mx.exchange().is_root() {
mx.exchange().to_string().trim_end_matches('.').to_string(); // From RFC7505 section 3:
(mx.preference(), host) // > A domain that advertises a null MX MUST NOT
}) // > advertise any other MX RR.
.collect(); // We assume this is the only record and exit early.
return Err(
"556 5.1.10 Permanent failure: Recipient address has null MX"
.to_string(),
);
}
let host = mx.exchange().to_string().trim_end_matches('.').to_string();
hosts.push((mx.preference(), host))
}
hosts.sort(); hosts.sort();
hosts hosts
} }