use core::fmt;
use alloc::string::{String, ToString};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
pub mod changes;
pub mod get;
pub mod query;
pub mod set;
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct JmapMailbox {
pub id: Option<String>,
pub name: Option<String>,
pub parent_id: Option<String>,
pub role: Option<JmapMailboxRole>,
#[serde(default)]
pub sort_order: u32,
#[serde(default)]
pub total_emails: u32,
#[serde(default)]
pub unread_emails: u32,
#[serde(default)]
pub total_threads: u32,
#[serde(default)]
pub unread_threads: u32,
#[serde(default)]
pub my_rights: JmapMailboxRights,
#[serde(default)]
pub is_subscribed: bool,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct JmapMailboxRights {
pub may_read_items: bool,
pub may_add_items: bool,
pub may_remove_items: bool,
pub may_set_seen: bool,
pub may_set_keywords: bool,
pub may_create_child: bool,
pub may_rename: bool,
pub may_delete: bool,
pub may_submit: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum JmapMailboxRole {
Inbox,
Archive,
Drafts,
Flagged,
Important,
Junk,
Sent,
Subscribed,
Trash,
Other(String),
}
impl fmt::Display for JmapMailboxRole {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Inbox => "inbox",
Self::Archive => "archive",
Self::Drafts => "drafts",
Self::Flagged => "flagged",
Self::Important => "important",
Self::Junk => "junk",
Self::Sent => "sent",
Self::Subscribed => "subscribed",
Self::Trash => "trash",
Self::Other(s) => s.as_str(),
})
}
}
impl Serialize for JmapMailboxRole {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_str(&self.to_string())
}
}
impl<'de> Deserialize<'de> for JmapMailboxRole {
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let s = String::deserialize(d)?;
Ok(match s.as_str() {
"inbox" => Self::Inbox,
"archive" => Self::Archive,
"drafts" => Self::Drafts,
"flagged" => Self::Flagged,
"important" => Self::Important,
"junk" => Self::Junk,
"sent" => Self::Sent,
"subscribed" => Self::Subscribed,
"trash" => Self::Trash,
_ => Self::Other(s),
})
}
}
#[derive(Clone, Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum JmapMailboxProperty {
Id,
Name,
ParentId,
Role,
SortOrder,
TotalEmails,
UnreadEmails,
TotalThreads,
UnreadThreads,
MyRights,
IsSubscribed,
}