From fe4dae12df6ae1d2e436db01b83bf0f489016068 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Fri, 7 Aug 2020 00:39:17 +0300 Subject: [PATCH] listing/*: show MailboxEntry::status() when length is 0 Show the MailboxEntry::status() string when self.length == 0, instead of "MAILBOX is empty". --- src/components/mail/listing/compact.rs | 2 +- src/components/mail/listing/conversations.rs | 2 +- src/components/mail/listing/plain.rs | 2 +- src/components/mail/listing/thread.rs | 2 +- src/conf/accounts.rs | 11 ++++++++--- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/components/mail/listing/compact.rs b/src/components/mail/listing/compact.rs index c434049e..f2464b2b 100644 --- a/src/components/mail/listing/compact.rs +++ b/src/components/mail/listing/compact.rs @@ -438,7 +438,7 @@ impl MailListingTrait for CompactListing { std::cmp::min(80, self.rows.len().saturating_sub(1)), ); if self.length == 0 && self.filter_term.is_empty() { - let message = format!("{} is empty", account[&self.cursor_pos.1].name()); + let message: String = account[&self.cursor_pos.1].status(); self.data_columns.columns[0] = CellBuffer::new_with_context(message.len(), self.length + 1, default_cell, context); write_string_to_grid( diff --git a/src/components/mail/listing/conversations.rs b/src/components/mail/listing/conversations.rs index f66ea037..0e16ba1a 100644 --- a/src/components/mail/listing/conversations.rs +++ b/src/components/mail/listing/conversations.rs @@ -471,7 +471,7 @@ impl MailListingTrait for ConversationsListing { .set_attrs(self.color_cache.theme_default.attrs); ret }; - let message = format!("{} is empty", account[&self.cursor_pos.1].name()); + let message: String = account[&self.cursor_pos.1].status(); self.content = CellBuffer::new_with_context(message.len(), 1, default_cell, context); write_string_to_grid( &message, diff --git a/src/components/mail/listing/plain.rs b/src/components/mail/listing/plain.rs index f3e8fb05..bcdaaa9e 100644 --- a/src/components/mail/listing/plain.rs +++ b/src/components/mail/listing/plain.rs @@ -980,7 +980,7 @@ impl PlainListing { } } if self.length == 0 && self.filter_term.is_empty() { - let message = format!("{} is empty", account[&self.cursor_pos.1].name()); + let message: String = account[&self.cursor_pos.1].status(); self.data_columns.columns[0] = CellBuffer::new_with_context(message.len(), self.length + 1, default_cell, context); write_string_to_grid( diff --git a/src/components/mail/listing/thread.rs b/src/components/mail/listing/thread.rs index b805e631..0cb85743 100644 --- a/src/components/mail/listing/thread.rs +++ b/src/components/mail/listing/thread.rs @@ -239,7 +239,7 @@ impl MailListingTrait for ThreadListing { ret }; if threads.len() == 0 { - let message = format!("Mailbox `{}` is empty.", account[&self.cursor_pos.1].name()); + let message: String = account[&self.cursor_pos.1].status(); self.data_columns.columns[0] = CellBuffer::new_with_context(message.len(), 1, default_cell, context); write_string_to_grid( diff --git a/src/conf/accounts.rs b/src/conf/accounts.rs index a5b4647f..b86c274b 100644 --- a/src/conf/accounts.rs +++ b/src/conf/accounts.rs @@ -117,9 +117,13 @@ pub struct MailboxEntry { impl MailboxEntry { pub fn status(&self) -> String { match self.status { - MailboxStatus::Available => self.name().to_string(), + MailboxStatus::Available => format!( + "{} [{} messages]", + self.name(), + self.ref_mailbox.count().ok().unwrap_or((0, 0)).1 + ), MailboxStatus::Failed(ref e) => e.to_string(), - MailboxStatus::None => "Retrieving mailbox".to_string(), + MailboxStatus::None => "Retrieving mailbox.".to_string(), MailboxStatus::Parsing(done, total) => { format!("Parsing messages. [{}/{}]", done, total) } @@ -572,7 +576,8 @@ impl Account { if entry.conf.mailbox_conf.autoload || entry.ref_mailbox.special_usage() == SpecialUsageMailbox::Inbox { - entry.status = MailboxStatus::Parsing(0, 0); + let total = entry.ref_mailbox.count().ok().unwrap_or((0, 0)).1; + entry.status = MailboxStatus::Parsing(0, total); if self.backend_capabilities.is_async { if let Ok(mailbox_job) = self.backend.write().unwrap().fetch_async(*h) { let mailbox_job = mailbox_job.into_future();