niax / rust-email

Implementation of MIME Messages for Rust
MIT License
63 stars 34 forks source link

Header lookup should be case insensitive #32

Open jugglerchris opened 8 years ago

jugglerchris commented 8 years ago

I think HeaderMap::get should be case insensitive, eg headers.get("Content-Transfer-Encoding") should still work if the actual header is spelled "Content-transfer-encoding". I guess I would go for ordered_headers having the original case and the headers HashMap storing lower-cased keys (translating whenever it's used).

Ophirr33 commented 7 years ago

If this is a blocker for anyone, you can get around it with the following:

fn get_header_case_insensitive<'a>(mime_message: &'a MimeMessage, target_header: &str) -> Option<&'a email::Header> {
    mime_message.headers.iter().find(|header| header.name.to_lowercase() == target_header.to_lowercase())
}