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 <manos@pitsidianak.is>
pull/435/head
Manos Pitsidianakis 3 months ago
parent a330ff96e9
commit a85b3a089f
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -348,11 +348,11 @@ impl Account {
.into_iter()
.collect::<HashSet<String>>();
for f in ref_mailboxes.values_mut() {
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());
}
if let Some(conf) = self.settings.mailbox_confs.get_mut(f.path()) {
mailbox_conf_hash_set.remove(f.path());
conf.mailbox_conf.usage = if f.special_usage() != SpecialUsageMailbox::Normal {
Some(f.special_usage())
} else {

@ -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

Loading…
Cancel
Save