#header-parser #pest-parser #parser #peg

email-address-list

Pest based parser for address-lists in email headers like to/from/cc/etc

5 unstable releases

0.3.0 Apr 25, 2024
0.2.5 Nov 20, 2019
0.2.1 Dec 1, 2018
0.2.0 Dec 1, 2018
0.1.0 Nov 10, 2018

#709 in Parser implementations

Download history 4/week @ 2024-09-19 2/week @ 2024-09-26

281 downloads per month

GPL-3.0 license

44KB
1K SLoC

Rust 1K SLoC // 0.0% comments Pest 143 SLoC

email-address-list

Crate version Documentation License

Relatively naïve Pest based parser, picking out "contacts" from "email address lists" found in headers such as from, to, cc, etc.

This library aims to be practical rather than "correct". It is (potentially excessively) permissive in parsing even the worst garbage in everyone's inbox. Limited testing with real world data was done, but the grammar probably still needs work to catch even more edge cases.

0.0.x releases may contain bugfixes and features, 0.x.0 might break compatibility.

Examples

RFC compliant header:

use email_address_list::*;

let manual: AddressList = vec![
    Contact::new("ríomhphost@example.org").set_name("Túsainm Sloinne"),
    Contact::new("sampla@example.org")
].into();

let result = parse_address_list(
    "Túsainm Sloinne <ríomhphost@example.org>, sampla@example.org"
).unwrap();

assert!(result.deep_eq(&manual));

Non RFC compliant header:

let manual: AddressList = vec![
    Contact::new("enaslov@example.org").set_name("Ime Priimek"),
    Contact::new("primer@example.org"),
    Contact::new("nepravilno.oblikovan@example.org")
        .set_name("Oblikovan, Nepravilno"),
    Contact::new("napačno.oblikovan@example.org"),
].into();

let result = parse_address_list(
    concat!(
        r#""Ime Priimek" <enaslov@example.org;primer@example.org>, "#,
        "Oblikovan, Nepravilno <nepravilno.oblikovan@example.org,>>, ",
        "<'napačno.oblikovan@example.org'>",
    )
).unwrap();

assert!(result.deep_eq(&manual));

If you find examples of email-address-list failing, either by omitting addresses or supplying wrong addresses, please share them with the author.

For further information, please see the documentation.

Thanks

Dependencies

~4–6.5MB
~130K SLoC