use std::path::PathBuf; use protobuf::Message; use crate::cmd::open_submaildir; use crate::error::Result; use crate::pb3::jwebmail::{StatsReq, StatsResp}; pub fn count(path: PathBuf, req: &[u8]) -> Result> { let r = StatsReq::parse_from_bytes(req)?; let md = open_submaildir(path, &r.folder); let mut resp = StatsResp::new(); resp.mail_count = md.count_cur() as u32; resp.unread_count = md .list_cur() .filter(|x| x.as_ref().map_or(false, |z| !z.is_seen())) .count() as u32; resp.byte_size = md .path() .join("cur") .read_dir()? .map(|x| x.map_or(0, |z| z.metadata().map_or(0, |y| y.len()))) .sum(); resp.write_to_bytes().map_err(|e| e.into()) }