Crates.io | eml-parser |
lib.rs | eml-parser |
version | 0.1.4 |
source | src |
created_at | 2020-04-25 05:54:15.069065 |
updated_at | 2023-11-26 18:29:08.619453 |
description | A library for parsing .eml files. |
homepage | https://github.com/aeshirey/EmlParser/ |
repository | https://github.com/aeshirey/EmlParser/ |
max_upload_size | |
id | 233861 |
size | 52,507 |
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 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:
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);