jmap_client/sieve/
query.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 serde::Serialize;
13
14use crate::{
15    core::query::{self, QueryObject},
16    Set,
17};
18
19use super::SieveScript;
20
21#[derive(Serialize, Clone, Debug)]
22#[serde(untagged)]
23pub enum Filter {
24    Name {
25        #[serde(rename = "name")]
26        value: String,
27    },
28    IsActive {
29        #[serde(rename = "isActive")]
30        value: bool,
31    },
32}
33
34#[derive(Serialize, Debug, Clone)]
35#[serde(tag = "property")]
36pub enum Comparator {
37    #[serde(rename = "name")]
38    Name,
39    #[serde(rename = "isActive")]
40    IsActive,
41}
42
43impl Filter {
44    pub fn name(value: impl Into<String>) -> Self {
45        Filter::Name {
46            value: value.into(),
47        }
48    }
49
50    pub fn is_active(value: bool) -> Self {
51        Filter::IsActive { value }
52    }
53}
54
55impl Comparator {
56    pub fn name() -> query::Comparator<Comparator> {
57        query::Comparator::new(Comparator::Name)
58    }
59
60    pub fn is_active() -> query::Comparator<Comparator> {
61        query::Comparator::new(Comparator::IsActive)
62    }
63}
64
65impl QueryObject for SieveScript<Set> {
66    type QueryArguments = ();
67
68    type Filter = Filter;
69
70    type Sort = Comparator;
71}