rusted_mail/api/
requests.rs1use super::Serialize;
4
5#[derive(Debug, Clone, Serialize)]
7#[serde(rename_all = "camelCase")]
8#[must_use]
9pub struct FetchOptions {
10 mailbox: String,
11 uid_set: String,
12 limit: usize,
13 include_preview: bool,
14}
15
16impl FetchOptions {
17 pub fn new(uid_set: impl Into<String>) -> Self {
19 Self {
20 mailbox: "INBOX".to_string(),
21 uid_set: uid_set.into(),
22 limit: 100,
23 include_preview: true,
24 }
25 }
26
27 pub fn mailbox(mut self, mailbox: impl Into<String>) -> Self {
29 self.mailbox = mailbox.into();
30 self
31 }
32
33 pub fn limit(mut self, limit: usize) -> Self {
35 self.limit = limit;
36 self
37 }
38
39 pub fn include_preview(mut self, include: bool) -> Self {
41 self.include_preview = include;
42 self
43 }
44}
45
46#[derive(Debug, Clone, Serialize)]
48#[serde(rename_all = "camelCase")]
49#[must_use]
50pub struct BodyOptions {
51 mailbox: String,
52 mark_seen: bool,
53 include_raw: bool,
54}
55
56impl Default for BodyOptions {
57 fn default() -> Self {
58 Self {
59 mailbox: "INBOX".to_string(),
60 mark_seen: false,
61 include_raw: false,
62 }
63 }
64}
65
66impl BodyOptions {
67 pub fn mailbox(mut self, mailbox: impl Into<String>) -> Self {
69 self.mailbox = mailbox.into();
70 self
71 }
72
73 pub fn mark_seen(mut self, mark_seen: bool) -> Self {
75 self.mark_seen = mark_seen;
76 self
77 }
78
79 pub fn include_raw(mut self, include_raw: bool) -> Self {
81 self.include_raw = include_raw;
82 self
83 }
84}
85
86#[derive(Debug, Clone, Serialize)]
88#[serde(rename_all = "camelCase")]
89#[must_use]
90pub struct SearchOptions {
91 mailbox: String,
92 query: String,
93 #[serde(skip_serializing_if = "Option::is_none")]
94 from: Option<String>,
95 #[serde(skip_serializing_if = "Option::is_none")]
96 to: Option<String>,
97 #[serde(skip_serializing_if = "Option::is_none")]
98 subject: Option<String>,
99 #[serde(skip_serializing_if = "Option::is_none")]
100 text: Option<String>,
101 #[serde(skip_serializing_if = "Option::is_none")]
102 seen: Option<bool>,
103}
104
105impl Default for SearchOptions {
106 fn default() -> Self {
107 Self {
108 mailbox: "INBOX".to_string(),
109 query: String::new(),
110 from: None,
111 to: None,
112 subject: None,
113 text: None,
114 seen: None,
115 }
116 }
117}
118
119impl SearchOptions {
120 pub fn new() -> Self {
122 Self::default()
123 }
124
125 pub fn mailbox(mut self, mailbox: impl Into<String>) -> Self {
127 self.mailbox = mailbox.into();
128 self
129 }
130
131 pub fn query(mut self, query: impl Into<String>) -> Self {
133 self.query = query.into();
134 self
135 }
136
137 pub fn from(mut self, value: impl Into<String>) -> Self {
139 self.from = Some(value.into());
140 self
141 }
142
143 pub fn to(mut self, value: impl Into<String>) -> Self {
145 self.to = Some(value.into());
146 self
147 }
148
149 pub fn subject(mut self, value: impl Into<String>) -> Self {
151 self.subject = Some(value.into());
152 self
153 }
154
155 pub fn text(mut self, value: impl Into<String>) -> Self {
157 self.text = Some(value.into());
158 self
159 }
160
161 pub fn seen(mut self, seen: bool) -> Self {
163 self.seen = Some(seen);
164 self
165 }
166}
167
168#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
170#[serde(rename_all = "camelCase")]
171pub struct MessageSet {
172 mailbox: String,
173 uid_set: String,
174}
175
176impl MessageSet {
177 #[must_use]
179 pub fn new(mailbox: impl Into<String>, uid_set: impl Into<String>) -> Self {
180 Self {
181 mailbox: mailbox.into(),
182 uid_set: uid_set.into(),
183 }
184 }
185
186 #[must_use]
188 pub fn mailbox(&self) -> &str {
189 &self.mailbox
190 }
191
192 #[must_use]
194 pub fn uids(&self) -> &str {
195 &self.uid_set
196 }
197}
198
199#[derive(Debug, Clone, Default, Serialize)]
201#[serde(rename_all = "camelCase")]
202#[must_use]
203pub struct JmapEmailQuery {
204 #[serde(skip_serializing_if = "Option::is_none")]
205 in_mailbox: Option<String>,
206 #[serde(skip_serializing_if = "Option::is_none")]
207 text: Option<String>,
208 #[serde(skip_serializing_if = "Option::is_none")]
209 from: Option<String>,
210 #[serde(skip_serializing_if = "Option::is_none")]
211 to: Option<String>,
212 #[serde(skip_serializing_if = "Option::is_none")]
213 subject: Option<String>,
214 #[serde(skip_serializing_if = "Option::is_none")]
215 has_attachment: Option<bool>,
216}
217
218impl JmapEmailQuery {
219 pub fn new() -> Self {
221 Self::default()
222 }
223
224 pub fn in_mailbox(mut self, id: impl Into<String>) -> Self {
226 self.in_mailbox = Some(id.into());
227 self
228 }
229
230 pub fn text(mut self, value: impl Into<String>) -> Self {
232 self.text = Some(value.into());
233 self
234 }
235
236 pub fn from(mut self, value: impl Into<String>) -> Self {
238 self.from = Some(value.into());
239 self
240 }
241
242 pub fn to(mut self, value: impl Into<String>) -> Self {
244 self.to = Some(value.into());
245 self
246 }
247
248 pub fn subject(mut self, value: impl Into<String>) -> Self {
250 self.subject = Some(value.into());
251 self
252 }
253
254 pub fn has_attachment(mut self, value: bool) -> Self {
256 self.has_attachment = Some(value);
257 self
258 }
259}