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);
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()).unwrap();
    assert_eq!(ctype.mimetype, "application/octet-stream");
    assert_eq!(ctype.charset, "utf8");
    assert_eq!(ctype.boundary, None);
    assert_eq!(ctype.name, Some("迎娶白富美".to_string()));