Function mailparse::parse_content_type
[−]
[src]
pub fn parse_content_type(header: &str)
-> Result<ParsedContentType, MailParseError>
Helper method to parse a header value as a Content-Type header. The charset defaults to "us-ascii" if no charset parameter is provided in the header value.
Examples
use mailparse::{parse_header, parse_content_type};
let (parsed, _) = parse_header(
b"Content-Type: text/html; charset=foo; boundary=\"quotes_are_removed\"")
.unwrap();
let ctype = parse_content_type(&parsed.get_value().unwrap()).unwrap();
assert_eq!(ctype.mimetype, "text/html");
assert_eq!(ctype.charset, "foo");
assert_eq!(ctype.boundary, Some("quotes_are_removed".to_string()));
use mailparse::{parse_header, parse_content_type};
let (parsed, _) = parse_header(b"Content-Type: bogus").unwrap();
let ctype = parse_content_type(&parsed.get_value().unwrap()).unwrap();
assert_eq!(ctype.mimetype, "bogus");
assert_eq!(ctype.charset, "us-ascii");
assert_eq!(ctype.boundary, None);