pub struct Spf { /* private fields */ }
Expand description
The definition of the Spf struct which contains all information related a single SPF record.
Implementations
Check that data stored in the Spf Struct is considered a valid Spf Record.
This is supported on crate feature warn-dns
only.
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
Set version to spf2.0/pra
Set version to spf2.0/mfrom
Set version to spf2.0/pra,mfrom
Set version to spf2.0/mfrom,pra
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());
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.
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());
👎 Deprecated: This is expected to be depreciated.
This is expected to be depreciated.
Note: Experimential
Do not use. Very rudementary 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)
True if there is a redirect present in the spf record.
Returns a reference to the Redirect
Mechanism
Returns a reference to the a Vec
of Mechanism<String>
for Include
Returns a reference to the a Vec
of Mechanism<String>
for A
Returns a reference to the a Vec
of Mechanism<String>
for MX
Returns a reference to the a Vec
of Mechanism<IpNetwork>
for IP4
Returns a reference to the a Vec
of Mechanism<IpNetwork>
for IP6
Returns a reference to the a Vec
of Mechanism<String>
for Exists
Returns a reference to the a Vec
of Mechanism<String>
for Ptr
Returns a reference to Mechanism<String>
for All
Trait Implementations
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");