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#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
17#[serde(rename_all = "camelCase")]
18pub struct JmapMailbox {
19 pub id: Option<String>,
21 pub name: Option<String>,
23 pub parent_id: Option<String>,
25 #[cfg_attr(feature = "schemars", schemars(with = "Option<String>"))]
27 pub role: Option<JmapMailboxRole>,
28 #[serde(default)]
30 pub sort_order: u32,
31 #[serde(default)]
33 pub total_emails: u32,
34 #[serde(default)]
36 pub unread_emails: u32,
37 #[serde(default)]
39 pub total_threads: u32,
40 #[serde(default)]
42 pub unread_threads: u32,
43 #[serde(default)]
45 pub my_rights: JmapMailboxRights,
46 #[serde(default)]
48 pub is_subscribed: bool,
49}
50
51#[derive(Clone, Debug, Default, Serialize, Deserialize)]
53#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
54#[serde(rename_all = "camelCase")]
55pub struct JmapMailboxRights {
56 pub may_read_items: bool,
58 pub may_add_items: bool,
60 pub may_remove_items: bool,
62 pub may_set_seen: bool,
64 pub may_set_keywords: bool,
66 pub may_create_child: bool,
68 pub may_rename: bool,
70 pub may_delete: bool,
72 pub may_submit: bool,
74}
75
76#[derive(Clone, Debug, PartialEq, Eq)]
79pub enum JmapMailboxRole {
80 Inbox,
82 Archive,
84 Drafts,
86 Flagged,
88 Important,
90 Junk,
92 Sent,
94 Subscribed,
96 Trash,
98 Other(String),
100}
101
102impl fmt::Display for JmapMailboxRole {
103 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
104 f.write_str(match self {
105 Self::Inbox => "inbox",
106 Self::Archive => "archive",
107 Self::Drafts => "drafts",
108 Self::Flagged => "flagged",
109 Self::Important => "important",
110 Self::Junk => "junk",
111 Self::Sent => "sent",
112 Self::Subscribed => "subscribed",
113 Self::Trash => "trash",
114 Self::Other(s) => s.as_str(),
115 })
116 }
117}
118
119impl Serialize for JmapMailboxRole {
120 fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
121 s.serialize_str(&self.to_string())
122 }
123}
124
125impl<'de> Deserialize<'de> for JmapMailboxRole {
126 fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
127 let s = String::deserialize(d)?;
128 Ok(match s.as_str() {
129 "inbox" => Self::Inbox,
130 "archive" => Self::Archive,
131 "drafts" => Self::Drafts,
132 "flagged" => Self::Flagged,
133 "important" => Self::Important,
134 "junk" => Self::Junk,
135 "sent" => Self::Sent,
136 "subscribed" => Self::Subscribed,
137 "trash" => Self::Trash,
138 _ => Self::Other(s),
139 })
140 }
141}
142
143#[derive(Clone, Debug, Serialize)]
145#[serde(rename_all = "camelCase")]
146pub enum JmapMailboxProperty {
147 Id,
149 Name,
151 ParentId,
153 Role,
155 SortOrder,
157 TotalEmails,
159 UnreadEmails,
161 TotalThreads,
163 UnreadThreads,
165 MyRights,
167 IsSubscribed,
169}