pub struct SpfBuilder<State = Builder> { /* private fields */ }
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>
impl<State> SpfBuilder<State>
Sourcepub fn new() -> Self
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§impl SpfBuilder<Builder>
impl SpfBuilder<Builder>
Sourcepub fn new_builder() -> SpfBuilder<Builder>
pub fn new_builder() -> SpfBuilder<Builder>
Create an SpfBuilder with State
of Builder
Source§impl SpfBuilder<Parsed>
impl SpfBuilder<Parsed>
Sourcepub fn new_parsed() -> SpfBuilder<Parsed>
pub fn new_parsed() -> SpfBuilder<Parsed>
Create an SpfBuilder with State
of Parsed
Source§impl<State> SpfBuilder<State>where
State: Modifiable,
impl<State> SpfBuilder<State>where
State: Modifiable,
Sourcepub fn add_include(&mut self, mechanism: Mechanism<String>) -> &mut Self
pub fn add_include(&mut self, mechanism: Mechanism<String>) -> &mut Self
Add an include Mechanism
Source§impl SpfBuilder<Builder>
impl SpfBuilder<Builder>
Sourcepub fn add_redirect(
self,
mechanism: Mechanism<String>,
) -> SpfBuilder<Redirected>
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
Sourcepub fn add_all(self, mechanism: Mechanism<All>) -> SpfBuilder<ContainsAll>
pub fn add_all(self, mechanism: Mechanism<All>) -> SpfBuilder<ContainsAll>
Add a MechanismState
to ContainsAll
Source§impl<State> SpfBuilder<State>where
State: Modifiable,
impl<State> SpfBuilder<State>where
State: Modifiable,
Sourcepub fn set_v2_pra(&mut self) -> &mut Self
Available on crate feature spf2
only.
pub fn set_v2_pra(&mut self) -> &mut Self
spf2
only.Set version to spf2.0/pra
Sourcepub fn set_v2_mfrom(&mut self) -> &mut Self
Available on crate feature spf2
only.
pub fn set_v2_mfrom(&mut self) -> &mut Self
spf2
only.Set version to spf2.0/mfrom
Sourcepub fn set_v2_pra_mfrom(&mut self) -> &mut Self
Available on crate feature spf2
only.
pub fn set_v2_pra_mfrom(&mut self) -> &mut Self
spf2
only.Set version to spf2.0/pra,mfrom
Sourcepub fn set_v2_mfrom_pra(&mut self) -> &mut Self
Available on crate feature spf2
only.
pub fn set_v2_mfrom_pra(&mut self) -> &mut Self
spf2
only.Set version to spf2.0/mfrom,pra
Source§impl<State> SpfBuilder<State>
impl<State> SpfBuilder<State>
Sourcepub fn clear_mechanism(&mut self, kind: Kind)where
State: Modifiable,
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);
Sourcepub fn append_mechanism<T>(&mut self, mechanism: Mechanism<T>) -> &mut Selfwhere
Self: Append<T>,
pub fn append_mechanism<T>(&mut self, mechanism: Mechanism<T>) -> &mut Selfwhere
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>
Sourcepub fn is_redirect(&self) -> bool
pub fn is_redirect(&self) -> bool
True if there is a redirect present in the spf record.
Sourcepub fn redirect(&self) -> Option<&Mechanism<String>>
pub fn redirect(&self) -> Option<&Mechanism<String>>
Returns a reference to the Redirect
Mechanism
Sourcepub fn includes(&self) -> Option<&Vec<Mechanism<String>>>
pub fn includes(&self) -> Option<&Vec<Mechanism<String>>>
Returns a reference to the a Vec
of Mechanism<String>
for Include
Sourcepub fn a(&self) -> Option<&Vec<Mechanism<String>>>
pub fn a(&self) -> Option<&Vec<Mechanism<String>>>
Returns a reference to a Vec
of Mechanism<String>
for A
Sourcepub fn mx(&self) -> Option<&Vec<Mechanism<String>>>
pub fn mx(&self) -> Option<&Vec<Mechanism<String>>>
Returns a reference to a Vec
of Mechanism<String>
for MX
Sourcepub fn ip4(&self) -> Option<&Vec<Mechanism<IpNetwork>>>
pub fn ip4(&self) -> Option<&Vec<Mechanism<IpNetwork>>>
Returns a reference to a Vec
of Mechanism<IpNetwork>
for IP4
Sourcepub fn ip6(&self) -> Option<&Vec<Mechanism<IpNetwork>>>
pub fn ip6(&self) -> Option<&Vec<Mechanism<IpNetwork>>>
Returns a reference to a Vec
of Mechanism<IpNetwork>
for IP6
Sourcepub fn exists(&self) -> Option<&Vec<Mechanism<String>>>
pub fn exists(&self) -> Option<&Vec<Mechanism<String>>>
Returns a reference to a Vec
of Mechanism<String>
for Exists
Sourcepub fn ptr(&self) -> Option<&Mechanism<String>>
pub fn ptr(&self) -> Option<&Mechanism<String>>
Returns a reference to a Vec
of Mechanism<String>
for Ptr
Sourcepub fn build(self) -> Result<Spf<String>, SpfError>
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());
Trait Implementations§
Source§impl<State: Clone> Clone for SpfBuilder<State>
impl<State: Clone> Clone for SpfBuilder<State>
Source§fn clone(&self) -> SpfBuilder<State>
fn clone(&self) -> SpfBuilder<State>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<State: Debug> Debug for SpfBuilder<State>
impl<State: Debug> Debug for SpfBuilder<State>
Source§impl<State> Default for SpfBuilder<State>
impl<State> Default for SpfBuilder<State>
Source§impl<'de, State> Deserialize<'de> for SpfBuilder<State>
impl<'de, State> Deserialize<'de> for SpfBuilder<State>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<State> Display for SpfBuilder<State>
impl<State> Display for SpfBuilder<State>
Source§impl From<Spf<String>> for SpfBuilder<Builder>
Converts a Spf<String> into a
SpfBuilder`struct.
impl From<Spf<String>> for SpfBuilder<Builder>
Converts a Spf<String> into a
SpfBuilder`struct.
Source§impl FromStr for SpfBuilder<Parsed>
Creates an SpfBuilder struct
by parsing a string representation of Spf.
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.");