pub struct Spf { /* private fields */ }
Expand description
The definition of the Spf struct which contains all information related a single SPF record.
Implementations§
source§impl Spf
impl Spf
sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Check that data stored in the Spf Struct is considered a valid Spf Record.
sourcepub fn has_warnings(&self) -> bool
Available on crate feature warn-dns
only.
pub fn has_warnings(&self) -> bool
warn-dns
only.Check if there were any warnings when parsing the Spf String.
This can only be changed to true
when warn-dns
feature has been eabled. Other wise it
will always be false
sourcepub fn set_v2_pra(&mut self)
pub fn set_v2_pra(&mut self)
Set version to spf2.0/pra
sourcepub fn set_v2_mfrom(&mut self)
pub fn set_v2_mfrom(&mut self)
Set version to spf2.0/mfrom
sourcepub fn set_v2_pra_mfrom(&mut self)
pub fn set_v2_pra_mfrom(&mut self)
Set version to spf2.0/pra,mfrom
sourcepub fn set_v2_mfrom_pra(&mut self)
pub fn set_v2_mfrom_pra(&mut self)
Set version to spf2.0/mfrom,pra
sourcepub fn clear_mechanism(&mut self, kind: Kind)
pub fn clear_mechanism(&mut self, kind: Kind)
Clear the passed Kind which has been passed.
Sets the passed mechanism to None
§Note:
This method clears all assocated Mechanism for the Kind
provided.
§Example:
use decon_spf::mechanism::{Qualifier, Kind, Mechanism};
use decon_spf::Spf;
let mut new_spf_record = Spf::new();
new_spf_record.set_v1();
new_spf_record.append_mechanism(Mechanism::all(Qualifier::Pass));
new_spf_record.append_mechanism(Mechanism::a(Qualifier::Pass));
new_spf_record.append_ip_mechanism(Mechanism::new_ip(Qualifier::Pass,
"203.32.160.0/23".parse().unwrap()));
assert_eq!(new_spf_record.to_string(), "v=spf1 a ip4:203.32.160.0/23 all".to_string());
// Remove ip4 Mechanism
new_spf_record.clear_mechanism(Kind::IpV4);
assert_eq!(new_spf_record.to_string(), "v=spf1 a all".to_string());
sourcepub fn append_mechanism(&mut self, mechanism: Mechanism<String>)
pub fn append_mechanism(&mut self, mechanism: Mechanism<String>)
Appends the passed Mechanism<String>
to the SPF struct.
This only works for Mechanism which are NOT ip4:
or ip6:
§Example:
use decon_spf::mechanism::{Qualifier, Mechanism};
use decon_spf::Spf;
let mut new_spf_record = Spf::new();
new_spf_record.set_v1();
new_spf_record.append_mechanism(Mechanism::new_redirect(Qualifier::Pass,
"_spf.example.com".to_string()));
new_spf_record.append_mechanism(Mechanism::all(Qualifier::Pass));
assert_eq!(new_spf_record.to_string(), "v=spf1 redirect=_spf.example.com".to_string());
§Note:
If the Spf is already set as Redirect
trying to append an All
Mechanism will have no affect.
sourcepub fn append_ip_mechanism(&mut self, mechanism: Mechanism<IpNetwork>)
pub fn append_ip_mechanism(&mut self, mechanism: Mechanism<IpNetwork>)
Appends the passed Mechanism<IpNetwork>
to the SPF struct.
§Example:
use decon_spf::mechanism::{Qualifier, Mechanism};
use decon_spf::Spf;
let mut new_spf_record = Spf::new();
new_spf_record.set_v1();
new_spf_record.append_ip_mechanism(Mechanism::new_ip(Qualifier::Pass,
"203.32.160.0/23".parse().unwrap()));
new_spf_record.append_mechanism(Mechanism::all(Qualifier::Pass));
assert_eq!(new_spf_record.to_string(), "v=spf1 ip4:203.32.160.0/23 all".to_string());
sourcepub fn try_validate(&mut self) -> Result<(), SpfError>
👎Deprecated: This is expected to be depreciated.
pub fn try_validate(&mut self) -> Result<(), SpfError>
§Note: Experimential
Do not use. Very rudimentary validation check.
- Will fail if the length of
source
is more than MAX_SPF_STRING_LENGTH characters See:SourceLengthExceeded
- Will fail if there are more than 10 DNS lookups. Looks are required for each
A
,MX
,Redirect
, andInclude
Mechanism. See:LookupLimitExceeded
(This will change given new information)
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 the 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 the 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 the 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 the 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 the 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 the a Vec
of Mechanism<String>
for Ptr
Trait Implementations§
source§impl<'de> Deserialize<'de> for Spf
impl<'de> Deserialize<'de> for Spf
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 FromStr for Spf
impl FromStr for Spf
Creates an Spf Struct
by parsing a string representation of Spf.
§Examples:
use decon_spf::Spf;
use decon_spf::SpfError;
// Successful
let input = "v=spf1 a mx -all";
let spf: Spf = input.parse().unwrap();
assert_eq!(spf.to_string(), input);
// Additional Space between `A` and `MX`
let bad_input = "v=spf1 a mx -all";
let err: SpfError = bad_input.parse::<Spf>().unwrap_err();
assert_eq!(err.to_string(), SpfError::WhiteSpaceSyntaxError.to_string());
// err.to_string() -> "Spf contains two or more consecutive whitespace characters.");
// Example with warn-dns feature enabled.
// Spf contains an invalid DNS host entry
let bad_spf2: Spf = "v=spf1 a mx:example.m/24 -all".parse().unwrap();
// Note: `warn-dns` will check `example.m` ignoring `/24`
#[cfg(feature = "warn-dns")]
assert_eq!(bad_spf2.has_warnings(), true);
#[cfg(feature = "warn-dns")]
assert_eq!(bad_spf2.warnings().unwrap()[0], "example.m/24");