use aok::Result;
use crate::{record_type, resolve};
#[derive(Debug, Clone)]
pub struct Mx {
pub priority: u16,
pub server: String,
pub ttl: u64,
}
pub async fn mx(domain: impl AsRef<str>) -> Result<Vec<Mx>> {
resolve(domain, "MX", |li| {
let mut r = Vec::with_capacity(li.len());
for i in li {
if i.r#type == record_type::MX {
if let Some((priority_str, server)) = i.data.split_once(' ')
&& let Ok(priority) = priority_str.parse::<u16>()
{
r.push(Mx {
priority,
server: server.trim_end_matches('.').to_string(),
ttl: i.ttl,
});
}
}
}
Ok(Some(r))
})
.await
}