pub fn parse_mime_headers(
raw: &str,
) -> Result<HashMap<String, String>, Box<dyn Error>>Expand description
Parses the headers of a MIME email, returning a hashmap of the headers.
The parsing is done by splitting the raw email on the first empty line, and splitting each line on the colon, separating the key and value.
Aligned with the RFC 2045, the headers are case-insensitive.
ยงExamples
let expected = [("From", "test@example.com"), ("To", "test@example.com")]
.into_iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect::<std::collections::HashMap<_, _>>();
let headers = mailsis_utils::parse_mime_headers("From: test@example.com\r\nTo: test@example.com\r\n").unwrap();
assert_eq!(headers, expected);let expected = [("From", "test@example.com"), ("To", "test@example.com")]
.into_iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect::<std::collections::HashMap<_, _>>();
let headers = mailsis_utils::parse_mime_headers("From: test@example.com\r\nTo: test@example.com\r\n\r\nBody of the email").unwrap();
assert_eq!(headers, expected);