Skip to main content

parse_mime_params

Function parse_mime_params 

Source
pub fn parse_mime_params<'a>(
    s: &'a [u8],
    limits: &Limits,
) -> Result<(MimeParams<'a>, usize), ParseError>
Expand description

Parses *( ";" attribute "=" value ) (RFC 2045 section 5.1) with the MIME token class, CFWS between the parts, and case-insensitive names, and validates every RFC 2231 extended value and continuation. Returns the parameters and the bytes used (parsing stops at the first byte that does not start another parameter).

§Errors

ErrorKind::NotToken, ErrorKind::MissingValue, ErrorKind::DuplicateParameter, ErrorKind::UnterminatedQuote, ErrorKind::TooManyMembers beyond max_params; for RFC 2231: ErrorKind::SectionGap, ErrorKind::TooManySections beyond max_rfc2231_sections, the ExtValue::parse errors (a charset outside section 0 is ErrorKind::InvalidPercentEncoding at its '), ErrorKind::InvalidUtf8, ErrorKind::ControlInDecoded; ErrorKind::UnbalancedComment, ErrorKind::CommentTooDeep.

§Examples

use parse_net::{mail, Limits};

let (p, used) = mail::parse_mime_params(b"; charset=\"utf-8\" (comment); format=flowed rest", &Limits::DEFAULT)?;
assert_eq!((p.len(), used), (2, 42));
let mut buf = [0u8; 8];
assert_eq!(p.decode_into("CHARSET", &mut buf)?, Some("utf-8"));