From a85b3a089fae968a28f2fefb441379e27630ee17 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Tue, 9 Jul 2024 13:40:33 +0300 Subject: [PATCH] meli/accounts: allow default_mailbox to be any mailbox .. And not just the ones defined in the configuration. Previously, it'd only work if the mailbox was defined in the configuration file. Also, make it so that the default mailbox is selected when meli is first invoked, not just when changing to another account later. Fixes #350 Resolves: https://git.meli-email.org/meli/meli/issues/350 Signed-off-by: Manos Pitsidianakis --- meli/src/accounts.rs | 6 +++--- meli/src/mail/listing.rs | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/meli/src/accounts.rs b/meli/src/accounts.rs index 731dafeb..739d9cf2 100644 --- a/meli/src/accounts.rs +++ b/meli/src/accounts.rs @@ -348,11 +348,11 @@ impl Account { .into_iter() .collect::>(); for f in ref_mailboxes.values_mut() { + if default_mailbox.remove(f.path()) { + self.settings.default_mailbox = Some(f.hash()); + } if let Some(conf) = self.settings.mailbox_confs.get_mut(f.path()) { mailbox_conf_hash_set.remove(f.path()); - if default_mailbox.remove(f.path()) { - self.settings.default_mailbox = Some(f.hash()); - } conf.mailbox_conf.usage = if f.special_usage() != SpecialUsageMailbox::Normal { Some(f.special_usage()) } else { diff --git a/meli/src/mail/listing.rs b/meli/src/mail/listing.rs index 430ebfc7..06760e23 100644 --- a/meli/src/mail/listing.rs +++ b/meli/src/mail/listing.rs @@ -2832,6 +2832,16 @@ impl Listing { cmd_buf: String::with_capacity(4), }; ret.component.realize(ret.id().into(), context); + { + let _new_val = ret.cursor_pos.account; + if let Some(idx) = context.accounts[_new_val] + .default_mailbox() + .and_then(|h| ret.accounts[_new_val].entry_by_hash(h)) + { + ret.cursor_pos.menu = MenuEntryCursor::Mailbox(idx); + ret.menu_cursor_pos.menu = MenuEntryCursor::Mailbox(idx); + } + } ret.change_account(context); ret } @@ -3335,6 +3345,20 @@ impl Listing { index_style: previous_index_styles.get(&f.hash).copied(), }) .collect::<_>(); + if let ( + ListingComponent::Offline(_), + MenuEntryCursor::Mailbox(ref mut idx), + Some(default), + ) = ( + &self.component, + &mut self.cursor_pos.menu, + context.accounts[self.cursor_pos.account] + .default_mailbox() + .and_then(|h| self.accounts[self.cursor_pos.account].entry_by_hash(h)), + ) { + *idx = default; + self.menu_cursor_pos.menu = MenuEntryCursor::Mailbox(default); + } match self.cursor_pos.menu { MenuEntryCursor::Mailbox(idx) => { // Account might have no mailboxes yet if it's offline