#parse #email #eml #email-parsing

eml-parser

A library for parsing .eml files

2 releases

0.1.2 Feb 14, 2021
0.1.0 Apr 25, 2020

#15 in Email

Download history 414/week @ 2020-11-04 369/week @ 2020-11-11 517/week @ 2020-11-18 314/week @ 2020-11-25 373/week @ 2020-12-02 356/week @ 2020-12-09 748/week @ 2020-12-16 321/week @ 2020-12-23 798/week @ 2020-12-30 1457/week @ 2021-01-06 645/week @ 2021-01-13 703/week @ 2021-01-20 735/week @ 2021-01-27 863/week @ 2021-02-03 1324/week @ 2021-02-10 1528/week @ 2021-02-17

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

Custom license

30KB
604 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()?
    .unwrap();

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

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

Dependencies

~1.5MB
~40K SLoC