spf: take argument in a more flexible way

This commit is contained in:
Dirkjan Ochtman
2024-10-12 08:00:15 -07:00
committed by Wez Furlong
parent 90219f5179
commit 7d60811bf6
2 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -65,8 +65,8 @@ impl<'a> SpfContext<'a> {
}
}
pub(crate) fn domain(&self, spec: &Option<DomainSpec>) -> Result<String, SpfResult> {
let Some(spec) = spec.as_ref() else {
pub(crate) fn domain(&self, spec: Option<&DomainSpec>) -> Result<String, SpfResult> {
let Some(spec) = spec else {
return Ok(self.domain.to_owned());
};
+3 -3
View File
@@ -93,7 +93,7 @@ impl Directive {
let matched = match &self.mechanism {
Mechanism::All => true,
Mechanism::A { domain, cidr_len } => {
let domain = cx.domain(domain)?;
let domain = cx.domain(domain.as_ref())?;
let resolved = match resolver.lookup_ip(&domain).await {
Ok(ips) => ips,
Err(err) => {
@@ -109,7 +109,7 @@ impl Directive {
.any(|&resolved_ip| cidr_len.matches(cx.client_ip, resolved_ip))
}
Mechanism::Mx { domain, cidr_len } => {
let domain = cx.domain(domain)?;
let domain = cx.domain(domain.as_ref())?;
let exchanges = match resolver.lookup_mx(&domain).await {
Ok(exchanges) => exchanges,
Err(err) => {
@@ -160,7 +160,7 @@ impl Directive {
}
.matches(cx.client_ip, IpAddr::V6(*ip6_network)),
Mechanism::Ptr { domain } => {
let domain = match Name::from_str(&cx.domain(domain)?) {
let domain = match Name::from_str(&cx.domain(domain.as_ref())?) {
Ok(domain) => domain,
Err(err) => {
return Err(SpfResult {