Struct decon_spf::Spf

source ·
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

source

pub fn new() -> Self

Create a new empty Spf struct.

source

pub fn is_valid(&self) -> bool

Check that data stored in the Spf Struct is considered a valid Spf Record.

source

pub fn has_warnings(&self) -> bool

Available on crate feature 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

source

pub fn set_v1(&mut self)

Set version to v=spf1

source

pub fn set_v2_pra(&mut self)

Set version to spf2.0/pra

source

pub fn set_v2_mfrom(&mut self)

Set version to spf2.0/mfrom

source

pub fn set_v2_pra_mfrom(&mut self)

Set version to spf2.0/pra,mfrom

source

pub fn set_v2_mfrom_pra(&mut self)

Set version to spf2.0/mfrom,pra

source

pub fn is_v1(&self) -> bool

Check that version is v1

source

pub fn is_v2(&self) -> bool

Check that version is v2

source

pub fn version(&self) -> &String

Return a reference to version

source

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());
source

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.

source

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());
source

pub fn try_validate(&mut self) -> Result<(), SpfError>

👎Deprecated: This is expected to be depreciated.
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, and Include Mechanism. See: LookupLimitExceeded (This will change given new information)
source

pub fn source(&self) -> &String

Returns a reference to the string stored in source

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 the a Vec of Mechanism<String> for A

source

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

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

source

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

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

source

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

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

source

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

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

source

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

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

source

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

Returns a reference to Mechanism<String> for All

source

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

Available on crate feature warn-dns only.

Return a reference to the list of domains that gave warnings.

Trait Implementations§

source§

impl Clone for Spf

source§

fn clone(&self) -> Spf

Returns a copy 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 Debug for Spf

source§

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

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

impl Default for Spf

source§

fn default() -> Spf

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

impl<'de> Deserialize<'de> for Spf

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 Display for Spf

source§

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

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

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");
§

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 PartialEq for Spf

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Spf

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 TryFrom<&str> for Spf

§

type Error = SpfError

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

fn try_from(s: &str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl StructuralPartialEq for Spf

Auto Trait Implementations§

§

impl RefUnwindSafe for Spf

§

impl Send for Spf

§

impl Sync for Spf

§

impl Unpin for Spf

§

impl UnwindSafe for Spf

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

§

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§

default 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>,

§

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

§

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