Expand description
A library containing a data model and parser for Sender Policy Framework (SPF) records.
The data structures in this library are modeled after the ABNF in RFC 7208, section 12.
§Usage
The main top-level data structure in this module is the SpfRecord
struct. SpfRecord
represents a syntactically valid SPF record. An
SpfRecord
can be constructed programmatically or parsed from a string:
use std::net::Ipv4Addr;
use viaspf_record::*;
let spf_record = "v=spf1 mx ip4:12.34.56.78/24 -all".parse();
assert_eq!(
spf_record,
Ok(SpfRecord {
terms: vec![
Term::Directive(Directive {
qualifier: None,
mechanism: Mechanism::Mx(Mx {
domain_spec: None,
prefix_len: None,
}),
}),
Term::Directive(Directive {
qualifier: None,
mechanism: Mechanism::Ip4(Ip4 {
addr: Ipv4Addr::new(12, 34, 56, 78),
prefix_len: Some(Ip4CidrLength::new(24).unwrap()),
}),
}),
Term::Directive(Directive {
qualifier: Some(Qualifier::Fail),
mechanism: Mechanism::All,
}),
],
})
);
Also provided as a top-level data structure is the ExplainString
struct.
It can be parsed from a string in the same way.
SPF record data may be printed via Display
. The string representations are
the canonical SPF string representations. Thus roundtripping through parsing
and printing is possible:
use viaspf_record::SpfRecord;
let record_str = "v=spf1 mx -all";
assert_eq!(record_str.parse::<SpfRecord>()?.to_string(), record_str);
Structs§
- A
- An a mechanism.
- Delimiters
- Macro delimiter characters.
- Directive
- A directive.
- Domain
Spec - A domain specification.
- Exists
- An exists mechanism.
- Explain
String - An explain string.
- Explanation
- An exp modifier.
- Include
- An include mechanism.
- Ip4
- An ip4 mechanism.
- Ip6
- An ip6 mechanism.
- Ip4Cidr
Length - An IPv4 CIDR prefix length.
- Ip6Cidr
Length - An IPv6 CIDR prefix length.
- Macro
- A macro.
- Macro
Literal - A literal part of a macro string.
- Macro
String - A macro string.
- Mx
- An mx mechanism.
- Name
- A modifier name.
- Parse
Error - An error indicating that SPF record data could not be parsed.
- Ptr
- A ptr mechanism.
- Redirect
- A redirect modifier.
- SpfRecord
- An SPF record.
- Unknown
- An unknown modifier.
Enums§
- Dual
Cidr Length - A combined IPv4 and/or IPv6 CIDR prefix length.
- Escape
- An escape sequence in a macro string.
- Explain
String Segment - A part of an explain string.
- Macro
Expand - A part of a macro string that may be expanded.
- Macro
Kind - The kind of a macro (macro letter).
- Macro
String Segment - A part of a macro string.
- Mechanism
- A mechanism.
- Modifier
- A modifier.
- Qualifier
- A qualifier.
- Term
- A term.