use crate::{
jmap::{
methods::{Get, Set},
objects::{Id, Object},
protocol::Method,
},
MailboxHash,
};
impl Id<MailboxObject> {
pub fn into_hash(&self) -> MailboxHash {
MailboxHash::from_bytes(self.inner.as_bytes())
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MailboxObject {
pub id: Id<Self>,
pub is_subscribed: bool,
pub my_rights: JmapRights,
pub name: String,
pub parent_id: Option<Id<Self>>,
pub role: Option<String>,
pub sort_order: u64,
pub total_emails: u64,
pub total_threads: u64,
pub unread_emails: u64,
pub unread_threads: u64,
}
impl Object for MailboxObject {
const NAME: &'static str = "Mailbox";
const SERVER_SET_FIELDS: &'static [&'static str] = &[
"id",
"totalEmails",
"unreadEmails",
"unreadThreads",
"totalThreads",
"myRights",
];
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct JmapRights {
pub may_add_items: bool,
pub may_create_child: bool,
pub may_delete: bool,
pub may_read_items: bool,
pub may_remove_items: bool,
pub may_rename: bool,
pub may_set_keywords: bool,
pub may_set_seen: bool,
pub may_submit: bool,
}
impl Default for JmapRights {
fn default() -> Self {
Self {
may_add_items: true,
may_create_child: true,
may_delete: true,
may_read_items: true,
may_remove_items: true,
may_rename: true,
may_set_keywords: true,
may_set_seen: true,
may_submit: true,
}
}
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MailboxGet {
#[serde(flatten)]
pub get_call: Get<MailboxObject>,
}
impl MailboxGet {
pub fn new(get_call: Get<MailboxObject>) -> Self {
Self { get_call }
}
}
impl Method<MailboxObject> for MailboxGet {
const NAME: &'static str = "Mailbox/get";
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MailboxSet {
#[serde(flatten)]
pub set_call: Set<MailboxObject>,
#[serde(default, skip_serializing_if = "is_false")]
pub on_destroy_remove_emails: bool,
}
const fn is_false(v: &bool) -> bool {
!*v
}
impl MailboxSet {
pub fn new(set_call: Set<MailboxObject>) -> Self {
Self {
set_call,
on_destroy_remove_emails: false,
}
}
_impl!(on_destroy_remove_emails: bool);
}
impl Method<MailboxObject> for MailboxSet {
const NAME: &'static str = "Mailbox/set";
}