4 releases

0.1.4 Nov 26, 2023
0.1.3 Mar 12, 2022
0.1.2 Feb 14, 2021
0.1.0 Apr 25, 2020

#48 in Email

Download history 992/week @ 2024-07-22 919/week @ 2024-07-29 682/week @ 2024-08-05 746/week @ 2024-08-12 1138/week @ 2024-08-19 1016/week @ 2024-08-26 1294/week @ 2024-09-02 1030/week @ 2024-09-09 1115/week @ 2024-09-16 914/week @ 2024-09-23 867/week @ 2024-09-30 1016/week @ 2024-10-07 1453/week @ 2024-10-14 1227/week @ 2024-10-21 1076/week @ 2024-10-28 1040/week @ 2024-11-04

4,910 downloads per month
Used in 4 crates (2 directly)

Custom license

33KB
658 lines

EmlParser

EmlParser is a crate intended to parse .eml files. Currently, this crate is very basic, supporting extracting field (name,value) pairs from an email header plus the body of the message. Special headers To, From, and Subject are separated out; all others are currently listed in a Vec<HeaderField>.

The parsing for this crate attempts to follow RFC-0822, though in practice there seem to be deviations from the RFC as to how to handle newlines. The spec lays out that the body and header are separated by a null line, as delimited by CRLF. Often, we'll actually see \n\n, so EmlParser allows \n\n, \r\r, and \r\n\r\n.

Note that header fields are able to include newlines in them, defined as linear whitespace.

Finding the separator between the header and body follows the following transition digram:

Transition diagram for detecting the header/body delimiter

Usage

You can use EmlParser with a &str or a filename:

let eml: Eml = EmlParser::from_file("Re: hello.eml")?
    .ignore_body()
    .parse()?;

let expected = HeaderFieldValue::SingleEmailAddress(EmailAddress::NameAndEmailAddress {
    name: "Anne Thompson".to_string(),
    address: "anne@example.com".to_string(),
});

assert_eq!(Some(expected), eml.from);
assert_eq!(Some("Re: hello".to_string()), eml.subject);

Dependencies

~10MB
~233K SLoC