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
parent
5f003a31be
commit
36e29cb6fd
|
@ -457,6 +457,17 @@ Example:
|
||||||
"INBOX" = { index_style = "plain" }
|
"INBOX" = { index_style = "plain" }
|
||||||
"INBOX/Lists/devlist" = { autoload = false, pager = { filter = "pygmentize -l diff -f 256"} }
|
"INBOX/Lists/devlist" = { autoload = false, pager = { filter = "pygmentize -l diff -f 256"} }
|
||||||
.Ed
|
.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
|
.El
|
||||||
.Sh COMPOSING
|
.Sh COMPOSING
|
||||||
Composing specific options
|
Composing specific options
|
||||||
|
|
|
@ -87,6 +87,8 @@ pub struct MailboxConf {
|
||||||
pub ignore: ToggleFlag,
|
pub ignore: ToggleFlag,
|
||||||
#[serde(default = "none")]
|
#[serde(default = "none")]
|
||||||
pub usage: Option<SpecialUsageMailbox>,
|
pub usage: Option<SpecialUsageMailbox>,
|
||||||
|
#[serde(default = "none")]
|
||||||
|
pub sort_order: Option<usize>,
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub extra: HashMap<String, String>,
|
pub extra: HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
@ -99,6 +101,7 @@ impl Default for MailboxConf {
|
||||||
subscribe: ToggleFlag::Unset,
|
subscribe: ToggleFlag::Unset,
|
||||||
ignore: ToggleFlag::Unset,
|
ignore: ToggleFlag::Unset,
|
||||||
usage: None,
|
usage: None,
|
||||||
|
sort_order: None,
|
||||||
extra: HashMap::default(),
|
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| {
|
tree.sort_unstable_by(|a, b| {
|
||||||
if mailbox_entries[&b.hash]
|
if mailbox_entries[&b.hash]
|
||||||
.ref_mailbox
|
.conf
|
||||||
.path()
|
.mailbox_conf
|
||||||
.eq_ignore_ascii_case("INBOX")
|
.sort_order
|
||||||
|
.is_none()
|
||||||
|
&& mailbox_entries[&b.hash]
|
||||||
|
.ref_mailbox
|
||||||
|
.path()
|
||||||
|
.eq_ignore_ascii_case("INBOX")
|
||||||
{
|
{
|
||||||
std::cmp::Ordering::Greater
|
std::cmp::Ordering::Greater
|
||||||
} else if mailbox_entries[&a.hash]
|
} else if mailbox_entries[&a.hash]
|
||||||
.ref_mailbox
|
.conf
|
||||||
.path()
|
.mailbox_conf
|
||||||
.eq_ignore_ascii_case("INBOX")
|
.sort_order
|
||||||
|
.is_none()
|
||||||
|
&& mailbox_entries[&a.hash]
|
||||||
|
.ref_mailbox
|
||||||
|
.path()
|
||||||
|
.eq_ignore_ascii_case("INBOX")
|
||||||
{
|
{
|
||||||
std::cmp::Ordering::Less
|
std::cmp::Ordering::Less
|
||||||
} else {
|
} else {
|
||||||
mailbox_entries[&a.hash]
|
mailbox_eq_key!(mailbox_entries[&a.hash])
|
||||||
.ref_mailbox
|
.cmp(&mailbox_eq_key!(mailbox_entries[&b.hash]))
|
||||||
.path()
|
|
||||||
.cmp(&mailbox_entries[&b.hash].ref_mailbox.path())
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2302,22 +2319,30 @@ fn build_mailboxes_order(
|
||||||
mailboxes_order.push(n.hash);
|
mailboxes_order.push(n.hash);
|
||||||
n.children.sort_unstable_by(|a, b| {
|
n.children.sort_unstable_by(|a, b| {
|
||||||
if mailbox_entries[&b.hash]
|
if mailbox_entries[&b.hash]
|
||||||
.ref_mailbox
|
.conf
|
||||||
.path()
|
.mailbox_conf
|
||||||
.eq_ignore_ascii_case("INBOX")
|
.sort_order
|
||||||
|
.is_none()
|
||||||
|
&& mailbox_entries[&b.hash]
|
||||||
|
.ref_mailbox
|
||||||
|
.path()
|
||||||
|
.eq_ignore_ascii_case("INBOX")
|
||||||
{
|
{
|
||||||
std::cmp::Ordering::Greater
|
std::cmp::Ordering::Greater
|
||||||
} else if mailbox_entries[&a.hash]
|
} else if mailbox_entries[&a.hash]
|
||||||
.ref_mailbox
|
.conf
|
||||||
.path()
|
.mailbox_conf
|
||||||
.eq_ignore_ascii_case("INBOX")
|
.sort_order
|
||||||
|
.is_none()
|
||||||
|
&& mailbox_entries[&a.hash]
|
||||||
|
.ref_mailbox
|
||||||
|
.path()
|
||||||
|
.eq_ignore_ascii_case("INBOX")
|
||||||
{
|
{
|
||||||
std::cmp::Ordering::Less
|
std::cmp::Ordering::Less
|
||||||
} else {
|
} else {
|
||||||
mailbox_entries[&a.hash]
|
mailbox_eq_key!(mailbox_entries[&a.hash])
|
||||||
.ref_mailbox
|
.cmp(&mailbox_eq_key!(mailbox_entries[&b.hash]))
|
||||||
.path()
|
|
||||||
.cmp(&mailbox_entries[&b.hash].ref_mailbox.path())
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
stack.extend(n.children.iter().rev().map(Some));
|
stack.extend(n.children.iter().rev().map(Some));
|
||||||
|
|
Loading…
Reference in New Issue