Browse Source

conf: move html_filter to PagerSettings

html_filter was in Account settings, but it makes more sense for it to
be in PagerSettings
embed
Manos Pitsidianakis 2 years ago
parent
commit
9a3b9b1409
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 7
      meli.conf.5
  2. 13
      ui/src/components/mail/view.rs
  3. 12
      ui/src/components/mail/view/envelope.rs
  4. 7
      ui/src/components/mail/view/html.rs
  5. 38
      ui/src/conf.rs
  6. 8
      ui/src/conf/pager.rs

7
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 <email@address.tld>"
.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

13
ui/src/components/mail/view.rs

@ -134,9 +134,9 @@ impl MailView {
Some(Box::new(move |a: &'closure Attachment, v: &mut Vec<u8>| {
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;
}

12
ui/src/components/mail/view/envelope.rs

@ -96,8 +96,8 @@ impl EnvelopeView {
Some(Box::new(|a: &Attachment, v: &mut Vec<u8>| {
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;
}
_ => {

7
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<u8> = 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)

38
ui/src/conf.rs

@ -157,11 +157,6 @@ pub struct FileAccount {
display_name: Option<String>,
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<String>,
#[serde(default = "false_val")]
read_only: bool,
subscribed_folders: Vec<String>,
@ -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<Option<String>, D::Error>
where
D: Deserializer<'de>,
{
let s = <String>::deserialize(deserializer)?;
if s.is_empty() {
Ok(None)
} else {
Ok(Some(s))
}
}
fn toggleflag_de<'de, D>(deserializer: D) -> std::result::Result<ToggleFlag, D::Error>
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<Option<String>, D::Error>
where
D: Deserializer<'de>,
{
let s = <String>::deserialize(deserializer)?;
if s.is_empty() {
Ok(None)
} else {
Ok(Some(s))
}
}
}
impl<'de> Deserialize<'de> for IndexStyle {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where

8
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<String>,
/// 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<String>,
/// Respect "format=flowed"
/// Default: true
#[serde(default = "true_val")]

Loading…
Cancel
Save