diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-09-27 22:21:35 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-09-27 22:21:35 +0300 |
commit | 250129665b0a74d0946cbfd39d3dcc36e62a67d4 (patch) | |
tree | af4ac292b3f801957bfa43ba6b1c07fd0b5974e1 | |
parent | 19ec6e54fcffdb896a95222bbd7132f2e505a073 (diff) |
Pass attachment names through decoding
Attachment names in Content-Type parameters can be encoded (eg
=?UTF-8...), so try decoding with phrase() first
-rw-r--r-- | melib/src/email/parser.rs | 2 | ||||
-rw-r--r-- | ui/src/components/mail/view.rs | 17 |
2 files changed, 12 insertions, 7 deletions
diff --git a/melib/src/email/parser.rs b/melib/src/email/parser.rs index 80828530..7ebfbd3b 100644 --- a/melib/src/email/parser.rs +++ b/melib/src/email/parser.rs @@ -787,6 +787,7 @@ named_args!(pub parts<'a>(boundary: &'a [u8]) < Vec<&'this_is_probably_unique_i_ ( { Vec::<&[u8]>::new() } )) )); +/* Caution: values should be passed through phrase() */ named!( content_type_parameter<(&[u8], &[u8])>, do_parse!( @@ -1190,5 +1191,4 @@ mod tests { } } } - } diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index 529d8799..8a8e7c5f 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -875,13 +875,18 @@ impl Component for MailView { ContentType::Other { ref name, .. } => { let attachment_type = u.mime_type(); let binary = query_default_app(&attachment_type); + let mut name_opt = name.as_ref().and_then(|n| { + melib::email::parser::phrase(n.as_bytes()) + .to_full_result() + .ok() + .and_then(|n| String::from_utf8(n).ok()) + }); + if name_opt.is_none() { + name_opt = name.as_ref().map(|n| n.clone()); + } if let Ok(binary) = binary { - let p = create_temp_file( - &decode(u, None), - name.as_ref().map(|n| n.clone()), - None, - true, - ); + let p = + create_temp_file(&decode(u, None), name_opt, None, true); Command::new(&binary) .arg(p.path()) .stdin(Stdio::piped()) |