summaryrefslogtreecommitdiffstats
path: root/melib/src/email/compose/mime.rs
blob: b01eb7c6185b26a638a082dd7ee45e08abbe8d69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use super::*;

pub fn encode_header(value: &str) -> String {
    eprintln!("encoding \"{}\"", value);
    let mut ret = String::with_capacity(5 / 3 * value.len());
    for word in value.split_whitespace() {
        if word.is_ascii() {
            ret.push_str(word);
        } else {
            ret.push_str(
                format!("=?UTF-8?B?{}?=", BASE64_MIME.encode(word.as_bytes()).trim()).as_str(),
            );
        }
        ret.push(' ');
    }
    ret.pop();
    ret
}