Skip to main content

AuthenticationResults

Struct AuthenticationResults 

Source
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>

Source

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.

Source

pub fn with_dkim_results( self, dkim: &[DkimOutput<'_>], header_from: &str, ) -> Self

Adds one dkim entry per DKIM output. See set_dkim_result.

Source

pub fn set_dkim_results(&mut self, dkim: &[DkimOutput<'_>], header_from: &str)

Adds one dkim entry per DKIM output. See set_dkim_result.

Source

pub fn with_dkim_result(self, dkim: &DkimOutput<'_>, header_from: &str) -> Self

Adds a dkim or dkim-atps entry. See set_dkim_result.

Source

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.

Source

pub fn with_dkim2_result(self, dkim2: &Dkim2Output<'_>) -> Self

Adds a dkim2 entry. See set_dkim2_result.

Source

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.

Source

pub fn with_spf_result( self, spf: &SpfOutput, params: &SpfParameters<'_>, ) -> Self

Adds an spf entry. See set_spf_result.

Source

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.

Source

pub fn with_dmarc_result(self, dmarc: &DmarcOutput) -> Self

Adds a dmarc entry. See set_dmarc_result.

Source

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).

Source

pub fn with_iprev_result(self, iprev: &IprevOutput, remote_ip: IpAddr) -> Self

Adds an iprev entry. See set_iprev_result.

Source

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>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'x> Debug for AuthenticationResults<'x>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for AuthenticationResults<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'x> Eq for AuthenticationResults<'x>

Source§

impl HeaderWriter for AuthenticationResults<'_>

Source§

fn write_header(&self, writer: &mut impl Writer)

Writes the complete header field, including the field name and the trailing CRLF, to writer.
Source§

fn to_header(&self) -> String

Returns the complete header field as a string, including the field name and the trailing CRLF. Invalid UTF-8 is replaced with U+FFFD.
Source§

impl<'x> PartialEq for AuthenticationResults<'x>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'x> StructuralPartialEq for AuthenticationResults<'x>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more