blob: 797f4d6023768475ba9b28362382c08c453d7eb2 (
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
|
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<Vec<u8>> {
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())
}
|