[][src]Function mailparse::parse_header

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

Parse a single header from the raw data given. This function takes raw byte data, and starts parsing it, expecting there to be a MIME header key-value pair right at the beginning. It parses that header and returns it, along with the index at which the next header is expected to start. If you just want to parse a single header, you can ignore the second component of the tuple, which is the index of the next header. Error values are returned if the data could not be successfully interpreted as a MIME key-value pair.

Examples

    use mailparse::parse_header;
    let (parsed, _) = parse_header(concat!(
            "Subject: Hello, sir,\n",
            "   I am multiline\n",
            "Next:Header").as_bytes())
        .unwrap();
    assert_eq!(parsed.get_key().unwrap(), "Subject");
    assert_eq!(parsed.get_value().unwrap(), "Hello, sir, I am multiline");