summaryrefslogtreecommitdiff
path: root/src/cmd/remove.rs
blob: 2779add349e5d7c606d3210d73a74d8e7b6fb6cc (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 crate::cmd::{open_submaildir, MailStorage};
use crate::de_jmhoffmann_jwebmail_mailstorage::Call_Remove;

pub fn remove(
    ms: &MailStorage,
    call: &mut dyn Call_Remove,
    folder: String,
    mid: String,
) -> varlink::Result<()> {
    if let Some(p) = ms.maildir_path.read().unwrap().clone() {
        let md = open_submaildir(p, &folder);

        let res = md.delete(&mid);
        match res {
            Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
                call.reply_invalid_mid(folder, mid)
            }
            Err(e) => Err(varlink::context!(e, varlink::ErrorKind::from(&e))),
            Ok(()) => call.reply(),
        }
    } else {
        call.reply_not_initialized()
    }
}