#spf #dns #domain #smtp #data-model #query-api

viaspf-record

Data model and parser for Sender Policy Framework (SPF) records

6 releases

0.5.0 Sep 12, 2023
0.5.0-alpha.1 Jul 12, 2023
0.4.1 May 10, 2022
0.4.0 Mar 6, 2022
0.4.0-alpha.3 Jan 20, 2022

#321 in Email

Download history 198/week @ 2023-12-13 117/week @ 2023-12-20 132/week @ 2023-12-27 145/week @ 2024-01-03 168/week @ 2024-01-10 235/week @ 2024-01-17 218/week @ 2024-01-24 238/week @ 2024-01-31 237/week @ 2024-02-07 280/week @ 2024-02-14 154/week @ 2024-02-21 206/week @ 2024-02-28 262/week @ 2024-03-06 263/week @ 2024-03-13 353/week @ 2024-03-20 187/week @ 2024-03-27

1,093 downloads per month
Used in 18 crates (via viaspf)

GPL-3.0-or-later

90KB
2.5K SLoC

viaspf-record

The viaspf-record library contains a data model and parser for SPF records. SPF records are described in the Sender Policy Framework specification, version 1 (RFC 7208).

The data structures in this library constitute a complete and faithful encoding of the ABNF in RFC 7208, section 12. Extensive checking ensures correctness and conformance with the specification.

This library is used in viaspf, where you can find a complete implementation of SPF, including APIs for performing SPF queries. The viaspf-record library is a stand-alone product and could also be used in other projects.

The minimum supported Rust version is 1.65.0.

Usage

This is a Rust library. Include viaspf-record in Cargo.toml as usual.

The 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,
            }),
        ],
    })
);

Refer to the API documentation for details.

Licence

Copyright © 2020–2023 David Bürgin

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

No runtime deps