diff --git a/meli.conf.5 b/meli.conf.5 index 18c69693..7803c737 100644 --- a/meli.conf.5 +++ b/meli.conf.5 @@ -70,6 +70,7 @@ identity="username@hostname.local" [pager] filter = "/usr/bin/pygmentize" +html_filter = "w3m -I utf-8 -T text/html" [notifications] script = "notify-send" @@ -113,8 +114,6 @@ shows one row per thread .It Cm display_name Ar String (optional) a name which can be combined with your address: "Name " -.It Cm html_filter Ar String -(optional) pipe html attachments through this filter before display .It Cm read_only Ar boolean attempt to not make any changes to this account. .Pq Em false @@ -273,6 +272,10 @@ enable freedesktop-spec notifications. this is usually what you want (optional) always show headers when scrolling. .\" default value .Pq Em false +.It Cm html_filter Ar String +(optional) pipe html attachments through this filter before display +.\" default value +.Pq Em none .It Cm filter Ar String (optional) a command to pipe mail output through for viewing in pager. .\" default value diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index 3459703e..92a11cb9 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -134,9 +134,9 @@ impl MailView { Some(Box::new(move |a: &'closure Attachment, v: &mut Vec| { if a.content_type().is_text_html() { use std::io::Write; - let settings = context.accounts[self.coordinates.0].runtime_settings.conf(); + let settings = &context.settings; /* FIXME: duplication with view/html.rs */ - if let Some(filter_invocation) = settings.html_filter() { + if let Some(filter_invocation) = settings.pager.html_filter.as_ref() { let parts = split_command!(filter_invocation); let (cmd, args) = (parts[0], &parts[1..]); let command_obj = Command::new(cmd) @@ -576,16 +576,11 @@ impl Component for MailView { ViewMode::Attachment(aidx) if body.attachments()[aidx].is_html() => { self.pager = None; let attachment = &body.attachments()[aidx]; - self.subview = Some(Box::new(HtmlView::new( - &attachment, - context, - self.coordinates.0, - ))); + self.subview = Some(Box::new(HtmlView::new(&attachment, context))); self.mode = ViewMode::Subview; } ViewMode::Normal if body.is_html() => { - self.subview = - Some(Box::new(HtmlView::new(&body, context, self.coordinates.0))); + self.subview = Some(Box::new(HtmlView::new(&body, context))); self.pager = None; self.mode = ViewMode::Subview; } diff --git a/ui/src/components/mail/view/envelope.rs b/ui/src/components/mail/view/envelope.rs index d6fd8146..1cef8958 100644 --- a/ui/src/components/mail/view/envelope.rs +++ b/ui/src/components/mail/view/envelope.rs @@ -96,8 +96,8 @@ impl EnvelopeView { Some(Box::new(|a: &Attachment, v: &mut Vec| { if a.content_type().is_text_html() { use std::io::Write; - let settings = context.accounts[self.account_pos].runtime_settings.conf(); - if let Some(filter_invocation) = settings.html_filter() { + let settings = &context.settings; + if let Some(filter_invocation) = settings.pager.html_filter.as_ref() { let parts = split_command!(filter_invocation); let (cmd, args) = (parts[0], &parts[1..]); let command_obj = Command::new(cmd) @@ -319,14 +319,10 @@ impl Component for EnvelopeView { match self.mode { ViewMode::Attachment(aidx) if body.attachments()[aidx].is_html() => { let attachment = &body.attachments()[aidx]; - self.subview = Some(Box::new(HtmlView::new( - &attachment, - context, - self.account_pos, - ))); + self.subview = Some(Box::new(HtmlView::new(&attachment, context))); } ViewMode::Normal if body.is_html() => { - self.subview = Some(Box::new(HtmlView::new(&body, context, self.account_pos))); + self.subview = Some(Box::new(HtmlView::new(&body, context))); self.mode = ViewMode::Subview; } _ => { diff --git a/ui/src/components/mail/view/html.rs b/ui/src/components/mail/view/html.rs index 26666e78..fb37fecd 100644 --- a/ui/src/components/mail/view/html.rs +++ b/ui/src/components/mail/view/html.rs @@ -31,12 +31,13 @@ pub struct HtmlView { } impl HtmlView { - pub fn new(body: &Attachment, context: &mut Context, account_pos: usize) -> Self { + pub fn new(body: &Attachment, context: &mut Context) -> Self { let id = ComponentId::new_v4(); let bytes: Vec = decode_rec(body, None); - let settings = context.accounts[account_pos].runtime_settings.conf(); - let mut display_text = if let Some(filter_invocation) = settings.html_filter() { + let settings = &context.settings; + let mut display_text = if let Some(filter_invocation) = settings.pager.html_filter.as_ref() + { let parts = split_command!(filter_invocation); let (cmd, args) = (parts[0], &parts[1..]); let command_obj = Command::new(cmd) diff --git a/ui/src/conf.rs b/ui/src/conf.rs index 33af0ced..46e9d09c 100644 --- a/ui/src/conf.rs +++ b/ui/src/conf.rs @@ -157,11 +157,6 @@ pub struct FileAccount { display_name: Option, index_style: IndexStyle, - /// A command to pipe html output before displaying it in a pager - /// Default: None - #[serde(default = "none", deserialize_with = "non_empty_string")] - html_filter: Option, - #[serde(default = "false_val")] read_only: bool, subscribed_folders: Vec, @@ -268,10 +263,6 @@ impl FileAccount { pub fn index_style(&self) -> IndexStyle { self.index_style } - - pub fn html_filter(&self) -> Option<&str> { - self.html_filter.as_ref().map(String::as_str) - } } #[derive(Debug, Clone, Default, Serialize, Deserialize)] @@ -421,18 +412,6 @@ impl Default for IndexStyle { } } -fn non_empty_string<'de, D>(deserializer: D) -> std::result::Result, D::Error> -where - D: Deserializer<'de>, -{ - let s = ::deserialize(deserializer)?; - if s.is_empty() { - Ok(None) - } else { - Ok(Some(s)) - } -} - fn toggleflag_de<'de, D>(deserializer: D) -> std::result::Result where D: Deserializer<'de>, @@ -488,6 +467,23 @@ mod default_vals { } } +mod deserializers { + use serde::{Deserialize, Deserializer}; + pub(in crate::conf) fn non_empty_string<'de, D>( + deserializer: D, + ) -> std::result::Result, D::Error> + where + D: Deserializer<'de>, + { + let s = ::deserialize(deserializer)?; + if s.is_empty() { + Ok(None) + } else { + Ok(Some(s)) + } + } +} + impl<'de> Deserialize<'de> for IndexStyle { fn deserialize(deserializer: D) -> std::result::Result where diff --git a/ui/src/conf/pager.rs b/ui/src/conf/pager.rs index 1aa822f5..2773bd6a 100644 --- a/ui/src/conf/pager.rs +++ b/ui/src/conf/pager.rs @@ -20,6 +20,7 @@ */ use super::default_vals::*; +use super::deserializers::*; /// Settings for the pager function. #[derive(Debug, Deserialize, Clone, Default, Serialize)] pub struct PagerSettings { @@ -45,9 +46,14 @@ pub struct PagerSettings { /// A command to pipe mail output through for viewing in pager. /// Default: None - #[serde(default = "none")] + #[serde(default = "none", deserialize_with = "non_empty_string")] pub filter: Option, + /// A command to pipe html output before displaying it in a pager + /// Default: None + #[serde(default = "none", deserialize_with = "non_empty_string")] + pub html_filter: Option, + /// Respect "format=flowed" /// Default: true #[serde(default = "true_val")]