From 742f038f74051ab8499ec2aaa65bf4cd4c12e1dd Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 16 Mar 2024 14:57:48 +0200 Subject: [PATCH] accounts: move sent_mailbox to settings In the next commits we will add a `default_mailbox` field. Instead of poluting the `Account` struct with more setting fields, consolidate them on its `settings`. Signed-off-by: Manos Pitsidianakis --- meli/src/accounts.rs | 24 ++++++++++-------------- meli/src/conf.rs | 8 +++++++- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/meli/src/accounts.rs b/meli/src/accounts.rs index 10dd9ae6..a64cbb74 100644 --- a/meli/src/accounts.rs +++ b/meli/src/accounts.rs @@ -139,7 +139,6 @@ pub struct Account { pub mailbox_entries: IndexMap, pub mailboxes_order: Vec, pub tree: Vec, - pub sent_mailbox: Option, pub collection: Collection, pub address_book: AddressBook, pub settings: AccountConf, @@ -323,7 +322,6 @@ impl Account { mailboxes_order: Default::default(), tree: Default::default(), address_book, - sent_mailbox: Default::default(), collection: backend.collection(), settings, main_loop_handler, @@ -341,8 +339,6 @@ impl Account { IndexMap::with_capacity_and_hasher(ref_mailboxes.len(), Default::default()); let mut mailboxes_order: Vec = Vec::with_capacity(ref_mailboxes.len()); - let mut sent_mailbox = None; - /* Keep track of which mailbox config values we encounter in the actual * mailboxes returned by the backend. For each of the actual * mailboxes, delete the key from the hash set. If any are left, they @@ -368,11 +364,11 @@ impl Account { }; match conf.mailbox_conf.usage { Some(SpecialUsageMailbox::Sent) => { - sent_mailbox = Some(f.hash()); + self.settings.sent_mailbox = Some(f.hash()); } None => { if f.special_usage() == SpecialUsageMailbox::Sent { - sent_mailbox = Some(f.hash()); + self.settings.sent_mailbox = Some(f.hash()); } } _ => {} @@ -398,7 +394,7 @@ impl Account { tmp }; if new.mailbox_conf.usage == Some(SpecialUsageMailbox::Sent) { - sent_mailbox = Some(f.hash()); + self.settings.sent_mailbox = Some(f.hash()); } mailbox_entries.insert( @@ -499,7 +495,6 @@ impl Account { self.mailboxes_order = mailboxes_order; self.mailbox_entries = mailbox_entries; self.tree = tree; - self.sent_mailbox = sent_mailbox; Ok(()) } @@ -1541,10 +1536,11 @@ impl Account { .into_iter() .map(|e| (e.hash(), e)) .collect::>(); - if let Some(updated_mailboxes) = - self.collection - .merge(envelopes, mailbox_hash, self.sent_mailbox) - { + if let Some(updated_mailboxes) = self.collection.merge( + envelopes, + mailbox_hash, + self.settings.sent_mailbox, + ) { for f in updated_mailboxes { self.main_loop_handler.send(ThreadEvent::UIEvent( UIEvent::MailboxUpdate((self.hash, f)), @@ -1890,8 +1886,8 @@ impl Account { { self.tree.remove(pos); } - if self.sent_mailbox == Some(mailbox_hash) { - self.sent_mailbox = None; + if self.settings.sent_mailbox == Some(mailbox_hash) { + self.settings.sent_mailbox = None; } self.collection .threads diff --git a/meli/src/conf.rs b/meli/src/conf.rs index 2a1535a3..c906f5cf 100644 --- a/meli/src/conf.rs +++ b/meli/src/conf.rs @@ -31,7 +31,11 @@ use std::{ process::{Command, Stdio}, }; -use melib::{backends::TagHash, search::Query, SortField, SortOrder, StderrLogger}; +use melib::{ + backends::{MailboxHash, TagHash}, + search::Query, + SortField, SortOrder, StderrLogger, +}; use crate::{ conf::deserializers::non_empty_opt_string, @@ -230,6 +234,7 @@ pub struct FileSettings { #[derive(Clone, Debug, Default, Serialize)] pub struct AccountConf { pub account: AccountSettings, + pub sent_mailbox: Option, pub conf: FileAccount, pub conf_override: MailUIConf, pub mailbox_confs: IndexMap, @@ -281,6 +286,7 @@ impl From for AccountConf { let mailbox_confs = x.mailboxes.clone(); Self { account: acc, + sent_mailbox: None, conf_override: x.conf_override.clone(), conf: x, mailbox_confs,