use maildir::Maildir; use serde::Serialize; use crate::error::Result; #[derive(Serialize)] pub struct CountInfo { total_mails: u32, byte_size: u64, unread_mails: u32, } pub fn count(md: &Maildir) -> Result { Ok(CountInfo { total_mails: md.count_cur() as u32, unread_mails: md .list_cur() .filter(|x| x.as_ref().map_or(false, |z| !z.is_seen())) .count() as u32, byte_size: md .path() .join("cur") .read_dir()? .map(|x| x.map_or(0, |z| z.metadata().map_or(0, |y| y.len()))) .sum(), }) }