mirror of
https://github.com/chatmail/relay.git
synced 2026-09-13 10:53:15 +00:00
fix: Implement missing "implicit MX" rule
Implements "implicit MX" as described by https://datatracker.ietf.org/doc/html/rfc5321#section-5.1 Fixes: #126 Signed-off-by: Jagoda Ślązak <jslazak@jslazak.com>
This commit is contained in:
+26
-18
@@ -59,25 +59,33 @@ impl TransportHandler {
|
|||||||
allow_invalid_cert = true;
|
allow_invalid_cert = true;
|
||||||
}
|
}
|
||||||
let query = format!("{mx_domain}.");
|
let query = format!("{mx_domain}.");
|
||||||
let mx_records = dns_resolver.mx_lookup(query).await.map_err(|e| {
|
|
||||||
if e.is_no_records_found() {
|
|
||||||
format!("512 No MX records for {mx_domain}")
|
|
||||||
} else if e.is_nx_domain() {
|
|
||||||
format!("512 Domain {mx_domain} does not exist")
|
|
||||||
} else {
|
|
||||||
format!("421 DNS resolution failed for {mx_domain}")
|
|
||||||
}
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut hosts: Vec<(u16, String)> = mx_records
|
match dns_resolver.mx_lookup(query).await {
|
||||||
.iter()
|
Ok(mx_records) => {
|
||||||
.map(|mx| {
|
let mut hosts: Vec<(u16, String)> = mx_records
|
||||||
let host = mx.exchange().to_string().trim_end_matches('.').to_string();
|
.iter()
|
||||||
(mx.preference(), host)
|
.map(|mx| {
|
||||||
})
|
let host =
|
||||||
.collect();
|
mx.exchange().to_string().trim_end_matches('.').to_string();
|
||||||
hosts.sort();
|
(mx.preference(), host)
|
||||||
hosts
|
})
|
||||||
|
.collect();
|
||||||
|
hosts.sort();
|
||||||
|
hosts
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
if e.is_no_records_found() {
|
||||||
|
// "implicit MX" as described by section 5.1 of RFC5321
|
||||||
|
// https://datatracker.ietf.org/doc/html/rfc5321#section-5.1
|
||||||
|
log::debug!("No MX record found, using implicit MX: {mx_domain}");
|
||||||
|
vec![(0, mx_domain)]
|
||||||
|
} else if e.is_nx_domain() {
|
||||||
|
return Err(format!("512 Domain {mx_domain} does not exist"));
|
||||||
|
} else {
|
||||||
|
return Err(format!("421 DNS resolution failed for {mx_domain}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user