Struct SpfBuilder

Source
pub struct SpfBuilder<State = Builder> { /* private fields */ }
Available on crate feature builder only.
Expand description

The definition of the SpfBuilder struct which contains all information related a single SPF record.

Implementations§

Source§

impl<State> SpfBuilder<State>

Source

pub fn new() -> Self

Create a new empty SpfBuilder struct.

use decon_spf::{SpfBuilder, Builder};
use decon_spf::mechanism::{Mechanism, MechanismError, Qualifier};

// Strict building style.
let mut spf: SpfBuilder<Builder> = SpfBuilder::new();
spf.set_v1()
    .add_a(Mechanism::a(Qualifier::Pass))
    .add_mx(Mechanism::mx(Qualifier::Pass).with_rrdata("test.com").unwrap());
// add_all() changes the struct state from Builder to ContainsAll
let mut spf = spf.add_all(Mechanism::all());

let mut spf = SpfBuilder::new_builder();
spf
    .set_v1()
    .append_mechanism(Mechanism::a(Qualifier::Pass))
    .append_mechanism(Mechanism::ip_from_string("ip4:203.32.160.10").unwrap())
    .append_mechanism(Mechanism::all());
Source

pub fn version(&self) -> &String

Access the version attribute

Source§

impl SpfBuilder<Builder>

Source

pub fn new_builder() -> SpfBuilder<Builder>

Create an SpfBuilder with State of Builder

Source§

impl SpfBuilder<Parsed>

Source

pub fn new_parsed() -> SpfBuilder<Parsed>

Create an SpfBuilder with State of Parsed

Source§

impl<State> SpfBuilder<State>
where State: Modifiable,

Source

pub fn set_v1(&mut self) -> &mut Self

Set version to v=spf1

Source

pub fn add_a(&mut self, mechanism: Mechanism<String>) -> &mut Self

Add an a mechanism

Source

pub fn add_mx(&mut self, mechanism: Mechanism<String>) -> &mut Self

Add an mx mechanism

Source

pub fn add_include(&mut self, mechanism: Mechanism<String>) -> &mut Self

Add an include Mechanism

Source

pub fn add_ip(&mut self, mechanism: Mechanism<IpNetwork>) -> &mut Self

Add either and Ip4 or Ip6 Mechanism

Source§

impl SpfBuilder<Builder>

Source

pub fn add_redirect( self, mechanism: Mechanism<String>, ) -> SpfBuilder<Redirected>

Append a Redirect Mechanism to the Spf Struct. This also changes the struct’s State

Source

pub fn add_all(self, mechanism: Mechanism<All>) -> SpfBuilder<ContainsAll>

Add a Mechanism to the SpfBuilder struct. This also changes the State to ContainsAll

Source§

impl<State> SpfBuilder<State>
where State: Modifiable,

Source

pub fn set_v2_pra(&mut self) -> &mut Self

Available on crate feature spf2 only.

Set version to spf2.0/pra

Source

pub fn set_v2_mfrom(&mut self) -> &mut Self

Available on crate feature spf2 only.

Set version to spf2.0/mfrom

Source

pub fn set_v2_pra_mfrom(&mut self) -> &mut Self

Available on crate feature spf2 only.

Set version to spf2.0/pra,mfrom

Source

pub fn set_v2_mfrom_pra(&mut self) -> &mut Self

Available on crate feature spf2 only.

Set version to spf2.0/mfrom,pra

Source

pub fn is_v2(&self) -> bool

Available on crate feature spf2 only.

Check that version is v2

Source§

impl<State> SpfBuilder<State>

Source

pub fn clear_mechanism(&mut self, kind: Kind)
where State: Modifiable,

Clear the passed Kind which has been passed. Sets the passed mechanism to None

§Note:

This method clears all associated Mechanism for the Kind provided.

§Example:
use decon_spf::mechanism::{Qualifier, Kind, Mechanism};
use decon_spf::{Builder, SpfBuilder};
let mut spf: SpfBuilder<Builder> = SpfBuilder::new();
spf.set_v1();
spf.append_mechanism(Mechanism::all_with_qualifier(Qualifier::Pass));
spf.append_mechanism(Mechanism::a(Qualifier::Pass));
spf.append_mechanism(Mechanism::ip(Qualifier::Pass,
                                                 "203.32.160.0/23".parse().unwrap()));
// Remove ip4 Mechanism
spf.clear_mechanism(Kind::IpV4);
Source

pub fn append_mechanism<T>(&mut self, mechanism: Mechanism<T>) -> &mut Self
where Self: Append<T>,

This is generic method for adding Mechanism<T> to the SpfBuilder struct.

§Note:

This approach does not provide protection to prevent redirect and all from both being present in a single SpfBuilder struct. If you wish to prevent this. Please use the add_redirect() and add_all() functions.

use decon_spf::mechanism::{Qualifier, Mechanism};
use decon_spf::{Builder, Spf, SpfBuilder};
let mut spf: SpfBuilder<Builder> = SpfBuilder::new();
spf.set_v1();
spf.append_mechanism(Mechanism::redirect(Qualifier::Pass,
                                "_spf.example.com").unwrap())
   .append_mechanism(Mechanism::all_with_qualifier(Qualifier::Pass));

let mut spf: SpfBuilder<Builder> = SpfBuilder::new_builder();
spf.set_v1().add_a(Mechanism::a(Qualifier::Pass));
let mut spf = spf.add_all(Mechanism::all()); // spf -> SpfBuilder<ContainsAll>
// spf.redirect() and spf.add_all() are only defined for SpfBuilder<Builder>
// As such they do not exist for <ContainsAll> or <Redirect>
Source

pub fn is_redirect(&self) -> bool

True if there is a redirect present in the spf record.

Source

pub fn redirect(&self) -> Option<&Mechanism<String>>

Returns a reference to the Redirect Mechanism

Source

pub fn includes(&self) -> Option<&Vec<Mechanism<String>>>

Returns a reference to the a Vec of Mechanism<String> for Include

Source

pub fn a(&self) -> Option<&Vec<Mechanism<String>>>

Returns a reference to a Vec of Mechanism<String> for A

Source

pub fn mx(&self) -> Option<&Vec<Mechanism<String>>>

Returns a reference to a Vec of Mechanism<String> for MX

Source

pub fn ip4(&self) -> Option<&Vec<Mechanism<IpNetwork>>>

Returns a reference to a Vec of Mechanism<IpNetwork> for IP4

Source

pub fn ip6(&self) -> Option<&Vec<Mechanism<IpNetwork>>>

Returns a reference to a Vec of Mechanism<IpNetwork> for IP6

Source

pub fn exists(&self) -> Option<&Vec<Mechanism<String>>>

Returns a reference to a Vec of Mechanism<String> for Exists

Source

pub fn ptr(&self) -> Option<&Mechanism<String>>

Returns a reference to a Vec of Mechanism<String> for Ptr

Source

pub fn all(&self) -> Option<&Mechanism<All>>

Returns a reference to Mechanism<All> for All

Source

pub fn build(self) -> Result<Spf<String>, SpfError>

Creates a Spf<String> from SpfBuilder This function also validates the SpfBuilder struct before returning a Spf

use decon_spf::{Spf, SpfBuilder, Builder, SpfError};
use decon_spf::mechanism::{Mechanism, Qualifier};
let mut builder: SpfBuilder<Builder> = SpfBuilder::new();
// Note Version was not Set. build() assumes v=spf1 when not present
builder.add_a(Mechanism::a(Qualifier::Pass));
let mut builder = builder.add_all(Mechanism::all());
let spf = match builder.build() {
    Ok(result) => { result },
    Err(_) => { panic!() }
};
assert_eq!(1,spf.lookup_count());

let mut builder: SpfBuilder<Builder> = SpfBuilder::new();
builder.append_mechanism(Mechanism::redirect(Qualifier::Pass,"test.com").expect("ok"));
builder.append_mechanism(Mechanism::all());

let result = match builder.build() {
    Ok(_) => { panic!()},
    Err(e) => {
        assert!(matches!(e, SpfError::RedirectWithAllMechanism));
        e
    }
};
assert!(result.is_spf_error());
Source§

impl<State> SpfBuilder<State>

Source

pub fn iter(&self) -> SpfBuilderIterator

Allows you to iterate over Mechanisms contained within the SPF record.

§Note: Version string is not included.

Trait Implementations§

Source§

impl<State: Clone> Clone for SpfBuilder<State>

Source§

fn clone(&self) -> SpfBuilder<State>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<State: Debug> Debug for SpfBuilder<State>

Source§

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

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

impl<State> Default for SpfBuilder<State>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, State> Deserialize<'de> for SpfBuilder<State>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<State> Display for SpfBuilder<State>

Source§

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

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

impl From<Spf<String>> for SpfBuilder<Builder>

Converts a Spf<String> into a SpfBuilder`struct.

Source§

fn from(source: Spf<String>) -> SpfBuilder<Builder>

Converts to this type from the input type.
Source§

impl FromStr for SpfBuilder<Parsed>

Creates an SpfBuilder struct by parsing a string representation of Spf.

§Examples:

 use decon_spf::{Parsed, SpfBuilder};
 use decon_spf::SpfError;
 // Successful
 let input = "v=spf1 a mx -all";
 let spf: SpfBuilder<Parsed> = input.parse().unwrap();
 assert_eq!(spf.to_string(), input);

 // Additional Space between `A` and `MX`
 let invalid_input = "v=spf1 a   mx -all";
 let err: SpfError = invalid_input.parse::<SpfBuilder<Parsed>>().unwrap_err();
 assert_eq!(err, SpfError::WhiteSpaceSyntaxError);
 //  err.to_string() -> "Spf contains two or more consecutive whitespace characters.");
Source§

type Err = SpfError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<State: PartialEq> PartialEq for SpfBuilder<State>

Source§

fn eq(&self, other: &SpfBuilder<State>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<State> Serialize for SpfBuilder<State>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<State> StructuralPartialEq for SpfBuilder<State>

Auto Trait Implementations§

§

impl<State> Freeze for SpfBuilder<State>

§

impl<State> RefUnwindSafe for SpfBuilder<State>
where State: RefUnwindSafe,

§

impl<State> Send for SpfBuilder<State>
where State: Send,

§

impl<State> Sync for SpfBuilder<State>
where State: Sync,

§

impl<State> Unpin for SpfBuilder<State>
where State: Unpin,

§

impl<State> UnwindSafe for SpfBuilder<State>
where State: UnwindSafe,

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,