jmap_client/sieve/
mod.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
12pub mod get;
13pub mod helpers;
14pub mod query;
15pub mod set;
16pub mod validate;
17
18use std::fmt::Display;
19
20use crate::core::changes::ChangesObject;
21use crate::core::Object;
22use crate::Get;
23use crate::Set;
24use serde::{Deserialize, Serialize};
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
27pub struct SieveScript<State = Get> {
28    #[serde(skip)]
29    _create_id: Option<usize>,
30
31    #[serde(skip)]
32    _state: std::marker::PhantomData<State>,
33
34    #[serde(rename = "id")]
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub id: Option<String>,
37
38    #[serde(rename = "name")]
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub name: Option<String>,
41
42    #[serde(rename = "blobId")]
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub blob_id: Option<String>,
45
46    #[serde(rename = "isActive")]
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub is_active: Option<bool>,
49}
50
51#[derive(Debug, Clone, Serialize, Default)]
52pub struct SetArguments {
53    #[serde(rename = "onSuccessActivateScript")]
54    #[serde(skip_serializing_if = "Option::is_none")]
55    on_success_activate_script: Option<String>,
56    #[serde(rename = "onSuccessDeactivateScript")]
57    #[serde(skip_serializing_if = "Option::is_none")]
58    on_success_deactivate_script: Option<bool>,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Copy)]
62pub enum Property {
63    #[serde(rename = "id")]
64    Id,
65    #[serde(rename = "name")]
66    Name,
67    #[serde(rename = "blobId")]
68    BlobId,
69    #[serde(rename = "isActive")]
70    IsActive,
71}
72
73impl Display for Property {
74    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
75        match self {
76            Property::Id => write!(f, "id"),
77            Property::Name => write!(f, "name"),
78            Property::BlobId => write!(f, "blobId"),
79            Property::IsActive => write!(f, "isActive"),
80        }
81    }
82}
83
84impl Object for SieveScript<Set> {
85    type Property = Property;
86
87    fn requires_account_id() -> bool {
88        true
89    }
90}
91
92impl Object for SieveScript<Get> {
93    type Property = Property;
94
95    fn requires_account_id() -> bool {
96        true
97    }
98}
99
100impl ChangesObject for SieveScript<Set> {
101    type ChangesResponse = ();
102}
103
104impl ChangesObject for SieveScript<Get> {
105    type ChangesResponse = ();
106}