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 } ```pull/144/head
parent
5f003a31be
commit
36e29cb6fd
|
@ -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
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
.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]
|
||||
.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]
|
||||
.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]
|
||||
.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…
Reference in New Issue