Add config overrides to mailbox filter
If per-folder config filter is defined, it overrides the app-wide filter.master
parent
c19b9ec181
commit
106dae3334
|
@ -576,19 +576,9 @@ impl Component for Listing {
|
||||||
{
|
{
|
||||||
/* Account might have no mailboxes yet if it's offline */
|
/* Account might have no mailboxes yet if it's offline */
|
||||||
/* Check if per-mailbox configuration overrides general configuration */
|
/* Check if per-mailbox configuration overrides general configuration */
|
||||||
if let Some(index_style) = context
|
let index_style =
|
||||||
.accounts
|
mailbox_acc_settings!(context[self.cursor_pos.0][mailbox_hash].index_style);
|
||||||
.get(self.cursor_pos.0)
|
self.component.set_style(*index_style);
|
||||||
.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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
context
|
context
|
||||||
.replies
|
.replies
|
||||||
|
@ -1208,19 +1198,10 @@ impl Listing {
|
||||||
self.component
|
self.component
|
||||||
.set_coordinates((self.cursor_pos.0, *mailbox_hash));
|
.set_coordinates((self.cursor_pos.0, *mailbox_hash));
|
||||||
/* Check if per-mailbox configuration overrides general configuration */
|
/* Check if per-mailbox configuration overrides general configuration */
|
||||||
if let Some(index_style) = context
|
|
||||||
.accounts
|
let index_style =
|
||||||
.get(self.cursor_pos.0)
|
mailbox_acc_settings!(context[self.cursor_pos.0][mailbox_hash].index_style);
|
||||||
.and_then(|account| account[mailbox_hash].conf.conf_override.index_style)
|
self.component.set_style(*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);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/* Set to dummy */
|
/* Set to dummy */
|
||||||
self.component = Offline(OfflineListing::new((self.cursor_pos.0, 0)));
|
self.component = Offline(OfflineListing::new((self.cursor_pos.0, 0)));
|
||||||
|
|
|
@ -760,8 +760,12 @@ impl CompactListing {
|
||||||
let root_envelope: EnvelopeRef = context.accounts[self.cursor_pos.0]
|
let root_envelope: EnvelopeRef = context.accounts[self.cursor_pos.0]
|
||||||
.collection
|
.collection
|
||||||
.get_env(root_env_hash);
|
.get_env(root_env_hash);
|
||||||
use crate::cache::{Query, QueryTrait};
|
use crate::cache::QueryTrait;
|
||||||
if let Some(filter_query) = context.settings.listing.filter.as_ref() {
|
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) {
|
if !root_envelope.is_match(filter_query) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -593,32 +593,20 @@ impl ConversationsListing {
|
||||||
hash: ThreadHash,
|
hash: ThreadHash,
|
||||||
) -> EntryStrings {
|
) -> EntryStrings {
|
||||||
let thread = threads.thread_ref(hash);
|
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 tags = String::new();
|
||||||
let mut colors = SmallVec::new();
|
let mut colors = SmallVec::new();
|
||||||
let backend_lck = context.accounts[self.cursor_pos.0].backend.read().unwrap();
|
let backend_lck = context.accounts[self.cursor_pos.0].backend.read().unwrap();
|
||||||
if let Some(t) = backend_lck.tags() {
|
if let Some(t) = backend_lck.tags() {
|
||||||
let tags_lck = t.read().unwrap();
|
let tags_lck = t.read().unwrap();
|
||||||
for t in e.labels().iter() {
|
for t in e.labels().iter() {
|
||||||
if mailbox
|
if settings.ignore_tags.contains(t) {
|
||||||
.conf_override
|
|
||||||
.tags
|
|
||||||
.as_ref()
|
|
||||||
.map(|s| s.ignore_tags.contains(t))
|
|
||||||
.unwrap_or(false)
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tags.push(' ');
|
tags.push(' ');
|
||||||
tags.push_str(tags_lck.get(t).as_ref().unwrap());
|
tags.push_str(tags_lck.get(t).as_ref().unwrap());
|
||||||
tags.push(' ');
|
tags.push(' ');
|
||||||
if let Some(&c) = mailbox
|
if let Some(&c) = settings.colors.get(t) {
|
||||||
.conf_override
|
|
||||||
.tags
|
|
||||||
.as_ref()
|
|
||||||
.map(|s| s.colors.get(t))
|
|
||||||
.unwrap_or(None)
|
|
||||||
{
|
|
||||||
colors.push(c);
|
colors.push(c);
|
||||||
} else {
|
} else {
|
||||||
colors.push(Color::Byte(8));
|
colors.push(Color::Byte(8));
|
||||||
|
@ -670,8 +658,7 @@ impl ConversationsListing {
|
||||||
let mut from_address_list = Vec::new();
|
let mut from_address_list = Vec::new();
|
||||||
let mut from_address_set: std::collections::HashSet<Vec<u8>> =
|
let mut from_address_set: std::collections::HashSet<Vec<u8>> =
|
||||||
std::collections::HashSet::new();
|
std::collections::HashSet::new();
|
||||||
for (idx, thread) in items.enumerate() {
|
for thread in items {
|
||||||
self.length += 1;
|
|
||||||
let thread_node = &threads.thread_nodes()[&threads.thread_ref(thread).root()];
|
let thread_node = &threads.thread_nodes()[&threads.thread_ref(thread).root()];
|
||||||
let root_env_hash = thread_node.message().unwrap_or_else(|| {
|
let root_env_hash = thread_node.message().unwrap_or_else(|| {
|
||||||
let mut iter_ptr = thread_node.children()[0];
|
let mut iter_ptr = thread_node.children()[0];
|
||||||
|
@ -710,6 +697,16 @@ impl ConversationsListing {
|
||||||
let root_envelope: &EnvelopeRef = &context.accounts[self.cursor_pos.0]
|
let root_envelope: &EnvelopeRef = &context.accounts[self.cursor_pos.0]
|
||||||
.collection
|
.collection
|
||||||
.get_env(root_env_hash);
|
.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 =
|
let strings =
|
||||||
self.make_entry_string(root_envelope, context, &from_address_list, threads, thread);
|
self.make_entry_string(root_envelope, context, &from_address_list, threads, thread);
|
||||||
|
@ -725,11 +722,12 @@ impl ConversationsListing {
|
||||||
max_entry_columns,
|
max_entry_columns,
|
||||||
strings.date.len() + 1 + strings.from.grapheme_width(),
|
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.all_threads.insert(thread);
|
||||||
|
|
||||||
self.order.insert(thread, idx);
|
self.order.insert(thread, self.length);
|
||||||
self.selection.insert(thread, false);
|
self.selection.insert(thread, false);
|
||||||
|
self.length += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let width = max_entry_columns;
|
let width = max_entry_columns;
|
||||||
|
|
|
@ -613,32 +613,20 @@ impl PlainListing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn make_entry_string(&self, e: EnvelopeRef, context: &Context) -> EntryStrings {
|
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 tags = String::new();
|
||||||
let mut colors = SmallVec::new();
|
let mut colors = SmallVec::new();
|
||||||
let backend_lck = context.accounts[self.cursor_pos.0].backend.read().unwrap();
|
let backend_lck = context.accounts[self.cursor_pos.0].backend.read().unwrap();
|
||||||
if let Some(t) = backend_lck.tags() {
|
if let Some(t) = backend_lck.tags() {
|
||||||
let tags_lck = t.read().unwrap();
|
let tags_lck = t.read().unwrap();
|
||||||
for t in e.labels().iter() {
|
for t in e.labels().iter() {
|
||||||
if mailbox
|
if settings.ignore_tags.contains(t) {
|
||||||
.conf_override
|
|
||||||
.tags
|
|
||||||
.as_ref()
|
|
||||||
.map(|s| s.ignore_tags.contains(t))
|
|
||||||
.unwrap_or(false)
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tags.push(' ');
|
tags.push(' ');
|
||||||
tags.push_str(tags_lck.get(t).as_ref().unwrap());
|
tags.push_str(tags_lck.get(t).as_ref().unwrap());
|
||||||
tags.push(' ');
|
tags.push(' ');
|
||||||
if let Some(&c) = mailbox
|
if let Some(&c) = settings.colors.get(t) {
|
||||||
.conf_override
|
|
||||||
.tags
|
|
||||||
.as_ref()
|
|
||||||
.map(|s| s.colors.get(t))
|
|
||||||
.unwrap_or(None)
|
|
||||||
{
|
|
||||||
colors.push(c);
|
colors.push(c);
|
||||||
} else {
|
} else {
|
||||||
colors.push(Color::Byte(8));
|
colors.push(Color::Byte(8));
|
||||||
|
@ -703,8 +691,7 @@ impl PlainListing {
|
||||||
Box::new(self.filtered_selection.iter().map(|h| *h))
|
Box::new(self.filtered_selection.iter().map(|h| *h))
|
||||||
as Box<dyn Iterator<Item = EnvelopeHash>>
|
as Box<dyn Iterator<Item = EnvelopeHash>>
|
||||||
};
|
};
|
||||||
for (idx, i) in iter.enumerate() {
|
for i in iter {
|
||||||
self.length += 1;
|
|
||||||
if !context.accounts[self.cursor_pos.0].contains_key(i) {
|
if !context.accounts[self.cursor_pos.0].contains_key(i) {
|
||||||
debug!("key = {}", i);
|
debug!("key = {}", i);
|
||||||
debug!(
|
debug!(
|
||||||
|
@ -717,6 +704,16 @@ impl PlainListing {
|
||||||
panic!();
|
panic!();
|
||||||
}
|
}
|
||||||
let envelope: EnvelopeRef = context.accounts[self.cursor_pos.0].collection.get_env(i);
|
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);
|
let entry_strings = self.make_entry_string(envelope, context);
|
||||||
min_width.1 = cmp::max(min_width.1, entry_strings.date.grapheme_width()); /* date */
|
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.all_envelopes.insert(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.order.insert(i, idx);
|
self.order.insert(i, self.length);
|
||||||
self.selection.insert(i, false);
|
self.selection.insert(i, false);
|
||||||
|
self.length += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
min_width.0 = self.length.saturating_sub(1).to_string().len();
|
min_width.0 = self.length.saturating_sub(1).to_string().len();
|
||||||
|
|
|
@ -161,9 +161,10 @@ impl MailView {
|
||||||
Some(Box::new(move |a: &'closure Attachment, v: &mut Vec<u8>| {
|
Some(Box::new(move |a: &'closure Attachment, v: &mut Vec<u8>| {
|
||||||
if a.content_type().is_text_html() {
|
if a.content_type().is_text_html() {
|
||||||
use std::io::Write;
|
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 */
|
/* 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 parts = split_command!(filter_invocation);
|
||||||
let (cmd, args) = (parts[0], &parts[1..]);
|
let (cmd, args) = (parts[0], &parts[1..]);
|
||||||
let command_obj = Command::new(cmd)
|
let command_obj = Command::new(cmd)
|
||||||
|
@ -399,7 +400,10 @@ impl Component for MailView {
|
||||||
|
|
||||||
self.headers_no = 0;
|
self.headers_no = 0;
|
||||||
let mut skip_header_ctr = self.headers_cursor;
|
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;
|
let (_, mut y) = upper_left;
|
||||||
macro_rules! print_header {
|
macro_rules! print_header {
|
||||||
($($string:expr)+) => {
|
($($string:expr)+) => {
|
||||||
|
@ -569,7 +573,9 @@ impl Component for MailView {
|
||||||
context
|
context
|
||||||
.dirty_areas
|
.dirty_areas
|
||||||
.push_back((upper_left, set_y(bottom_right, y + 3)));
|
.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_p = self.pager.size().1;
|
||||||
|
|
||||||
let height = height!(area).saturating_sub(y).saturating_sub(1);
|
let height = height!(area).saturating_sub(y).saturating_sub(1);
|
||||||
|
@ -637,11 +643,11 @@ impl Component for MailView {
|
||||||
self.initialised = false;
|
self.initialised = false;
|
||||||
}
|
}
|
||||||
ViewMode::Normal
|
ViewMode::Normal
|
||||||
if context
|
if mailbox_settings!(
|
||||||
.settings
|
context[self.coordinates.0][&self.coordinates.1].pager
|
||||||
.pager
|
)
|
||||||
.auto_choose_multipart_alternative
|
.auto_choose_multipart_alternative
|
||||||
.is_true()
|
.is_true()
|
||||||
&& match body.content_type {
|
&& match body.content_type {
|
||||||
ContentType::Multipart {
|
ContentType::Multipart {
|
||||||
kind: MultipartType::Alternative,
|
kind: MultipartType::Alternative,
|
||||||
|
@ -807,7 +813,10 @@ impl Component for MailView {
|
||||||
_ => match event {
|
_ => match event {
|
||||||
UIEvent::Input(ref key)
|
UIEvent::Input(ref key)
|
||||||
if shortcut!(key == shortcuts[Pager::DESCRIPTION]["scroll_up"])
|
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.headers_cursor <= self.headers_no =>
|
||||||
{
|
{
|
||||||
self.force_draw_headers = true;
|
self.force_draw_headers = true;
|
||||||
|
@ -823,7 +832,10 @@ impl Component for MailView {
|
||||||
}
|
}
|
||||||
UIEvent::Input(ref key)
|
UIEvent::Input(ref key)
|
||||||
if shortcut!(key == shortcuts[Pager::DESCRIPTION]["scroll_down"])
|
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.headers_cursor < self.headers_no =>
|
||||||
{
|
{
|
||||||
self.force_draw_headers = true;
|
self.force_draw_headers = true;
|
||||||
|
|
25
src/conf.rs
25
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)]
|
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct MailUIConf {
|
pub struct MailUIConf {
|
||||||
pub pager: Option<PagerSettings>,
|
pub pager: Option<PagerSettings>,
|
||||||
|
@ -110,7 +133,7 @@ pub struct FileAccount {
|
||||||
identity: String,
|
identity: String,
|
||||||
#[serde(default = "none")]
|
#[serde(default = "none")]
|
||||||
display_name: Option<String>,
|
display_name: Option<String>,
|
||||||
index_style: IndexStyle,
|
pub index_style: IndexStyle,
|
||||||
|
|
||||||
#[serde(default = "false_val")]
|
#[serde(default = "false_val")]
|
||||||
read_only: bool,
|
read_only: bool,
|
||||||
|
|
Loading…
Reference in New Issue