Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow external usage of parsing functions for SPF, DMARC and DKIM structs #30

Merged
merged 3 commits into from
May 15, 2024

Conversation

Miesvanderlippe
Copy link
Contributor

This is useful for other projects that want to use the parsing functionality on its own, without parsing an entire e-mail.

Closes #29

Some test code:

use mail_auth::{common::parse::TxtRecordParser, spf::Spf, dmarc::Dmarc, dkim::Signature};

fn main() {
    let spf_record = "v=spf1 A:example.com MX -all";
    match Spf::parse(spf_record.as_bytes()) {
        Ok(parsed_record) => {
            println!("SPF: {:?}", parsed_record);
        }, 
        Err(_) => { println!("Whoops"); }
    }

    let dmarc_record = "v=DMARC1; p=quarantine; adkim=s; aspf=s; rua=mailto:report@example.com; pct=100; fo=0:1:d:s;";

    match Dmarc::parse(dmarc_record.as_bytes()) {
        Ok(parsed_record) => {
            println!("Dmarc: {:?}", parsed_record);
        }, 
        Err(_) => { println!("Whoops"); },
    }

    let dkim_signature = "DKIM-Signature: v=1; a=rsa-sha256; s=jun2005.eng; c=relaxed/relaxed; d=example.com; s=dkim; t=1526555738; bh=mhU6OJb5ldZf+z/pX9+0Nc4tj/lmyYHWbR8LgI2Q=; h=To:From:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding; b=s1sdZCzdX9vxocsMSlT7cOrYixl1g8wfkdzrVe7BGN6ZdPV9xu2A";
    match Signature::parse(dkim_signature.as_bytes()) {
        Ok(parsed_record) => {
            println!("Dkim: {:?}", parsed_record);
        }, 
        Err(_) => { println!("Whoops"); },
    }
}

For using the Spf parser in other packages
For using the Spf parser in other packages
For using the Spf parser in other packages
@mdecimus mdecimus merged commit 0a0ac88 into stalwartlabs:main May 15, 2024
1 check failed
@Miesvanderlippe
Copy link
Contributor Author

Thanks for the quick merge @mdecimus :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Please consider making parsing results available
2 participants