use std::path::Path; use crate::cmd::MailStorage; use crate::de_jmhoffmann_jwebmail_mailstorage::Call_Folders; fn is_mailsubdir(p: &Path) -> bool { if !p.is_dir() { return false; } if !p.file_name().map_or(false, |fname| { fname.len() > 1 && fname.to_string_lossy().starts_with('.') }) { return false; } let mut buf = p.to_owned(); buf.push("cur"); if !buf.is_dir() { return false; } buf.pop(); buf.push("new"); if !buf.is_dir() { return false; } buf.pop(); buf.push("tmp"); if !buf.is_dir() { return false; } true } pub fn folders(ms: &MailStorage, call: &mut dyn Call_Folders) -> varlink::Result<()> { if let Some(path) = &*ms.maildir_path.read().unwrap() { let mut subdirs: Vec<_> = path .read_dir() .map_err(varlink::map_context!())? .filter_map(|d| d.ok()) .filter(|d| is_mailsubdir(&d.path())) .filter_map(|d| Some(d.path().file_name()?.to_string_lossy()[1..].to_owned())) .collect(); subdirs.sort(); call.reply(subdirs) } else { call.reply_not_initialized() } }