Function mailparse::parse_content_type
[−]
[src]
pub fn parse_content_type(header: &str) -> ParsedContentType
Helper method to parse a header value as a Content-Type header. Note that
the returned object's params
map will contain a charset key if a charset
was explicitly specified in the header; otherwise the params
map will not
contain a charset key. Regardless, the charset
field will contain a
charset - either the one explicitly specified or the default of "us-ascii".
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()); assert_eq!(ctype.mimetype, "text/html"); assert_eq!(ctype.charset, "foo"); assert_eq!(ctype.params.get("boundary"), Some(&"quotes_are_removed".to_string())); assert_eq!(ctype.params.get("charset"), Some(&"foo".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()); assert_eq!(ctype.mimetype, "bogus"); assert_eq!(ctype.charset, "us-ascii"); assert_eq!(ctype.params.get("boundary"), None); assert_eq!(ctype.params.get("charset"), None);
use mailparse::{parse_header, parse_content_type}; let (parsed, _) = parse_header(br#"Content-Type: application/octet-stream;name="=?utf8?B?6L+O5ai255m95a+M576O?=";charset="utf8""#).unwrap(); let ctype = parse_content_type(&parsed.get_value().unwrap()); assert_eq!(ctype.mimetype, "application/octet-stream"); assert_eq!(ctype.charset, "utf8"); assert_eq!(ctype.params.get("boundary"), None); assert_eq!(ctype.params.get("name"), Some(&"迎娶白富美".to_string()));