ui: fix `editing messages duplicates headers`

closes #94
embed
Manos Pitsidianakis 2019-04-06 08:57:00 +03:00
parent d9a3b03e2b
commit a29e39f5ef
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
1 changed files with 8 additions and 5 deletions

View File

@ -14,8 +14,6 @@ use fnv::FnvHashMap;
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub struct Draft { pub struct Draft {
// FIXME: Preserve header order
// FIXME: Validate headers, allow custom ones
headers: FnvHashMap<String, String>, headers: FnvHashMap<String, String>,
header_order: Vec<String>, header_order: Vec<String>,
body: String, body: String,
@ -97,9 +95,13 @@ impl Draft {
//TODO: Inform user if error //TODO: Inform user if error
{ {
let bytes = op.as_bytes().unwrap_or(&[]); let bytes = op.as_bytes().unwrap_or(&[]);
for (h, v) in envelope.headers(bytes).unwrap_or_else(|_| Vec::new()) { for (k, v) in envelope.headers(bytes).unwrap_or_else(|_| Vec::new()) {
ret.header_order.push(h.into()); if ignore_header(k.as_bytes()) {
ret.headers_mut().insert(h.into(), v.into()); continue;
}
if ret.headers.insert(k.into(), v.into()).is_none() {
ret.header_order.push(k.into());
}
} }
} }
@ -226,6 +228,7 @@ fn ignore_header(header: &[u8]) -> bool {
b"Bcc" => false, b"Bcc" => false,
b"In-Reply-To" => false, b"In-Reply-To" => false,
b"References" => false, b"References" => false,
b"MIME-Version" => true,
h if h.starts_with(b"X-") => false, h if h.starts_with(b"X-") => false,
_ => true, _ => true,
} }