jmap_client/sieve/
set.rs

1/*
2 * Copyright Stalwart Labs LLC See the COPYING
3 * file at the top-level directory of this distribution.
4 *
5 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
8 * option. This file may not be copied, modified, or distributed
9 * except according to those terms.
10 */
11
12use crate::{core::set::SetObject, Get, Set};
13
14use super::{SetArguments, SieveScript};
15
16impl SieveScript<Set> {
17    pub fn name(&mut self, name: impl Into<String>) -> &mut Self {
18        self.name = Some(name.into());
19        self
20    }
21
22    pub fn blob_id(&mut self, blob_id: impl Into<String>) -> &mut Self {
23        self.blob_id = Some(blob_id.into());
24        self
25    }
26}
27
28impl SetObject for SieveScript<Set> {
29    type SetArguments = SetArguments;
30
31    fn new(_create_id: Option<usize>) -> Self {
32        SieveScript {
33            _create_id,
34            _state: Default::default(),
35            id: None,
36            name: None,
37            blob_id: None,
38            is_active: None,
39        }
40    }
41
42    fn create_id(&self) -> Option<String> {
43        self._create_id.map(|id| format!("c{}", id))
44    }
45}
46
47impl SetArguments {
48    pub fn on_success_activate_script(&mut self, id: impl Into<String>) -> &mut Self {
49        self.on_success_activate_script = Some(format!("#{}", id.into()));
50        self
51    }
52
53    pub fn on_success_activate_script_id(&mut self, id: impl Into<String>) -> &mut Self {
54        self.on_success_activate_script = Some(id.into());
55        self
56    }
57
58    pub fn on_success_deactivate_script(&mut self, value: bool) -> &mut Self {
59        self.on_success_deactivate_script = Some(value);
60        self
61    }
62}
63
64impl SetObject for SieveScript<Get> {
65    type SetArguments = ();
66
67    fn new(_create_id: Option<usize>) -> Self {
68        unimplemented!()
69    }
70
71    fn create_id(&self) -> Option<String> {
72        None
73    }
74}