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

pub fn r#move(
    ms: &MailStorage,
    call: &mut dyn Call_Move,
    mid: String,
    from_folder: String,
    to_folder: String,
) -> varlink::Result<()> {
    if let Some(p) = ms.maildir_path.read().unwrap().clone() {
        let from = open_submaildir(p.clone(), &from_folder);
        let to = open_submaildir(p, &to_folder);
        if from.move_to(&mid, &to).is_err() {
            // This is not neccessarily true!
            // The error needs to be investigated to find out the actual cause.
            //
            // Other plausible causes:
            //
            //   InvalidFolder(folder: from_folder)
            //   InvalidMid(folder: from_folder, mid: mid)
            //
            return call.reply_invalid_folder(to_folder);
        }
        call.reply()
    } else {
        call.reply_not_initialized()
    }
}