pub fn parse_headers(raw_data: &[u8]) -> Result<(Vec<MailHeader>, usize), MailParseError> {
    let mut headers: Vec<MailHeader> = Vec::new();
    let mut ix = 0;
    loop {
        if ix >= raw_data.len() {
            break;
        } else if raw_data[ix] == b'\n' {
            ix += 1;
            break;
        } else if raw_data[ix] == b'\r' {
            if ix + 1 < raw_data.len() && raw_data[ix + 1] == b'\n' {
                ix += 2;
                break;
            } else {
                return Err(MailParseError::Generic(
                    "Headers were followed by an unexpected lone \
                     CR character!",
                ));
            }
        }
        let (header, ix_next) = parse_header(&raw_data[ix..])?;
        headers.push(header);
        ix += ix_next;
    }
    Ok((headers, ix))
}
/// 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(), "From");
///     assert_eq!(headers.get_first_value("To"), Some("you@yourself.com".to_string()));
/// ```
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 . 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.
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 . 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 .
pub fn parse_headers(raw_data: &[u8]) -> Result<(Vec<MailHeader>, usize), MailParseError> {
    let mut headers: Vec<MailHeader> = Vec::new();
    let mut ix = 0;
    loop {
        if ix >= raw_data.len() {
            break;
        } else if raw_data[ix] == b'\n' {
            ix += 1;
            break;
        } else if raw_data[ix] == b'\r' {
            if ix + 1 < raw_data.len() && raw_data[ix + 1] == b'\n' {
                ix += 2;
                break;
            } else {
                return Err(MailParseError::Generic(
                    "Headers were followed by an unexpected lone \
                     CR character!",
                ));
            }
        }
        let (header, ix_next) = parse_header(&raw_data[ix..])?;
        headers.push(header);
        ix += ix_next;
    }
    Ok((headers, ix))
}
pub fn parse_headers ( raw_data : & [ u8 ] ) -> Result < ( Vec < MailHeader > , usize ) , MailParseError > { let mut headers : Vec < MailHeader > = Vec :: new ( ) ; let mut ix = 0 ; loop { if ix >= raw_data . len ( ) { break ; } else if raw_data [ ix ] == b'\n' { ix += 1 ; break ; } else if raw_data [ ix ] == b'\r' { if ix + 1 < raw_data . len ( ) && raw_data [ ix + 1 ] == b'\n' { ix += 2 ; break ; } else { return Err ( MailParseError :: Generic ( " \
 " , ) ) ; } } let ( header , ix_next ) = parse_header ( & raw_data [ ix .. ] ) ? ; headers . push ( header ) ; ix += ix_next ; } Ok ( ( headers , ix ) ) }
Parses all the headers from the raw data given.
Parses all the headers from the raw data given .
raw_data
&[u8]
raw_data
&[u8]
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(), "From");
assert_eq!(headers.get_first_value("To"), Some("you@yourself.com".to_string()));
```
` ` ` 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 () " From " ) ; assert_eq! ( headers . get_first_value ( " To " ) Some ( " you@yourself . com " . to_string () )) ; ` ` `