Browse Source

Lookup tag color/ignore settings in all three setting levels

There are three setting levels for tag settings:

- per mailbox override    ^
- per account override    |
- global setting          |
                        depth

So lookup in each of them in this order for configuration, not just the
deepest level.
memfd
Manos Pitsidianakis 1 year ago
parent
commit
20b02ffd4f
Signed by untrusted user: epilys GPG Key ID: 73627C2F690DF710
  1. 23
      src/components/mail/compose.rs
  2. 10
      src/components/mail/listing/compact.rs
  3. 10
      src/components/mail/listing/conversations.rs
  4. 10
      src/components/mail/listing/plain.rs
  5. 10
      src/components/mail/listing/thread.rs
  6. 2
      src/conf.rs

23
src/components/mail/compose.rs

@ -157,14 +157,14 @@ impl Composer {
..Default::default()
};
for (h, v) in
mailbox_acc_settings!(context[account_hash].composing.default_header_values).iter()
account_settings!(context[account_hash].composing.default_header_values).iter()
{
if v.is_empty() {
continue;
}
ret.draft.set_header(h, v.into());
}
if *mailbox_acc_settings!(context[account_hash].composing.insert_user_agent) {
if *account_settings!(context[account_hash].composing.insert_user_agent) {
ret.draft.set_header(
"User-Agent",
format!("meli {}", option_env!("CARGO_PKG_VERSION").unwrap_or("0.0")),
@ -429,7 +429,7 @@ impl Composer {
write_string_to_grid(
&format!(
"☑ sign with {}",
mailbox_acc_settings!(context[self.account_hash].pgp.key)
account_settings!(context[self.account_hash].pgp.key)
.as_ref()
.map(|s| s.as_str())
.unwrap_or("default key")
@ -520,7 +520,7 @@ impl Component for Composer {
if !self.initialized {
if self.sign_mail.is_unset() {
self.sign_mail = ToggleFlag::InternalVal(*mailbox_acc_settings!(
self.sign_mail = ToggleFlag::InternalVal(*account_settings!(
context[self.account_hash].pgp.auto_sign
));
}
@ -1078,8 +1078,7 @@ impl Component for Composer {
{
/* Edit draft in $EDITOR */
let editor = if let Some(editor_command) =
mailbox_acc_settings!(context[self.account_hash].composing.editor_command)
.as_ref()
account_settings!(context[self.account_hash].composing.editor_command).as_ref()
{
editor_command.to_string()
} else {
@ -1104,7 +1103,7 @@ impl Component for Composer {
true,
);
if *mailbox_acc_settings!(context[self.account_hash].composing.embed) {
if *account_settings!(context[self.account_hash].composing.embed) {
self.embed = Some(EmbedStatus::Running(
crate::terminal::embed::create_pty(
width!(self.embed_area),
@ -1358,7 +1357,7 @@ impl Component for Composer {
};
let our_map: ShortcutMap =
mailbox_acc_settings!(context[self.account_hash].shortcuts.composing).key_values();
account_settings!(context[self.account_hash].shortcuts.composing).key_values();
map.insert(Composer::DESCRIPTION, our_map);
map
@ -1411,7 +1410,7 @@ pub fn send_draft(
flags: Flag,
complete_in_background: bool,
) -> Result<Option<(JobId, JoinHandle, JobChannel<()>)>> {
let format_flowed = *mailbox_acc_settings!(context[account_hash].composing.format_flowed);
let format_flowed = *account_settings!(context[account_hash].composing.format_flowed);
if sign_mail.is_true() {
let mut content_type = ContentType::default();
if format_flowed {
@ -1446,10 +1445,10 @@ pub fn send_draft(
}
let output = crate::components::mail::pgp::sign(
body.into(),
mailbox_acc_settings!(context[account_hash].pgp.gpg_binary)
account_settings!(context[account_hash].pgp.gpg_binary)
.as_ref()
.map(|s| s.as_str()),
mailbox_acc_settings!(context[account_hash].pgp.key)
account_settings!(context[account_hash].pgp.key)
.as_ref()
.map(|s| s.as_str()),
);
@ -1498,7 +1497,7 @@ pub fn send_draft(
}
}
let bytes = draft.finalise().unwrap();
let send_mail = mailbox_acc_settings!(context[account_hash].composing.send_mail).clone();
let send_mail = account_settings!(context[account_hash].composing.send_mail).clone();
let ret =
context.accounts[&account_hash].send(bytes.clone(), send_mail, complete_in_background);
save_draft(bytes.as_bytes(), context, mailbox_type, flags, account_hash);

10
src/components/mail/listing/compact.rs

@ -928,6 +928,8 @@ impl CompactListing {
.ignore_tags
)
.contains(t)
|| account_settings!(context[self.cursor_pos.0].tags.ignore_tags).contains(t)
|| context.settings.tags.ignore_tags.contains(t)
|| !tags_lck.contains_key(t)
{
continue;
@ -938,7 +940,13 @@ impl CompactListing {
colors.push(
mailbox_settings!(context[self.cursor_pos.0][&self.cursor_pos.1].tags.colors)
.get(t)
.map(|&c| c),
.cloned()
.or_else(|| {
account_settings!(context[self.cursor_pos.0].tags.colors)
.get(t)
.cloned()
.or_else(|| context.settings.tags.colors.get(t).cloned())
}),
);
}
if !tags.is_empty() {

10
src/components/mail/listing/conversations.rs

@ -938,6 +938,8 @@ impl ConversationsListing {
.ignore_tags
)
.contains(t)
|| account_settings!(context[self.cursor_pos.0].tags.ignore_tags).contains(t)
|| context.settings.tags.ignore_tags.contains(t)
|| !tags_lck.contains_key(t)
{
continue;
@ -948,7 +950,13 @@ impl ConversationsListing {
colors.push(
mailbox_settings!(context[self.cursor_pos.0][&self.cursor_pos.1].tags.colors)
.get(t)
.map(|&c| c),
.cloned()
.or_else(|| {
account_settings!(context[self.cursor_pos.0].tags.colors)
.get(t)
.cloned()
.or_else(|| context.settings.tags.colors.get(t).cloned())
}),
);
}
if !tags.is_empty() {

10
src/components/mail/listing/plain.rs

@ -743,6 +743,8 @@ impl PlainListing {
.ignore_tags
)
.contains(t)
|| account_settings!(context[self.cursor_pos.0].tags.ignore_tags).contains(t)
|| context.settings.tags.ignore_tags.contains(t)
|| !tags_lck.contains_key(t)
{
continue;
@ -753,7 +755,13 @@ impl PlainListing {
colors.push(
mailbox_settings!(context[self.cursor_pos.0][&self.cursor_pos.1].tags.colors)
.get(t)
.map(|&c| c),
.cloned()
.or_else(|| {
account_settings!(context[self.cursor_pos.0].tags.colors)
.get(t)
.cloned()
.or_else(|| context.settings.tags.colors.get(t).cloned())
}),
);
}
if !tags.is_empty() {

10
src/components/mail/listing/thread.rs

@ -859,6 +859,8 @@ impl ThreadListing {
.ignore_tags
)
.contains(t)
|| account_settings!(context[self.cursor_pos.0].tags.ignore_tags).contains(t)
|| context.settings.tags.ignore_tags.contains(t)
|| !tags_lck.contains_key(t)
{
continue;
@ -869,7 +871,13 @@ impl ThreadListing {
colors.push(
mailbox_settings!(context[self.cursor_pos.0][&self.cursor_pos.1].tags.colors)
.get(t)
.map(|&c| c),
.cloned()
.or_else(|| {
account_settings!(context[self.cursor_pos.0].tags.colors)
.get(t)
.cloned()
.or_else(|| context.settings.tags.colors.get(t).cloned())
}),
);
}
if !tags.is_empty() {

2
src/conf.rs

@ -78,7 +78,7 @@ macro_rules! split_command {
}
#[macro_export]
macro_rules! mailbox_acc_settings {
macro_rules! account_settings {
($context:ident[$account_hash:expr].$setting:ident.$field:ident) => {{
$context.accounts[&$account_hash]
.settings

Loading…
Cancel
Save