use std::io::ErrorKind as IOErrKind; use std::path::PathBuf; use protobuf::Message as _; use crate::cmd::open_submaildir; use crate::error::Result; use crate::pb3::jwebmail::{ShowReq, ShowResp}; use crate::rfc822::parsed_mail_to_mail; pub fn read(path: PathBuf, req: &[u8]) -> Result> { let r = ShowReq::parse_from_bytes(req)?; let md = open_submaildir(path, &r.folder); md.add_flags(&r.mid, "S")?; let mut mail = md.find(&r.mid).ok_or_else(|| { std::io::Error::new(IOErrKind::NotFound, format!("mail {} not found", &r.mid)) })?; let mut resp = ShowResp::new(); resp.mail = Some(parsed_mail_to_mail(mail.parsed()?)?).into(); resp.write_to_bytes().map_err(|e| e.into()) }