blob: 1a77c6307126d397e6d0ac85e071bdaacea8591a (
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
28
29
30
31
32
33
34
35
36
37
|
use std::fs::create_dir;
use std::path::PathBuf;
use protobuf::Message as _;
use crate::error::Result;
use crate::pb3::jwebmail::{AddFolderReq, AddFolderResp};
pub fn add_folder(mut p: PathBuf, req: &[u8]) -> Result<Vec<u8>> {
let r = AddFolderReq::parse_from_bytes(req)?;
let mut resp = AddFolderResp::new();
let mut folder = ".".to_owned();
folder.push_str(&r.name);
p.push(folder);
if p.is_dir() {
resp.status = 1;
return resp.write_to_bytes().map_err(|e| e.into());
}
create_dir(p.clone())?;
p.push("tmp");
create_dir(p.clone())?;
p.pop();
p.push("new");
create_dir(p.clone())?;
p.pop();
p.push("cur");
create_dir(p)?;
resp.status = 0;
resp.write_to_bytes().map_err(|e| e.into())
}
|