diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/src/components/mail.rs | 36 | ||||
-rw-r--r-- | ui/src/conf/accounts.rs | 29 |
2 files changed, 49 insertions, 16 deletions
diff --git a/ui/src/components/mail.rs b/ui/src/components/mail.rs index 0cf85ed3..503c669b 100644 --- a/ui/src/components/mail.rs +++ b/ui/src/components/mail.rs @@ -39,8 +39,6 @@ struct AccountMenuEntry { name: String, // Index in the config account vector. index: usize, - // Each entry and its index in the account - entries: Vec<(usize, Folder)>, } /// The account sidebar. @@ -67,13 +65,6 @@ impl AccountMenu { .map(|(i, a)| AccountMenuEntry { name: a.name().to_string(), index: i, - entries: { - let mut entries = Vec::with_capacity(a.len()); - for (idx, acc) in a.list_folders().into_iter().enumerate() { - entries.push((idx, acc)); - } - entries - }, }) .collect(); AccountMenu { @@ -96,16 +87,27 @@ impl AccountMenu { if cfg!(feature = "debug_log") && !is_valid_area!(area) { eprintln!("BUG: invalid area in print_account"); } + // Each entry and its index in the account + let entries: Vec<(usize, Folder)> = { + let a = &context.accounts[a.index]; + let mut entries = Vec::with_capacity(a.len()); + for (idx, acc) in a.list_folders().into_iter().enumerate() { + entries.push((idx, acc)); + } + entries + }; let upper_left = upper_left!(area); let bottom_right = bottom_right!(area); let highlight = self.cursor.map(|(x, _)| x == a.index).unwrap_or(false); - let mut parents: Vec<Option<usize>> = vec![None; a.entries.len()]; + let mut parents: Vec<Option<usize>> = vec![None; entries.len()]; - for (idx, e) in a.entries.iter().enumerate() { - for c in e.1.children() { - parents[*c] = Some(idx); + for (idx, e) in entries.iter().enumerate() { + for &c in e.1.children() { + if c < parents.len() { + parents[c] = Some(idx); + } } } let mut roots = Vec::new(); @@ -137,6 +139,9 @@ impl AccountMenu { index: usize, //account index context: &mut Context, ) { + if root >= entries.len() { + return; + } let len = s.len(); match context.accounts[index].status(root) { Ok(_) => {} @@ -167,7 +172,7 @@ impl AccountMenu { } for r in roots { print( - r, &parents, &mut depth, &a.entries, &mut s, &mut inc, a.index, context, + r, &parents, &mut depth, &entries, &mut s, &mut inc, a.index, context, ); } @@ -274,6 +279,9 @@ impl Component for AccountMenu { UIEventType::StartupCheck(_) => { self.dirty = true; } + UIEventType::MailboxUpdate(_) => { + self.dirty = true; + } _ => {} } false diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs index dfa8ac38..24f7b98c 100644 --- a/ui/src/conf/accounts.rs +++ b/ui/src/conf/accounts.rs @@ -123,13 +123,32 @@ impl<'a> Iterator for MailboxIterator<'a> { 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 ref_folders: Vec<Folder> = backend.folders(); + let mut ref_folders: Vec<Folder> = backend.folders(); let mut folders: Vec<Option<Result<Mailbox>>> = Vec::with_capacity(ref_folders.len()); let mut workers: Vec<Worker> = Vec::new(); + let notify_fn = Arc::new(notify_fn); + + if let Some(pos) = ref_folders + .iter() + .position(|f| f.name().eq_ignore_ascii_case("INBOX")) + { + ref_folders.swap(pos, 0); + } let sent_folder = ref_folders .iter() .position(|x: &Folder| x.name() == settings.account().sent_folder); - let notify_fn = Arc::new(notify_fn); + if let Some(folder_confs) = settings.conf().folders() { + //if cfg!(feature = "debug_log") { + //eprintln!("folder renames: {:?}", folder_renames); + //} + for f in &mut ref_folders { + if let Some(r) = folder_confs.get(&f.name().to_ascii_lowercase()) { + if let Some(rename) = r.rename() { + f.change_name(rename); + } + } + } + } for f in ref_folders { folders.push(None); workers.push(Account::new_worker(f, &mut backend, notify_fn.clone())); @@ -258,6 +277,12 @@ impl Account { } } } + if let Some(pos) = folders + .iter() + .position(|f| f.name().eq_ignore_ascii_case("INBOX")) + { + folders.swap(pos, 0); + } folders } pub fn name(&self) -> &str { |