diff --git a/melib/src/conf/mod.rs b/melib/src/conf/mod.rs index bcd087519..390684bcf 100644 --- a/melib/src/conf/mod.rs +++ b/melib/src/conf/mod.rs @@ -25,7 +25,6 @@ pub struct AccountSettings { pub root_folder: String, pub format: String, pub sent_folder: String, - pub threaded: bool, } impl AccountSettings { diff --git a/melib/src/mailbox/mod.rs b/melib/src/mailbox/mod.rs index 58cc92675..6e9e4a356 100644 --- a/melib/src/mailbox/mod.rs +++ b/melib/src/mailbox/mod.rs @@ -31,8 +31,6 @@ pub use self::email::*; pub mod backends; use error::Result; use mailbox::backends::{folder_default, Folder, MailBackend}; -pub mod accounts; -pub use mailbox::accounts::Account; pub mod thread; pub use mailbox::thread::{build_threads, Container, Threads, SortOrder, SortField}; diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index ec91aca80..cc59a28c5 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -416,9 +416,8 @@ impl Component for CompactListing { Action::MailListing(MailListingAction::ToggleThreaded) => { context.accounts[self.cursor_pos.0] .runtime_settings - .threaded = !context.accounts[self.cursor_pos.0] - .runtime_settings - .threaded; + .conf_mut() + .toggle_threaded(); self.refresh_mailbox(context); self.dirty = true; return; diff --git a/ui/src/components/mail/listing/mod.rs b/ui/src/components/mail/listing/mod.rs index 5ad511e02..5dc6dba57 100644 --- a/ui/src/components/mail/listing/mod.rs +++ b/ui/src/components/mail/listing/mod.rs @@ -96,7 +96,8 @@ impl MailListing { let threaded = context.accounts[self.cursor_pos.0] .runtime_settings - .threaded; + .conf() + .threaded(); // Inform State that we changed the current folder view. context.replies.push_back(UIEvent { id: 0, @@ -293,7 +294,8 @@ impl MailListing { fn highlight_line_self(&mut self, idx: usize, context: &Context) { let threaded = context.accounts[self.cursor_pos.0] .runtime_settings - .threaded; + .conf() + .threaded(); let mailbox = &context.accounts[self.cursor_pos.0][self.cursor_pos.1] .as_ref() .unwrap(); @@ -327,7 +329,8 @@ impl MailListing { fn highlight_line(&self, grid: &mut CellBuffer, area: Area, idx: usize, context: &Context) { let threaded = context.accounts[self.cursor_pos.0] .runtime_settings - .threaded; + .conf() + .threaded(); let mailbox = &context.accounts[self.cursor_pos.0][self.cursor_pos.1] .as_ref() .unwrap(); @@ -515,7 +518,8 @@ impl Component for MailListing { } else { let threaded = context.accounts[self.cursor_pos.0] .runtime_settings - .threaded; + .conf() + .threaded(); let account = &mut context.accounts[self.cursor_pos.0]; let (hash, is_seen) = { let mailbox = &mut account[self.cursor_pos.1] @@ -737,9 +741,8 @@ impl Component for MailListing { Action::MailListing(MailListingAction::ToggleThreaded) => { context.accounts[self.cursor_pos.0] .runtime_settings - .threaded = !context.accounts[self.cursor_pos.0] - .runtime_settings - .threaded; + .conf_mut() + .toggle_threaded(); self.refresh_mailbox(context); self.dirty = true; return; diff --git a/ui/src/components/mail/view/mod.rs b/ui/src/components/mail/view/mod.rs index 9e8e64430..db0113cd9 100644 --- a/ui/src/components/mail/view/mod.rs +++ b/ui/src/components/mail/view/mod.rs @@ -209,7 +209,7 @@ impl Component for MailView { let (envelope_idx, y): (usize, usize) = { let accounts = &mut context.accounts; - let threaded = accounts[self.coordinates.0].runtime_settings.threaded; + let threaded = accounts[self.coordinates.0].runtime_settings.conf().threaded(); let mailbox = &mut accounts[self.coordinates.0][self.coordinates.1] .as_ref() .unwrap(); @@ -372,7 +372,7 @@ impl Component for MailView { { let accounts = &context.accounts; - let threaded = accounts[self.coordinates.0].runtime_settings.threaded; + let threaded = accounts[self.coordinates.0].runtime_settings.conf().threaded(); let mailbox = &accounts[self.coordinates.0][self.coordinates.1] .as_ref() .unwrap(); @@ -462,7 +462,7 @@ impl Component for MailView { self.cmd_buf.clear(); let url = { let accounts = &context.accounts; - let threaded = accounts[self.coordinates.0].runtime_settings.threaded; + let threaded = accounts[self.coordinates.0].runtime_settings.conf().threaded(); let mailbox = &accounts[self.coordinates.0][self.coordinates.1] .as_ref() .unwrap(); diff --git a/ui/src/conf/mod.rs b/ui/src/conf/mod.rs index 908d66eeb..cc80922f4 100644 --- a/ui/src/conf/mod.rs +++ b/ui/src/conf/mod.rs @@ -42,6 +42,12 @@ impl FileAccount { pub fn folder(&self) -> &str { &self.root_folder } + pub fn threaded(&self) -> bool { + self.threaded + } + pub fn toggle_threaded(&mut self) { + self.threaded = !self.threaded; + } } #[derive(Debug, Clone, Default, Deserialize)] @@ -51,23 +57,26 @@ struct FileSettings { } #[derive(Debug, Clone, Default)] -pub struct AccountConfiguration { +pub struct AccountConf { account: AccountSettings, conf: FileAccount, } -impl AccountConfiguration { +impl AccountConf { pub fn account(&self) -> &AccountSettings { &self.account } pub fn conf(&self) -> &FileAccount { &self.conf } + pub fn conf_mut(&mut self) -> &mut FileAccount { + &mut self.conf + } } #[derive(Debug, Clone, Default)] pub struct Settings { - pub accounts: HashMap, + pub accounts: HashMap, pub pager: PagerSettings, } @@ -91,12 +100,11 @@ impl FileSettings { impl Settings { pub fn new() -> Settings { let fs = FileSettings::new(); - let mut s: HashMap = HashMap::new(); + let mut s: HashMap = HashMap::new(); for (id, x) in fs.accounts { let format = x.format.to_lowercase(); let sent_folder = x.sent_folder.clone(); - let threaded = x.threaded; let root_folder = x.root_folder.clone(); let acc = AccountSettings { @@ -104,10 +112,9 @@ impl Settings { root_folder, format, sent_folder, - threaded, }; - s.insert(id, AccountConfiguration { + s.insert(id, AccountConf { account: acc, conf: x }); diff --git a/ui/src/state.rs b/ui/src/state.rs index 8ce9ac53f..978793f52 100644 --- a/ui/src/state.rs +++ b/ui/src/state.rs @@ -179,7 +179,7 @@ impl State { let mut accounts: Vec = settings .accounts .iter() - .map(|(n, a_s)| Account::new(n.to_string(), a_s.account().clone(), &backends)) + .map(|(n, a_s)| Account::new(n.to_string(), a_s.clone(), &backends)) .collect(); accounts.sort_by(|a, b| a.name().cmp(&b.name())); let (startup_tx, startup_rx) = chan::async(); diff --git a/melib/src/mailbox/accounts.rs b/ui/src/types/accounts.rs similarity index 95% rename from melib/src/mailbox/accounts.rs rename to ui/src/types/accounts.rs index 66b094d31..c8dcb7f16 100644 --- a/melib/src/mailbox/accounts.rs +++ b/ui/src/types/accounts.rs @@ -24,8 +24,9 @@ */ use async::*; -use conf::AccountSettings; -use mailbox::backends::{Backends, RefreshEventConsumer}; +use conf::AccountConf; +use melib::error::Result; +use mailbox::backends::{MailBackend, Folder, Backends, RefreshEventConsumer}; use mailbox::*; use std::ops::{Index, IndexMut}; use std::result; @@ -47,20 +48,20 @@ pub struct Account { sent_folder: Option, - pub settings: AccountSettings, - pub runtime_settings: AccountSettings, + pub settings: AccountConf, + pub runtime_settings: AccountConf, pub backend: Box, } impl Account { - pub fn new(name: String, settings: AccountSettings, map: &Backends) -> Self { - let mut backend = map.get(settings.format())(&settings); + pub fn new(name: String, settings: AccountConf, map: &Backends) -> Self { + let mut backend = map.get(settings.account().format())(settings.account()); let ref_folders: Vec = backend.folders(); let mut folders: Vec>> = Vec::with_capacity(ref_folders.len()); let mut workers: Vec = Vec::new(); let sent_folder = ref_folders .iter() - .position(|x: &Folder| x.name() == settings.sent_folder); + .position(|x: &Folder| x.name() == settings.account().sent_folder); for f in ref_folders { folders.push(None); let handle = backend.get(&f); diff --git a/ui/src/types/mod.rs b/ui/src/types/mod.rs index 4f7048716..8dcc76def 100644 --- a/ui/src/types/mod.rs +++ b/ui/src/types/mod.rs @@ -19,6 +19,8 @@ * along with meli. If not, see . */ +pub mod accounts; +pub use self::accounts::Account; #[macro_use] mod position; #[macro_use]