Struct decon_spf::Spf[][src]

pub struct Spf { /* fields omitted */ }
Expand description

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

Implementations

Create a new empty Spf struct.

Check that the source string was parsed and was valid. Check that data stored in the Spf Struct is considered a valid Spf Record.

This is supported 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

Set version to v=spf1

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

Check that version is v1

Check that version is v2

Return a reference to version

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::new_all(Qualifier::Pass));
new_spf_record.append_mechanism(Mechanism::new_a_without_mechanism(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::new_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::new_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.

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, and Include Mechanism. See: LookupLimitExceeded (This will change given new information)
👎 Deprecated since 0.2.0:

This has been deprecated. Use to_string() instead.

Returns a new string representation of the spf record if possible. This does not use the source attribute.

Returns a reference to the string stored in source

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

This is supported on crate feature warn-dns only.

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

Trait Implementations

Formats the value using the given formatter. Read more

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

Formats the value using the given formatter. Read more

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.to_string().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.to_string().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");

The associated error which can be returned from parsing.

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

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.