diff options
Diffstat (limited to 'src/cmd/stats.rs')
-rw-r--r-- | src/cmd/stats.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/cmd/stats.rs b/src/cmd/stats.rs new file mode 100644 index 0000000..e8e8325 --- /dev/null +++ b/src/cmd/stats.rs @@ -0,0 +1,25 @@ +use crate::cmd::{open_submaildir, MailStorage}; +use crate::de_jmhoffmann_jwebmail_mailstorage::Call_Stats; + +pub fn stats(ms: &MailStorage, call: &mut dyn Call_Stats, folder: String) -> varlink::Result<()> { + if let Some(maildir_path) = ms.maildir_path.read().unwrap().clone() { + let maildir = open_submaildir(maildir_path, &folder); + + let mail_count = maildir.count_cur() as i64; + let unread_count = maildir + .list_cur() + .filter(|x| x.as_ref().map_or(false, |z| !z.is_seen())) + .count() as i64; + let byte_size: u64 = maildir + .path() + .join("cur") + .read_dir() + .map_err(varlink::map_context!())? + .map(|x| x.map_or(0, |z| z.metadata().map_or(0, |y| y.len()))) + .sum(); + + call.reply(mail_count, unread_count, byte_size as i64) + } else { + call.reply_not_initialized() + } +} |