diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2022-09-11 01:11:33 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2022-09-11 01:22:06 +0300 |
commit | 9cbbf71e0f8f9115e9e043982f20045cfc550eb7 (patch) | |
tree | 7e66ef86427b2f4f506aa132646486b81843266d /src | |
parent | 36883692782ed2355a0ec12ccf9f82aa2edcc8c1 (diff) | |
download | meli-9cbbf71e0f8f9115e9e043982f20045cfc550eb7.zip |
melib/email/attachments: Add DecodeOptions struct for decoding
Diffstat (limited to 'src')
-rw-r--r-- | src/components/mail/view.rs | 10 | ||||
-rw-r--r-- | src/components/mail/view/envelope.rs | 13 | ||||
-rw-r--r-- | src/components/mail/view/html.rs | 2 | ||||
-rw-r--r-- | src/mailcap.rs | 16 | ||||
-rw-r--r-- | src/terminal/color.rs | 2 |
5 files changed, 26 insertions, 17 deletions
diff --git a/src/components/mail/view.rs b/src/components/mail/view.rs index 47641095..f4677629 100644 --- a/src/components/mail/view.rs +++ b/src/components/mail/view.rs @@ -733,7 +733,7 @@ impl MailView { inner: Box::new(a.clone()), }); } else if a.content_type().is_text_html() { - let bytes = decode(a, None); + let bytes = a.decode(Default::default()); let filter_invocation = mailbox_settings!(context[coordinates.0][&coordinates.1].pager.html_filter) .as_ref() @@ -788,7 +788,7 @@ impl MailView { } } } else if a.is_text() { - let bytes = decode(a, None); + let bytes = a.decode(Default::default()); acc.push(AttachmentDisplay::InlineText { inner: Box::new(a.clone()), comment: None, @@ -810,7 +810,7 @@ impl MailView { if let Some(text_attachment_pos) = parts.iter().position(|a| a.content_type == "text/plain") { - let bytes = decode(&parts[text_attachment_pos], None); + let bytes = &parts[text_attachment_pos].decode(Default::default()); if bytes.trim().is_empty() && mailbox_settings!( context[coordinates.0][&coordinates.1] @@ -2211,7 +2211,7 @@ impl Component for MailView { let filename = attachment.filename(); if let Ok(command) = query_default_app(&attachment_type) { let p = create_temp_file( - &decode(attachment, None), + &attachment.decode(Default::default()), filename.as_deref(), None, true, @@ -2466,7 +2466,7 @@ impl Component for MailView { path.push(u.as_hyphenated().to_string()); } } - match save_attachment(&path, &decode(u, None)) { + match save_attachment(&path, &u.decode(Default::default())) { Err(err) => { context.replies.push_back(UIEvent::Notification( Some(format!("Failed to create file at {}", path.display())), diff --git a/src/components/mail/view/envelope.rs b/src/components/mail/view/envelope.rs index 2861c337..2f310558 100644 --- a/src/components/mail/view/envelope.rs +++ b/src/components/mail/view/envelope.rs @@ -83,9 +83,8 @@ impl EnvelopeView { /// Returns the string to be displayed in the Viewer fn attachment_to_text(&self, body: &Attachment, context: &mut Context) -> String { let finder = LinkFinder::new(); - let body_text = String::from_utf8_lossy(&decode_rec( - body, - Some(Box::new(|a: &Attachment, v: &mut Vec<u8>| { + let body_text = String::from_utf8_lossy(&body.decode_rec(DecodeOptions { + filter: Some(Box::new(|a: &Attachment, v: &mut Vec<u8>| { if a.content_type().is_text_html() { let settings = &context.settings; if let Some(filter_invocation) = settings.pager.html_filter.as_ref() { @@ -123,7 +122,8 @@ impl EnvelopeView { } } })), - )) + ..Default::default() + })) .into_owned(); match self.mode { ViewMode::Normal | ViewMode::Subview => { @@ -370,7 +370,8 @@ impl Component for EnvelopeView { self.mode = ViewMode::Subview; let colors = crate::conf::value(context, "mail.view.body"); self.subview = Some(Box::new(Pager::from_string( - String::from_utf8_lossy(&decode_rec(u, None)).to_string(), + String::from_utf8_lossy(&u.decode_rec(Default::default())) + .to_string(), Some(context), None, None, @@ -397,7 +398,7 @@ impl Component for EnvelopeView { let filename = u.filename(); if let Ok(command) = query_default_app(&attachment_type) { let p = create_temp_file( - &decode(u, None), + &u.decode(Default::default()), filename.as_deref(), None, true, diff --git a/src/components/mail/view/html.rs b/src/components/mail/view/html.rs index 873d0cae..fe72a040 100644 --- a/src/components/mail/view/html.rs +++ b/src/components/mail/view/html.rs @@ -33,7 +33,7 @@ pub struct HtmlView { impl HtmlView { pub fn new(body: &Attachment, context: &mut Context) -> Self { let id = ComponentId::new_v4(); - let bytes: Vec<u8> = decode_rec(body, None); + let bytes: Vec<u8> = body.decode_rec(Default::default()); let settings = &context.settings; let mut display_text = if let Some(filter_invocation) = settings.pager.html_filter.as_ref() diff --git a/src/mailcap.rs b/src/mailcap.rs index 7ff0e824..0cc566a3 100644 --- a/src/mailcap.rs +++ b/src/mailcap.rs @@ -23,7 +23,6 @@ */ use crate::state::Context; use crate::types::{create_temp_file, ForkType, UIEvent}; -use melib::attachments::decode; use melib::text_processing::GlobMatch; use melib::{email::Attachment, MeliError, Result}; use std::collections::HashMap; @@ -159,7 +158,8 @@ impl MailcapEntry { .map(|arg| match *arg { "%s" => { needs_stdin = false; - let _f = create_temp_file(&decode(a, None), None, None, true); + let _f = + create_temp_file(&a.decode(Default::default()), None, None, true); let p = _f.path().display().to_string(); f = Some(_f); p @@ -191,7 +191,11 @@ impl MailcapEntry { .stdout(Stdio::piped()) .spawn()?; - child.stdin.as_mut().unwrap().write_all(&decode(a, None))?; + child + .stdin + .as_mut() + .unwrap() + .write_all(&a.decode(Default::default()))?; child.wait_with_output()?.stdout } else { let child = Command::new("sh") @@ -221,7 +225,11 @@ impl MailcapEntry { .stdout(Stdio::inherit()) .spawn()?; - child.stdin.as_mut().unwrap().write_all(&decode(a, None))?; + child + .stdin + .as_mut() + .unwrap() + .write_all(&a.decode(Default::default()))?; debug!(child.wait_with_output()?.stdout); } else { let child = Command::new("sh") diff --git a/src/terminal/color.rs b/src/terminal/color.rs index 6c915e4f..37cdf67d 100644 --- a/src/terminal/color.rs +++ b/src/terminal/color.rs @@ -34,7 +34,7 @@ use termion::color::{AnsiValue, Rgb as TermionRgb}; /// /// # Examples /// -/// ``` +/// ```no_run /// use meli::Color; /// /// // The default color. |