io_jmap/rfc8621/
mailbox.rs1use core::fmt;
4
5use alloc::string::{String, ToString};
6
7use serde::{Deserialize, Deserializer, Serialize, Serializer};
8
9pub mod changes;
10pub mod get;
11pub mod query;
12pub mod set;
13
14#[derive(Clone, Debug, Default, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub struct JmapMailbox {
18 pub id: Option<String>,
20 pub name: Option<String>,
22 pub parent_id: Option<String>,
24 pub role: Option<JmapMailboxRole>,
26 #[serde(default)]
28 pub sort_order: u32,
29 #[serde(default)]
31 pub total_emails: u32,
32 #[serde(default)]
34 pub unread_emails: u32,
35 #[serde(default)]
37 pub total_threads: u32,
38 #[serde(default)]
40 pub unread_threads: u32,
41 #[serde(default)]
43 pub my_rights: JmapMailboxRights,
44 #[serde(default)]
46 pub is_subscribed: bool,
47}
48
49#[derive(Clone, Debug, Default, Serialize, Deserialize)]
51#[serde(rename_all = "camelCase")]
52pub struct JmapMailboxRights {
53 pub may_read_items: bool,
55 pub may_add_items: bool,
57 pub may_remove_items: bool,
59 pub may_set_seen: bool,
61 pub may_set_keywords: bool,
63 pub may_create_child: bool,
65 pub may_rename: bool,
67 pub may_delete: bool,
69 pub may_submit: bool,
71}
72
73#[derive(Clone, Debug, PartialEq, Eq)]
76pub enum JmapMailboxRole {
77 Inbox,
79 Archive,
81 Drafts,
83 Flagged,
85 Important,
87 Junk,
89 Sent,
91 Subscribed,
93 Trash,
95 Other(String),
97}
98
99impl fmt::Display for JmapMailboxRole {
100 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
101 f.write_str(match self {
102 Self::Inbox => "inbox",
103 Self::Archive => "archive",
104 Self::Drafts => "drafts",
105 Self::Flagged => "flagged",
106 Self::Important => "important",
107 Self::Junk => "junk",
108 Self::Sent => "sent",
109 Self::Subscribed => "subscribed",
110 Self::Trash => "trash",
111 Self::Other(s) => s.as_str(),
112 })
113 }
114}
115
116impl Serialize for JmapMailboxRole {
117 fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
118 s.serialize_str(&self.to_string())
119 }
120}
121
122impl<'de> Deserialize<'de> for JmapMailboxRole {
123 fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
124 let s = String::deserialize(d)?;
125 Ok(match s.as_str() {
126 "inbox" => Self::Inbox,
127 "archive" => Self::Archive,
128 "drafts" => Self::Drafts,
129 "flagged" => Self::Flagged,
130 "important" => Self::Important,
131 "junk" => Self::Junk,
132 "sent" => Self::Sent,
133 "subscribed" => Self::Subscribed,
134 "trash" => Self::Trash,
135 _ => Self::Other(s),
136 })
137 }
138}
139
140#[derive(Clone, Debug, Serialize)]
142#[serde(rename_all = "camelCase")]
143pub enum JmapMailboxProperty {
144 Id,
146 Name,
148 ParentId,
150 Role,
152 SortOrder,
154 TotalEmails,
156 UnreadEmails,
158 TotalThreads,
160 UnreadThreads,
162 MyRights,
164 IsSubscribed,
166}