diff --git a/src/components/mail/listing.rs b/src/components/mail/listing.rs index 5b94271d..84ab04d5 100644 --- a/src/components/mail/listing.rs +++ b/src/components/mail/listing.rs @@ -576,19 +576,9 @@ impl Component for Listing { { /* Account might have no mailboxes yet if it's offline */ /* Check if per-mailbox configuration overrides general configuration */ - if let Some(index_style) = context - .accounts - .get(self.cursor_pos.0) - .and_then(|account| account[mailbox_hash].conf.conf_override.index_style) - { - self.component.set_style(index_style); - } else if let Some(index_style) = context - .accounts - .get(self.cursor_pos.0) - .and_then(|account| Some(account.settings.conf.index_style())) - { - self.component.set_style(index_style); - } + let index_style = + mailbox_acc_settings!(context[self.cursor_pos.0][mailbox_hash].index_style); + self.component.set_style(*index_style); } context .replies @@ -1208,19 +1198,10 @@ impl Listing { self.component .set_coordinates((self.cursor_pos.0, *mailbox_hash)); /* Check if per-mailbox configuration overrides general configuration */ - if let Some(index_style) = context - .accounts - .get(self.cursor_pos.0) - .and_then(|account| account[mailbox_hash].conf.conf_override.index_style) - { - self.component.set_style(index_style); - } else if let Some(index_style) = context - .accounts - .get(self.cursor_pos.0) - .and_then(|account| Some(account.settings.conf.index_style())) - { - self.component.set_style(index_style); - } + + let index_style = + mailbox_acc_settings!(context[self.cursor_pos.0][mailbox_hash].index_style); + self.component.set_style(*index_style); } else { /* Set to dummy */ self.component = Offline(OfflineListing::new((self.cursor_pos.0, 0))); diff --git a/src/components/mail/listing/compact.rs b/src/components/mail/listing/compact.rs index 8ef30776..2aa5c664 100644 --- a/src/components/mail/listing/compact.rs +++ b/src/components/mail/listing/compact.rs @@ -760,8 +760,12 @@ impl CompactListing { let root_envelope: EnvelopeRef = context.accounts[self.cursor_pos.0] .collection .get_env(root_env_hash); - use crate::cache::{Query, QueryTrait}; - if let Some(filter_query) = context.settings.listing.filter.as_ref() { + use crate::cache::QueryTrait; + if let Some(filter_query) = + mailbox_settings!(context[self.cursor_pos.0][&self.cursor_pos.1].listing) + .filter + .as_ref() + { if !root_envelope.is_match(filter_query) { continue; } diff --git a/src/components/mail/listing/conversations.rs b/src/components/mail/listing/conversations.rs index ef270836..53487ccf 100644 --- a/src/components/mail/listing/conversations.rs +++ b/src/components/mail/listing/conversations.rs @@ -593,32 +593,20 @@ impl ConversationsListing { hash: ThreadHash, ) -> EntryStrings { let thread = threads.thread_ref(hash); - let mailbox = &context.accounts[self.cursor_pos.0][&self.cursor_pos.1].conf; + let settings = mailbox_settings!(context[self.cursor_pos.0][&self.cursor_pos.1].tags); let mut tags = String::new(); let mut colors = SmallVec::new(); let backend_lck = context.accounts[self.cursor_pos.0].backend.read().unwrap(); if let Some(t) = backend_lck.tags() { let tags_lck = t.read().unwrap(); for t in e.labels().iter() { - if mailbox - .conf_override - .tags - .as_ref() - .map(|s| s.ignore_tags.contains(t)) - .unwrap_or(false) - { + if settings.ignore_tags.contains(t) { continue; } tags.push(' '); tags.push_str(tags_lck.get(t).as_ref().unwrap()); tags.push(' '); - if let Some(&c) = mailbox - .conf_override - .tags - .as_ref() - .map(|s| s.colors.get(t)) - .unwrap_or(None) - { + if let Some(&c) = settings.colors.get(t) { colors.push(c); } else { colors.push(Color::Byte(8)); @@ -670,8 +658,7 @@ impl ConversationsListing { let mut from_address_list = Vec::new(); let mut from_address_set: std::collections::HashSet> = std::collections::HashSet::new(); - for (idx, thread) in items.enumerate() { - self.length += 1; + for thread in items { let thread_node = &threads.thread_nodes()[&threads.thread_ref(thread).root()]; let root_env_hash = thread_node.message().unwrap_or_else(|| { let mut iter_ptr = thread_node.children()[0]; @@ -710,6 +697,16 @@ impl ConversationsListing { let root_envelope: &EnvelopeRef = &context.accounts[self.cursor_pos.0] .collection .get_env(root_env_hash); + use crate::cache::QueryTrait; + if let Some(filter_query) = + mailbox_settings!(context[self.cursor_pos.0][&self.cursor_pos.1].listing) + .filter + .as_ref() + { + if !root_envelope.is_match(filter_query) { + continue; + } + } let strings = self.make_entry_string(root_envelope, context, &from_address_list, threads, thread); @@ -725,11 +722,12 @@ impl ConversationsListing { max_entry_columns, strings.date.len() + 1 + strings.from.grapheme_width(), ); - rows.push(((idx, (thread, root_env_hash)), strings)); + rows.push(((self.length, (thread, root_env_hash)), strings)); self.all_threads.insert(thread); - self.order.insert(thread, idx); + self.order.insert(thread, self.length); self.selection.insert(thread, false); + self.length += 1; } let width = max_entry_columns; diff --git a/src/components/mail/listing/plain.rs b/src/components/mail/listing/plain.rs index cffc7c35..1e796fd4 100644 --- a/src/components/mail/listing/plain.rs +++ b/src/components/mail/listing/plain.rs @@ -613,32 +613,20 @@ impl PlainListing { } } fn make_entry_string(&self, e: EnvelopeRef, context: &Context) -> EntryStrings { - let mailbox = &context.accounts[self.cursor_pos.0][&self.cursor_pos.1].conf; + let settings = mailbox_settings!(context[self.cursor_pos.0][&self.cursor_pos.1].tags); let mut tags = String::new(); let mut colors = SmallVec::new(); let backend_lck = context.accounts[self.cursor_pos.0].backend.read().unwrap(); if let Some(t) = backend_lck.tags() { let tags_lck = t.read().unwrap(); for t in e.labels().iter() { - if mailbox - .conf_override - .tags - .as_ref() - .map(|s| s.ignore_tags.contains(t)) - .unwrap_or(false) - { + if settings.ignore_tags.contains(t) { continue; } tags.push(' '); tags.push_str(tags_lck.get(t).as_ref().unwrap()); tags.push(' '); - if let Some(&c) = mailbox - .conf_override - .tags - .as_ref() - .map(|s| s.colors.get(t)) - .unwrap_or(None) - { + if let Some(&c) = settings.colors.get(t) { colors.push(c); } else { colors.push(Color::Byte(8)); @@ -703,8 +691,7 @@ impl PlainListing { Box::new(self.filtered_selection.iter().map(|h| *h)) as Box> }; - for (idx, i) in iter.enumerate() { - self.length += 1; + for i in iter { if !context.accounts[self.cursor_pos.0].contains_key(i) { debug!("key = {}", i); debug!( @@ -717,6 +704,16 @@ impl PlainListing { panic!(); } let envelope: EnvelopeRef = context.accounts[self.cursor_pos.0].collection.get_env(i); + use crate::cache::QueryTrait; + if let Some(filter_query) = + mailbox_settings!(context[self.cursor_pos.0][&self.cursor_pos.1].listing) + .filter + .as_ref() + { + if !envelope.is_match(filter_query) { + continue; + } + } let entry_strings = self.make_entry_string(envelope, context); min_width.1 = cmp::max(min_width.1, entry_strings.date.grapheme_width()); /* date */ @@ -731,8 +728,9 @@ impl PlainListing { self.all_envelopes.insert(i); } - self.order.insert(i, idx); + self.order.insert(i, self.length); self.selection.insert(i, false); + self.length += 1; } min_width.0 = self.length.saturating_sub(1).to_string().len(); diff --git a/src/components/mail/view.rs b/src/components/mail/view.rs index 3813acd0..00764a78 100644 --- a/src/components/mail/view.rs +++ b/src/components/mail/view.rs @@ -161,9 +161,10 @@ 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.settings; + let settings = + mailbox_settings!(context[self.coordinates.0][&self.coordinates.1].pager); /* FIXME: duplication with view/html.rs */ - if let Some(filter_invocation) = settings.pager.html_filter.as_ref() { + if let Some(filter_invocation) = settings.html_filter.as_ref() { let parts = split_command!(filter_invocation); let (cmd, args) = (parts[0], &parts[1..]); let command_obj = Command::new(cmd) @@ -399,7 +400,10 @@ impl Component for MailView { self.headers_no = 0; let mut skip_header_ctr = self.headers_cursor; - let sticky = context.settings.pager.headers_sticky || height_p < height; + let sticky = + mailbox_settings!(context[self.coordinates.0][&self.coordinates.1].pager) + .headers_sticky + || height_p < height; let (_, mut y) = upper_left; macro_rules! print_header { ($($string:expr)+) => { @@ -569,7 +573,9 @@ impl Component for MailView { context .dirty_areas .push_back((upper_left, set_y(bottom_right, y + 3))); - if !context.settings.pager.headers_sticky { + if !mailbox_settings!(context[self.coordinates.0][&self.coordinates.1].pager) + .headers_sticky + { let height_p = self.pager.size().1; let height = height!(area).saturating_sub(y).saturating_sub(1); @@ -637,11 +643,11 @@ impl Component for MailView { self.initialised = false; } ViewMode::Normal - if context - .settings - .pager - .auto_choose_multipart_alternative - .is_true() + if mailbox_settings!( + context[self.coordinates.0][&self.coordinates.1].pager + ) + .auto_choose_multipart_alternative + .is_true() && match body.content_type { ContentType::Multipart { kind: MultipartType::Alternative, @@ -807,7 +813,10 @@ impl Component for MailView { _ => match event { UIEvent::Input(ref key) if shortcut!(key == shortcuts[Pager::DESCRIPTION]["scroll_up"]) - && !context.settings.pager.headers_sticky + && !mailbox_settings!( + context[self.coordinates.0][&self.coordinates.1].pager + ) + .headers_sticky && self.headers_cursor <= self.headers_no => { self.force_draw_headers = true; @@ -823,7 +832,10 @@ impl Component for MailView { } UIEvent::Input(ref key) if shortcut!(key == shortcuts[Pager::DESCRIPTION]["scroll_down"]) - && !context.settings.pager.headers_sticky + && !mailbox_settings!( + context[self.coordinates.0][&self.coordinates.1].pager + ) + .headers_sticky && self.headers_cursor < self.headers_no => { self.force_draw_headers = true; diff --git a/src/conf.rs b/src/conf.rs index d0f077b7..3d0ff0d3 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -70,6 +70,29 @@ macro_rules! split_command { }}; } +#[macro_export] +macro_rules! mailbox_acc_settings { + ($context:ident[$account_idx:expr][$mailbox_path:expr].$field:ident) => {{ + $context.accounts[$account_idx][$mailbox_path] + .conf + .conf_override + .$field + .as_ref() + .unwrap_or(&$context.accounts[$account_idx].settings.conf.$field) + }}; +} +#[macro_export] +macro_rules! mailbox_settings { + ($context:ident[$account_idx:expr][$mailbox_path:expr].$field:ident) => {{ + $context.accounts[$account_idx][$mailbox_path] + .conf + .conf_override + .$field + .as_ref() + .unwrap_or(&$context.settings.$field) + }}; +} + #[derive(Default, Debug, Clone, Serialize, Deserialize)] pub struct MailUIConf { pub pager: Option, @@ -110,7 +133,7 @@ pub struct FileAccount { identity: String, #[serde(default = "none")] display_name: Option, - index_style: IndexStyle, + pub index_style: IndexStyle, #[serde(default = "false_val")] read_only: bool,