Browse Source

Add configurable mailbox sort order

Closes #25

```
     sort_order unsigned integer           (optional) Override sort order on the sidebar for this mailbox.  Example:

                                           [accounts."imap.example.com".mailboxes]
                                             "INBOX" = { index_style = "plain" }
                                             "INBOX/Sent" = { sort_order = 0 }
                                             "INBOX/Drafts" = { sort_order = 1 }
                                             "INBOX/Lists" = { sort_order = 2 }
```
master
Manos Pitsidianakis 1 month ago
parent
commit
36e29cb6fd
Signed by untrusted user: epilys GPG Key ID: 73627C2F690DF710
  1. 11
      docs/meli.conf.5
  2. 3
      melib/src/conf.rs
  3. 65
      src/conf/accounts.rs

11
docs/meli.conf.5

@ -457,6 +457,17 @@ Example:
"INBOX" = { index_style = "plain" }
"INBOX/Lists/devlist" = { autoload = false, pager = { filter = "pygmentize -l diff -f 256"} }
.Ed
.It Ic sort_order Ar unsigned integer
.Pq Em optional
Override sort order on the sidebar for this mailbox.
Example:
.Bd -literal
[accounts."imap.example.com".mailboxes]
"INBOX" = { index_style = "plain" }
"INBOX/Sent" = { sort_order = 0 }
"INBOX/Drafts" = { sort_order = 1 }
"INBOX/Lists" = { sort_order = 2 }
.Ed
.El
.Sh COMPOSING
Composing specific options

3
melib/src/conf.rs

@ -87,6 +87,8 @@ pub struct MailboxConf {
pub ignore: ToggleFlag,
#[serde(default = "none")]
pub usage: Option<SpecialUsageMailbox>,
#[serde(default = "none")]
pub sort_order: Option<usize>,
#[serde(flatten)]
pub extra: HashMap<String, String>,
}
@ -99,6 +101,7 @@ impl Default for MailboxConf {
subscribe: ToggleFlag::Unset,
ignore: ToggleFlag::Unset,
usage: None,
sort_order: None,
extra: HashMap::default(),
}
}

65
src/conf/accounts.rs

@ -2276,24 +2276,41 @@ fn build_mailboxes_order(
}
}
macro_rules! mailbox_eq_key {
($mailbox:expr) => {{
if let Some(sort_order) = $mailbox.conf.mailbox_conf.sort_order {
(0, sort_order, $mailbox.ref_mailbox.path())
} else {
(1, 0, $mailbox.ref_mailbox.path())
}
}};
}
tree.sort_unstable_by(|a, b| {
if mailbox_entries[&b.hash]
.ref_mailbox
.path()
.eq_ignore_ascii_case("INBOX")
.conf
.mailbox_conf
.sort_order
.is_none()
&& mailbox_entries[&b.hash]
.ref_mailbox
.path()
.eq_ignore_ascii_case("INBOX")
{
std::cmp::Ordering::Greater
} else if mailbox_entries[&a.hash]
.ref_mailbox
.path()
.eq_ignore_ascii_case("INBOX")
.conf
.mailbox_conf
.sort_order
.is_none()
&& mailbox_entries[&a.hash]
.ref_mailbox
.path()
.eq_ignore_ascii_case("INBOX")
{
std::cmp::Ordering::Less
} else {
mailbox_entries[&a.hash]
.ref_mailbox
.path()
.cmp(&mailbox_entries[&b.hash].ref_mailbox.path())
mailbox_eq_key!(mailbox_entries[&a.hash])
.cmp(&mailbox_eq_key!(mailbox_entries[&b.hash]))
}
});
@ -2302,22 +2319,30 @@ fn build_mailboxes_order(
mailboxes_order.push(n.hash);
n.children.sort_unstable_by(|a, b| {
if mailbox_entries[&b.hash]
.ref_mailbox
.path()
.eq_ignore_ascii_case("INBOX")
.conf
.mailbox_conf
.sort_order
.is_none()
&& mailbox_entries[&b.hash]
.ref_mailbox
.path()
.eq_ignore_ascii_case("INBOX")
{
std::cmp::Ordering::Greater
} else if mailbox_entries[&a.hash]
.ref_mailbox
.path()
.eq_ignore_ascii_case("INBOX")
.conf
.mailbox_conf
.sort_order
.is_none()
&& mailbox_entries[&a.hash]
.ref_mailbox
.path()
.eq_ignore_ascii_case("INBOX")
{
std::cmp::Ordering::Less
} else {
mailbox_entries[&a.hash]
.ref_mailbox
.path()
.cmp(&mailbox_entries[&b.hash].ref_mailbox.path())
mailbox_eq_key!(mailbox_entries[&a.hash])
.cmp(&mailbox_eq_key!(mailbox_entries[&b.hash]))
}
});
stack.extend(n.children.iter().rev().map(Some));

Loading…
Cancel
Save