diff --git a/melib/src/backends.rs b/melib/src/backends.rs index 422b0f45f..948636527 100644 --- a/melib/src/backends.rs +++ b/melib/src/backends.rs @@ -37,7 +37,7 @@ use std::ops::Deref; use fnv::FnvHashMap; use std; -pub type BackendCreator = Box Box>; +pub type BackendCreator = Box bool>) -> Box>; /// A hashmap containing all available mail backends. /// An abstraction over any available backends. @@ -58,15 +58,15 @@ impl Backends { }; b.register( "maildir".to_string(), - Box::new(|| Box::new(|f| Box::new(MaildirType::new(f)))), + Box::new(|| Box::new(|f, i| Box::new(MaildirType::new(f, i)))), ); b.register( "mbox".to_string(), - Box::new(|| Box::new(|f| Box::new(MboxType::new(f)))), + Box::new(|| Box::new(|f, i| Box::new(MboxType::new(f, i)))), ); b.register( "imap".to_string(), - Box::new(|| Box::new(|f| Box::new(ImapType::new(f)))), + Box::new(|| Box::new(|f, i| Box::new(ImapType::new(f, i)))), ); b } diff --git a/melib/src/backends/imap.rs b/melib/src/backends/imap.rs index 9f0774bd3..02d505460 100644 --- a/melib/src/backends/imap.rs +++ b/melib/src/backends/imap.rs @@ -651,7 +651,7 @@ macro_rules! exit_on_error { } } impl ImapType { - pub fn new(s: &AccountSettings) -> Self { + pub fn new(s: &AccountSettings, is_subscribed: Box bool>) -> Self { use std::io::prelude::*; use std::net::TcpStream; debug!(s); @@ -779,17 +779,26 @@ impl ImapType { drop(conn); m.folders = m.imap_folders(); + m.folders.retain(|_, f| is_subscribed(f.path())); + let keys = m + .folders + .keys() + .cloned() + .collect::>(); + for f in m.folders.values_mut() { + f.children.retain(|c| keys.contains(c)); + } + /* for f in m.folders.keys() { m.folder_connections.insert( *f, Arc::new(Mutex::new(exit_on_error!(s returning m.new_connection()))), ); - } + }*/ m } pub fn shell(&mut self) { - self.folders(); let mut conn = self.connection.lock().unwrap(); let mut res = String::with_capacity(8 * 1024); diff --git a/melib/src/backends/maildir/backend.rs b/melib/src/backends/maildir/backend.rs index 60b7d263b..9a7b50e73 100644 --- a/melib/src/backends/maildir/backend.rs +++ b/melib/src/backends/maildir/backend.rs @@ -529,7 +529,7 @@ impl MailBackend for MaildirType { } impl MaildirType { - pub fn new(settings: &AccountSettings) -> Self { + pub fn new(settings: &AccountSettings, is_subscribed: Box bool>) -> Self { let mut folders: FnvHashMap = Default::default(); fn recurse_folders>( folders: &mut FnvHashMap, @@ -627,6 +627,7 @@ impl MaildirType { .count(); folders.get_mut(&root_hash).map(|f| f.children = children); } + folders.retain(|_, f| is_subscribed(f.path())); let hash_indexes = Arc::new(Mutex::new(FnvHashMap::with_capacity_and_hasher( folders.len(), diff --git a/melib/src/backends/mbox.rs b/melib/src/backends/mbox.rs index 39c4363f0..84b7a4b4e 100644 --- a/melib/src/backends/mbox.rs +++ b/melib/src/backends/mbox.rs @@ -540,7 +540,7 @@ impl MailBackend for MboxType { } impl MboxType { - pub fn new(s: &AccountSettings) -> Self { + pub fn new(s: &AccountSettings, _is_subscribed: Box bool>) -> Self { let path = Path::new(s.root_folder.as_str()); if !path.exists() { panic!( diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index 70e9c28ef..bfece643a 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -562,12 +562,14 @@ impl Listing { } *depth -= 1; } + let mut keys = entries.keys().cloned().collect::>(); + keys.sort_unstable_by(|a, b| folders_order[a].partial_cmp(&folders_order[b]).unwrap()); /* Start with roots */ - for f in entries.keys() { - if entries[f].parent().is_none() { + for f in keys { + if entries[&f].parent().is_none() { print( - *f, + f, &mut depth, &mut inc, &entries, diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs index 29ced12d6..22748b86a 100644 --- a/ui/src/conf/accounts.rs +++ b/ui/src/conf/accounts.rs @@ -192,7 +192,13 @@ struct FolderNode { impl Account { pub fn new(name: String, settings: AccountConf, map: &Backends, notify_fn: NotifyFn) -> Self { - let mut backend = map.get(settings.account().format())(settings.account()); + let s = settings.clone(); + let mut backend = map.get(settings.account().format())( + settings.account(), + Box::new(move |path: &str| { + s.folder_confs.contains_key(path) && s.folder_confs[path].subscribe.is_true() + }), + ); let mut ref_folders: FnvHashMap = backend.folders(); let mut folders: FnvHashMap = FnvHashMap::with_capacity_and_hasher(ref_folders.len(), Default::default());