pub struct AuthenticationResults<'x> { /* private fields */ }Expand description
An Authentication-Results header (RFC 8601) under construction.
Create one with new, naming the host that performed the
checks (the authserv-id), then add the output of each verifier. Every
result has a consuming with_* method for chaining and a set_* method
that takes &mut self. Results are written in the order they are added.
A header with no results is written as Authentication-Results: <authserv-id>; none.
The Display implementation renders the header value without the field
name and without the trailing CRLF.
§Example
use mail_auth::{
AuthenticatedMessage, AuthenticationResults, MessageAuthenticator,
headers::HeaderWriter, spf::verify::SpfParameters,
};
let authenticator = MessageAuthenticator::new_cloudflare_tls().unwrap();
let message = AuthenticatedMessage::parse(raw_message).unwrap();
let dkim = authenticator.verify_dkim(&message).await;
let spf_params = || {
SpfParameters::mail_from(
"192.0.2.10".parse().unwrap(),
"mail.example.org",
"mx.example.com",
"sender@example.org",
)
};
let spf = authenticator.verify_spf(spf_params()).await;
let header = AuthenticationResults::new("mx.example.com")
.with_dkim_results(&dkim, message.first_from_address())
.with_spf_result(&spf, &spf_params())
.to_header();Implementations§
Source§impl<'x> AuthenticationResults<'x>
impl<'x> AuthenticationResults<'x>
Sourcepub fn new(hostname: &'x str) -> Self
pub fn new(hostname: &'x str) -> Self
Creates an empty header. hostname is the authserv-id (RFC 8601
Section 2.5): the name of the host that performed the checks.
Sourcepub fn with_dkim_results(
self,
dkim: &[DkimOutput<'_>],
header_from: &str,
) -> Self
pub fn with_dkim_results( self, dkim: &[DkimOutput<'_>], header_from: &str, ) -> Self
Adds one dkim entry per DKIM output. See
set_dkim_result.
Sourcepub fn set_dkim_results(&mut self, dkim: &[DkimOutput<'_>], header_from: &str)
pub fn set_dkim_results(&mut self, dkim: &[DkimOutput<'_>], header_from: &str)
Adds one dkim entry per DKIM output. See
set_dkim_result.
Sourcepub fn with_dkim_result(self, dkim: &DkimOutput<'_>, header_from: &str) -> Self
pub fn with_dkim_result(self, dkim: &DkimOutput<'_>, header_from: &str) -> Self
Adds a dkim or dkim-atps entry. See
set_dkim_result.
Sourcepub fn set_dkim_result(&mut self, dkim: &DkimOutput<'_>, header_from: &str)
pub fn set_dkim_result(&mut self, dkim: &DkimOutput<'_>, header_from: &str)
Adds a dkim entry (RFC 8601 Section 2.7.1) for one DKIM output.
The entry reports header.i (or header.d when the signature has no
i= tag), header.s and header.b, the first eight Base64
characters of the signature (RFC 6008). An ATPS result (RFC 6541) is
written as a dkim-atps entry and also reports header.from, taken
from header_from, the RFC 5322 From address. header_from is
ignored for other results.
Sourcepub fn with_dkim2_result(self, dkim2: &Dkim2Output<'_>) -> Self
pub fn with_dkim2_result(self, dkim2: &Dkim2Output<'_>) -> Self
Adds a dkim2 entry. See set_dkim2_result.
Sourcepub fn set_dkim2_result(&mut self, dkim2: &Dkim2Output<'_>)
pub fn set_dkim2_result(&mut self, dkim2: &Dkim2Output<'_>)
Adds a dkim2 entry for the result of a DKIM2 chain verification.
The entry reports header.d (signing domain) and header.i
(signature instance number) of the first link in the chain when the
chain passed, or of the first link that did not pass otherwise. Both
are omitted for a provisional verification.
Sourcepub fn with_spf_result(
self,
spf: &SpfOutput,
params: &SpfParameters<'_>,
) -> Self
pub fn with_spf_result( self, spf: &SpfOutput, params: &SpfParameters<'_>, ) -> Self
Adds an spf entry. See set_spf_result.
Sourcepub fn set_spf_result(&mut self, spf: &SpfOutput, params: &SpfParameters<'_>)
pub fn set_spf_result(&mut self, spf: &SpfOutput, params: &SpfParameters<'_>)
Adds an spf entry (RFC 8601 Section 2.7.2) for an SPF output.
params supplies the client IP, the HELO domain, the host domain and
the MAIL FROM address. Pass the MAIL FROM address as received, empty
for the null reverse-path (check_host substitutes
postmaster@<domain> on its own); a substituted address would be
reported instead of <>. The reported
identity follows the identity that check_host evaluated: smtp.helo
when the HELO identity produced the result, otherwise smtp.mailfrom
(written as <> for the null reverse-path). A comment explaining the
result, including the client IP address, precedes the property.
Sourcepub fn with_dmarc_result(self, dmarc: &DmarcOutput) -> Self
pub fn with_dmarc_result(self, dmarc: &DmarcOutput) -> Self
Adds a dmarc entry. See set_dmarc_result.
Sourcepub fn set_dmarc_result(&mut self, dmarc: &DmarcOutput)
pub fn set_dmarc_result(&mut self, dmarc: &DmarcOutput)
Adds a dmarc entry for a DMARC output (RFC 9989).
The result is the best of the DKIM and SPF alignment results. The
entry reports header.from (the RFC 5322 From domain) and
policy.dmarc, the policy published by that domain (none,
quarantine or reject).
Sourcepub fn with_iprev_result(self, iprev: &IprevOutput, remote_ip: IpAddr) -> Self
pub fn with_iprev_result(self, iprev: &IprevOutput, remote_ip: IpAddr) -> Self
Adds an iprev entry. See set_iprev_result.
Sourcepub fn set_iprev_result(&mut self, iprev: &IprevOutput, remote_ip: IpAddr)
pub fn set_iprev_result(&mut self, iprev: &IprevOutput, remote_ip: IpAddr)
Adds an iprev entry (RFC 8601 Section 3) for an iprev output.
remote_ip is the SMTP client address checked, reported as
policy.iprev.
Trait Implementations§
Source§impl<'x> Clone for AuthenticationResults<'x>
impl<'x> Clone for AuthenticationResults<'x>
Source§impl<'x> Debug for AuthenticationResults<'x>
impl<'x> Debug for AuthenticationResults<'x>
Source§impl Display for AuthenticationResults<'_>
impl Display for AuthenticationResults<'_>
impl<'x> Eq for AuthenticationResults<'x>
Source§impl HeaderWriter for AuthenticationResults<'_>
impl HeaderWriter for AuthenticationResults<'_>
Source§fn write_header(&self, writer: &mut impl Writer)
fn write_header(&self, writer: &mut impl Writer)
writer.Source§impl<'x> PartialEq for AuthenticationResults<'x>
impl<'x> PartialEq for AuthenticationResults<'x>
impl<'x> StructuralPartialEq for AuthenticationResults<'x>
Auto Trait Implementations§
impl<'x> Freeze for AuthenticationResults<'x>
impl<'x> RefUnwindSafe for AuthenticationResults<'x>
impl<'x> Send for AuthenticationResults<'x>
impl<'x> Sync for AuthenticationResults<'x>
impl<'x> Unpin for AuthenticationResults<'x>
impl<'x> UnsafeUnpin for AuthenticationResults<'x>
impl<'x> UnwindSafe for AuthenticationResults<'x>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more