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 <manos@pitsidianak.is>
pull/370/head
Manos Pitsidianakis 2 months ago
parent 484712b0c3
commit 742f038f74
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -139,7 +139,6 @@ pub struct Account {
pub mailbox_entries: IndexMap<MailboxHash, MailboxEntry>, pub mailbox_entries: IndexMap<MailboxHash, MailboxEntry>,
pub mailboxes_order: Vec<MailboxHash>, pub mailboxes_order: Vec<MailboxHash>,
pub tree: Vec<MailboxNode>, pub tree: Vec<MailboxNode>,
pub sent_mailbox: Option<MailboxHash>,
pub collection: Collection, pub collection: Collection,
pub address_book: AddressBook, pub address_book: AddressBook,
pub settings: AccountConf, pub settings: AccountConf,
@ -323,7 +322,6 @@ impl Account {
mailboxes_order: Default::default(), mailboxes_order: Default::default(),
tree: Default::default(), tree: Default::default(),
address_book, address_book,
sent_mailbox: Default::default(),
collection: backend.collection(), collection: backend.collection(),
settings, settings,
main_loop_handler, main_loop_handler,
@ -341,8 +339,6 @@ impl Account {
IndexMap::with_capacity_and_hasher(ref_mailboxes.len(), Default::default()); IndexMap::with_capacity_and_hasher(ref_mailboxes.len(), Default::default());
let mut mailboxes_order: Vec<MailboxHash> = Vec::with_capacity(ref_mailboxes.len()); let mut mailboxes_order: Vec<MailboxHash> = Vec::with_capacity(ref_mailboxes.len());
let mut sent_mailbox = None;
/* Keep track of which mailbox config values we encounter in the actual /* Keep track of which mailbox config values we encounter in the actual
* mailboxes returned by the backend. For each of 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 * mailboxes, delete the key from the hash set. If any are left, they
@ -368,11 +364,11 @@ impl Account {
}; };
match conf.mailbox_conf.usage { match conf.mailbox_conf.usage {
Some(SpecialUsageMailbox::Sent) => { Some(SpecialUsageMailbox::Sent) => {
sent_mailbox = Some(f.hash()); self.settings.sent_mailbox = Some(f.hash());
} }
None => { None => {
if f.special_usage() == SpecialUsageMailbox::Sent { 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 tmp
}; };
if new.mailbox_conf.usage == Some(SpecialUsageMailbox::Sent) { if new.mailbox_conf.usage == Some(SpecialUsageMailbox::Sent) {
sent_mailbox = Some(f.hash()); self.settings.sent_mailbox = Some(f.hash());
} }
mailbox_entries.insert( mailbox_entries.insert(
@ -499,7 +495,6 @@ impl Account {
self.mailboxes_order = mailboxes_order; self.mailboxes_order = mailboxes_order;
self.mailbox_entries = mailbox_entries; self.mailbox_entries = mailbox_entries;
self.tree = tree; self.tree = tree;
self.sent_mailbox = sent_mailbox;
Ok(()) Ok(())
} }
@ -1541,10 +1536,11 @@ impl Account {
.into_iter() .into_iter()
.map(|e| (e.hash(), e)) .map(|e| (e.hash(), e))
.collect::<HashMap<EnvelopeHash, Envelope>>(); .collect::<HashMap<EnvelopeHash, Envelope>>();
if let Some(updated_mailboxes) = if let Some(updated_mailboxes) = self.collection.merge(
self.collection envelopes,
.merge(envelopes, mailbox_hash, self.sent_mailbox) mailbox_hash,
{ self.settings.sent_mailbox,
) {
for f in updated_mailboxes { for f in updated_mailboxes {
self.main_loop_handler.send(ThreadEvent::UIEvent( self.main_loop_handler.send(ThreadEvent::UIEvent(
UIEvent::MailboxUpdate((self.hash, f)), UIEvent::MailboxUpdate((self.hash, f)),
@ -1890,8 +1886,8 @@ impl Account {
{ {
self.tree.remove(pos); self.tree.remove(pos);
} }
if self.sent_mailbox == Some(mailbox_hash) { if self.settings.sent_mailbox == Some(mailbox_hash) {
self.sent_mailbox = None; self.settings.sent_mailbox = None;
} }
self.collection self.collection
.threads .threads

@ -31,7 +31,11 @@ use std::{
process::{Command, Stdio}, process::{Command, Stdio},
}; };
use melib::{backends::TagHash, search::Query, SortField, SortOrder, StderrLogger}; use melib::{
backends::{MailboxHash, TagHash},
search::Query,
SortField, SortOrder, StderrLogger,
};
use crate::{ use crate::{
conf::deserializers::non_empty_opt_string, conf::deserializers::non_empty_opt_string,
@ -230,6 +234,7 @@ pub struct FileSettings {
#[derive(Clone, Debug, Default, Serialize)] #[derive(Clone, Debug, Default, Serialize)]
pub struct AccountConf { pub struct AccountConf {
pub account: AccountSettings, pub account: AccountSettings,
pub sent_mailbox: Option<MailboxHash>,
pub conf: FileAccount, pub conf: FileAccount,
pub conf_override: MailUIConf, pub conf_override: MailUIConf,
pub mailbox_confs: IndexMap<String, FileMailboxConf>, pub mailbox_confs: IndexMap<String, FileMailboxConf>,
@ -281,6 +286,7 @@ impl From<FileAccount> for AccountConf {
let mailbox_confs = x.mailboxes.clone(); let mailbox_confs = x.mailboxes.clone();
Self { Self {
account: acc, account: acc,
sent_mailbox: None,
conf_override: x.conf_override.clone(), conf_override: x.conf_override.clone(),
conf: x, conf: x,
mailbox_confs, mailbox_confs,

Loading…
Cancel
Save