jmap_client/principal/
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::{Principal, Type};
20
21#[derive(Serialize, Clone, Debug)]
22#[serde(untagged)]
23pub enum Filter {
24    Email {
25        #[serde(rename = "email")]
26        value: String,
27    },
28    Name {
29        #[serde(rename = "name")]
30        value: String,
31    },
32    DomainName {
33        #[serde(rename = "domainName")]
34        value: String,
35    },
36    Text {
37        #[serde(rename = "text")]
38        value: String,
39    },
40    Type {
41        #[serde(rename = "type")]
42        value: Type,
43    },
44    Timezone {
45        #[serde(rename = "timezone")]
46        value: String,
47    },
48    Members {
49        #[serde(rename = "members")]
50        value: String,
51    },
52    QuotaLt {
53        #[serde(rename = "quotaLowerThan")]
54        value: u32,
55    },
56    QuotaGt {
57        #[serde(rename = "quotaGreaterThan")]
58        value: u32,
59    },
60}
61
62#[derive(Serialize, Debug, Clone)]
63#[serde(tag = "property")]
64pub enum Comparator {
65    #[serde(rename = "type")]
66    Type,
67    #[serde(rename = "name")]
68    Name,
69    #[serde(rename = "email")]
70    Email,
71}
72
73impl Filter {
74    pub fn name(value: impl Into<String>) -> Self {
75        Filter::Name {
76            value: value.into(),
77        }
78    }
79
80    pub fn domain_name(value: impl Into<String>) -> Self {
81        Filter::DomainName {
82            value: value.into(),
83        }
84    }
85
86    pub fn email(value: impl Into<String>) -> Self {
87        Filter::Email {
88            value: value.into(),
89        }
90    }
91
92    pub fn text(value: impl Into<String>) -> Self {
93        Filter::Text {
94            value: value.into(),
95        }
96    }
97
98    pub fn timezone(value: impl Into<String>) -> Self {
99        Filter::Timezone {
100            value: value.into(),
101        }
102    }
103
104    pub fn members(value: impl Into<String>) -> Self {
105        Filter::Members {
106            value: value.into(),
107        }
108    }
109
110    pub fn ptype(value: Type) -> Self {
111        Filter::Type { value }
112    }
113
114    pub fn quota_lower_than(value: u32) -> Self {
115        Filter::QuotaLt { value }
116    }
117
118    pub fn quota_greater_than(value: u32) -> Self {
119        Filter::QuotaGt { value }
120    }
121}
122
123impl Comparator {
124    pub fn name() -> query::Comparator<Comparator> {
125        query::Comparator::new(Comparator::Name)
126    }
127
128    pub fn email() -> query::Comparator<Comparator> {
129        query::Comparator::new(Comparator::Email)
130    }
131
132    pub fn ptype() -> query::Comparator<Comparator> {
133        query::Comparator::new(Comparator::Type)
134    }
135}
136
137impl QueryObject for Principal<Set> {
138    type QueryArguments = ();
139
140    type Filter = Filter;
141
142    type Sort = Comparator;
143}