[][src]Function mailparse::parse_headers

pub fn parse_headers(
    raw_data: &[u8]
) -> Result<(Vec<MailHeader>, usize), MailParseError>

Parses all the headers from the raw data given. This function takes raw byte data, and starts parsing it, expecting there to be zero or more MIME header key-value pair right at the beginning, followed by two consecutive newlines (i.e. a blank line). It parses those headers and returns them in a vector. The normal vector functions can be used to access the headers linearly, or the MailHeaderMap trait can be used to access them in a map-like fashion. Along with this vector, the function returns the index at which the message body is expected to start. If you just care about the headers, you can ignore the second component of the returned tuple. Error values are returned if there was some sort of parsing error.

Examples

    use mailparse::{parse_headers, MailHeaderMap};
    let (headers, _) = parse_headers(concat!(
            "Subject: Test\n",
            "From: me@myself.com\n",
            "To: you@yourself.com").as_bytes())
        .unwrap();
    assert_eq!(headers[1].get_key().unwrap(), "From");
    assert_eq!(headers.get_first_value("To").unwrap(), Some("you@yourself.com".to_string()));