Skip to main content

jmap_mail_types/
backend.rs

1//! Property selector enums and [`jmap_types::JmapObject`] impls for RFC 8621 types.
2//!
3//! These are defined here so that `jmap-mail-server` can use them without
4//! violating the orphan rule (`JmapObject` is foreign but the mail types are
5//! local to this crate).
6
7use jmap_types::{GetObject, JmapObject, PatchObject, QueryObject, SetObject};
8
9// ---------------------------------------------------------------------------
10// Property selector enums (server-side; no serde required)
11// ---------------------------------------------------------------------------
12
13/// Property selector for [`crate::Mailbox`] `/get` and `/set`.
14#[non_exhaustive]
15#[derive(Debug, Clone, PartialEq, Eq, Hash)]
16pub enum MailboxProperty {
17    /// The `id` property (RFC 8621 §2).
18    Id,
19    /// The `name` property (RFC 8621 §2).
20    Name,
21    /// The `parentId` property (RFC 8621 §2).
22    ParentId,
23    /// The `role` property (RFC 8621 §2).
24    Role,
25    /// The `sortOrder` property (RFC 8621 §2).
26    SortOrder,
27    /// The `totalEmails` property (RFC 8621 §2).
28    TotalEmails,
29    /// The `unreadEmails` property (RFC 8621 §2).
30    UnreadEmails,
31    /// The `totalThreads` property (RFC 8621 §2).
32    TotalThreads,
33    /// The `unreadThreads` property (RFC 8621 §2).
34    UnreadThreads,
35    /// The `myRights` property (RFC 8621 §2).
36    MyRights,
37    /// The `isSubscribed` property (RFC 8621 §2).
38    IsSubscribed,
39}
40
41/// Property selector for [`crate::Thread`] `/get`.
42#[non_exhaustive]
43#[derive(Debug, Clone, PartialEq, Eq, Hash)]
44pub enum ThreadProperty {
45    /// The `id` property (RFC 8621 §3).
46    Id,
47    /// The `emailIds` property (RFC 8621 §3).
48    EmailIds,
49}
50
51/// Property selector for [`crate::Email`] `/get` and `/set`.
52#[non_exhaustive]
53#[derive(Debug, Clone, PartialEq, Eq, Hash)]
54pub enum EmailProperty {
55    /// The `id` property (RFC 8621 §4).
56    Id,
57    /// The `blobId` property (RFC 8621 §4).
58    BlobId,
59    /// The `threadId` property (RFC 8621 §4).
60    ThreadId,
61    /// The `mailboxIds` property (RFC 8621 §4).
62    MailboxIds,
63    /// The `keywords` property (RFC 8621 §4).
64    Keywords,
65    /// The `size` property (RFC 8621 §4).
66    Size,
67    /// The `receivedAt` property (RFC 8621 §4).
68    ReceivedAt,
69    /// The `messageId` property (RFC 8621 §4).
70    MessageId,
71    /// The `inReplyTo` property (RFC 8621 §4).
72    InReplyTo,
73    /// The `references` property (RFC 8621 §4).
74    References,
75    /// The `subject` property (RFC 8621 §4).
76    Subject,
77    /// The `from` property (RFC 8621 §4).
78    From,
79    /// The `to` property (RFC 8621 §4).
80    To,
81    /// The `cc` property (RFC 8621 §4).
82    Cc,
83    /// The `bcc` property (RFC 8621 §4).
84    Bcc,
85    /// The `replyTo` property (RFC 8621 §4).
86    ReplyTo,
87    /// The `sender` property (RFC 8621 §4).
88    Sender,
89    /// The `sentAt` property (RFC 8621 §4).
90    SentAt,
91    /// The `hasAttachment` property (RFC 8621 §4).
92    HasAttachment,
93    /// The `preview` property (RFC 8621 §4).
94    Preview,
95    /// The `bodyStructure` property (RFC 8621 §4).
96    BodyStructure,
97    /// The `textBody` property (RFC 8621 §4).
98    TextBody,
99    /// The `htmlBody` property (RFC 8621 §4).
100    HtmlBody,
101    /// The `attachments` property (RFC 8621 §4).
102    Attachments,
103    /// The `bodyValues` property (RFC 8621 §4).
104    BodyValues,
105    /// The `headers` property (RFC 8621 §4).
106    Headers,
107}
108
109/// Property selector for [`crate::Identity`] `/get` and `/set`.
110#[non_exhaustive]
111#[derive(Debug, Clone, PartialEq, Eq, Hash)]
112pub enum IdentityProperty {
113    /// The `id` property (RFC 8621 §6).
114    Id,
115    /// The `name` property (RFC 8621 §6).
116    Name,
117    /// The `email` property (RFC 8621 §6).
118    Email,
119    /// The `replyTo` property (RFC 8621 §6).
120    ReplyTo,
121    /// The `bcc` property (RFC 8621 §6).
122    Bcc,
123    /// The `textSignature` property (RFC 8621 §6).
124    TextSignature,
125    /// The `htmlSignature` property (RFC 8621 §6).
126    HtmlSignature,
127    /// The `mayDelete` property (RFC 8621 §6).
128    MayDelete,
129}
130
131/// Property selector for [`crate::EmailSubmission`] `/get` and `/set`.
132#[non_exhaustive]
133#[derive(Debug, Clone, PartialEq, Eq, Hash)]
134pub enum EmailSubmissionProperty {
135    /// The `id` property (RFC 8621 §7).
136    Id,
137    /// The `identityId` property (RFC 8621 §7).
138    IdentityId,
139    /// The `emailId` property (RFC 8621 §7).
140    EmailId,
141    /// The `threadId` property (RFC 8621 §7).
142    ThreadId,
143    /// The `envelope` property (RFC 8621 §7).
144    Envelope,
145    /// The `sendAt` property (RFC 8621 §7).
146    SendAt,
147    /// The `undoStatus` property (RFC 8621 §7).
148    UndoStatus,
149    /// The `deliveryStatus` property (RFC 8621 §7).
150    DeliveryStatus,
151    /// The `dsnBlobIds` property (RFC 8621 §7).
152    DsnBlobIds,
153    /// The `mdnBlobIds` property (RFC 8621 §7).
154    MdnBlobIds,
155}
156
157/// Property selector for [`crate::VacationResponse`] `/get` and `/set`.
158#[non_exhaustive]
159#[derive(Debug, Clone, PartialEq, Eq, Hash)]
160pub enum VacationResponseProperty {
161    /// The `id` property (RFC 8621 §8).
162    Id,
163    /// The `isEnabled` property (RFC 8621 §8).
164    IsEnabled,
165    /// The `fromDate` property (RFC 8621 §8).
166    FromDate,
167    /// The `toDate` property (RFC 8621 §8).
168    ToDate,
169    /// The `subject` property (RFC 8621 §8).
170    Subject,
171    /// The `textBody` property (RFC 8621 §8).
172    TextBody,
173    /// The `htmlBody` property (RFC 8621 §8).
174    HtmlBody,
175}
176
177/// Property selector for [`crate::SearchSnippet`] `/get`.
178#[non_exhaustive]
179#[derive(Debug, Clone, PartialEq, Eq, Hash)]
180pub enum SearchSnippetProperty {
181    /// The `emailId` property (RFC 8621 §5).
182    EmailId,
183    /// The `subject` property (RFC 8621 §5).
184    Subject,
185    /// The `preview` property (RFC 8621 §5).
186    Preview,
187}
188
189/// Property selector for [`crate::SieveScript`] `/get` and `/set`.
190#[cfg(feature = "sieve")]
191#[non_exhaustive]
192#[derive(Debug, Clone, PartialEq, Eq, Hash)]
193pub enum SieveScriptProperty {
194    /// The `id` property (RFC 9661).
195    Id,
196    /// The `name` property (RFC 9661).
197    Name,
198    /// The `blobId` property (RFC 9661).
199    BlobId,
200    /// The `isActive` property (RFC 9661).
201    IsActive,
202}
203
204// ---------------------------------------------------------------------------
205// JmapObject impls
206// ---------------------------------------------------------------------------
207
208impl JmapObject for crate::Mailbox {
209    const TYPE_NAME: &'static str = "Mailbox";
210    type Property = MailboxProperty;
211}
212
213impl GetObject for crate::Mailbox {}
214
215impl SetObject for crate::Mailbox {
216    type Patch = PatchObject;
217}
218
219impl QueryObject for crate::Mailbox {
220    type Filter = crate::MailboxFilterCondition;
221    type Comparator = serde_json::Value;
222}
223
224impl JmapObject for crate::Thread {
225    const TYPE_NAME: &'static str = "Thread";
226    type Property = ThreadProperty;
227}
228
229impl GetObject for crate::Thread {}
230
231impl JmapObject for crate::Email {
232    const TYPE_NAME: &'static str = "Email";
233    type Property = EmailProperty;
234}
235
236impl GetObject for crate::Email {}
237
238impl SetObject for crate::Email {
239    type Patch = PatchObject;
240}
241
242impl QueryObject for crate::Email {
243    type Filter = crate::EmailFilter;
244    type Comparator = crate::EmailComparator;
245}
246
247impl JmapObject for crate::Identity {
248    const TYPE_NAME: &'static str = "Identity";
249    type Property = IdentityProperty;
250}
251
252impl GetObject for crate::Identity {}
253
254impl SetObject for crate::Identity {
255    type Patch = PatchObject;
256}
257
258impl JmapObject for crate::EmailSubmission {
259    const TYPE_NAME: &'static str = "EmailSubmission";
260    type Property = EmailSubmissionProperty;
261}
262
263impl GetObject for crate::EmailSubmission {}
264
265impl SetObject for crate::EmailSubmission {
266    type Patch = PatchObject;
267}
268
269impl QueryObject for crate::EmailSubmission {
270    type Filter = crate::EmailSubmissionFilter;
271    type Comparator = serde_json::Value;
272}
273
274impl JmapObject for crate::VacationResponse {
275    const TYPE_NAME: &'static str = "VacationResponse";
276    type Property = VacationResponseProperty;
277}
278
279impl GetObject for crate::VacationResponse {}
280
281impl SetObject for crate::VacationResponse {
282    type Patch = PatchObject;
283}
284
285impl JmapObject for crate::SearchSnippet {
286    const TYPE_NAME: &'static str = "SearchSnippet";
287    type Property = SearchSnippetProperty;
288}
289
290#[cfg(feature = "sieve")]
291impl JmapObject for crate::sieve::SieveScript {
292    const TYPE_NAME: &'static str = "SieveScript";
293    type Property = SieveScriptProperty;
294}
295
296#[cfg(feature = "sieve")]
297impl GetObject for crate::sieve::SieveScript {}
298
299#[cfg(feature = "sieve")]
300impl SetObject for crate::sieve::SieveScript {
301    type Patch = PatchObject;
302}