blob: 0a6e88321449cdc2d39b194b28986ce014509566 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
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<CountInfo> {
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(),
})
}
|