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() } }