summaryrefslogtreecommitdiff
path: root/src/cmd.rs
blob: 576c9d42812df08a1d3aba6a94736e59cc74afca (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
use std::path::PathBuf;
use std::sync::RwLock;

use crate::de_jmhoffmann_jwebmail_mailstorage::*;
use maildir::Maildir;

mod add_folder;
mod folders;
mod init;
mod list;
mod r#move;
mod raw;
mod remove;
mod show;
mod stats;
mod search;

use add_folder::add_folder;
use folders::folders;
use init::init;
use list::list;
use r#move::r#move;
use raw::raw;
use remove::remove;
use show::show;
use stats::stats;
use search::search;

pub fn open_submaildir(mut path: PathBuf, sub: &str) -> Maildir {
    if !sub.is_empty() {
        path.push(String::from(".") + sub);
    }
    Maildir::from(path)
}

pub struct MailStorage {
    maildir_path: RwLock<Option<PathBuf>>,
}

impl Default for MailStorage {
    fn default() -> Self {
        MailStorage { maildir_path: RwLock::new(None) }
    }
}

impl VarlinkInterface for MailStorage {
    fn init(
        &self,
        call: &mut dyn Call_Init,
        unix_user: String,
        mailbox_path: String,
    ) -> varlink::Result<()> {
        init(self, call, unix_user, mailbox_path)
    }

    fn add_folder(&self, call: &mut dyn Call_AddFolder, name: String) -> varlink::Result<()> {
        add_folder(self, call, name)
    }

    fn stats(&self, call: &mut dyn Call_Stats, folder: String) -> varlink::Result<()> {
        stats(self, call, folder)
    }

    fn folders(&self, call: &mut dyn Call_Folders) -> varlink::Result<()> {
        folders(self, call)
    }

    fn list(
        &self,
        call: &mut dyn Call_List,
        folder: String,
        start: i64,
        end: i64,
        sort: Sort,
    ) -> varlink::Result<()> {
        list(self, call, folder, start, end, sort)
    }

    fn r#move(
        &self,
        call: &mut dyn Call_Move,
        mid: String,
        from_folder: String,
        to_folder: String,
    ) -> varlink::Result<()> {
        r#move(self, call, mid, from_folder, to_folder)
    }

    fn raw(
        &self,
        call: &mut dyn Call_Raw,
        folder: String,
        mid: String,
        path: Option<String>,
    ) -> varlink::Result<()> {
        raw(self, call, folder, mid, path)
    }

    fn remove(
        &self,
        call: &mut dyn Call_Remove,
        folder: String,
        mid: String,
    ) -> varlink::Result<()> {
        remove(self, call, folder, mid)
    }

    fn search(
        &self,
        call: &mut dyn Call_Search,
        folder: String,
        pattern: String,
    ) -> varlink::Result<()> {
        search(self, call, folder, pattern)
    }

    fn show(&self, call: &mut dyn Call_Show, folder: String, mid: String) -> varlink::Result<()> {
        show(self, call, folder, mid)
    }
}