use jmap_types::Id;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum MailboxRole {
Inbox,
Trash,
Sent,
Drafts,
Junk,
Archive,
Flagged,
Important,
All,
Other(String),
}
impl_string_enum!(MailboxRole, "a JMAP Mailbox role string",
"inbox" => Inbox,
"trash" => Trash,
"sent" => Sent,
"drafts" => Drafts,
"junk" => Junk,
"archive" => Archive,
"flagged" => Flagged,
"important" => Important,
"all" => All,
);
impl MailboxRole {
pub fn to_wire_str(&self) -> &str {
match self {
Self::Inbox => "inbox",
Self::Trash => "trash",
Self::Sent => "sent",
Self::Drafts => "drafts",
Self::Junk => "junk",
Self::Archive => "archive",
Self::Flagged => "flagged",
Self::Important => "important",
Self::All => "all",
Self::Other(s) => s.as_str(),
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MailboxRights {
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,
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Mailbox {
pub id: Id,
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub parent_id: Option<Id>,
#[serde(skip_serializing_if = "Option::is_none")]
pub role: Option<MailboxRole>,
pub sort_order: u32,
pub total_emails: u32,
pub unread_emails: u32,
pub total_threads: u32,
pub unread_threads: u32,
pub my_rights: MailboxRights,
pub is_subscribed: bool,
}
impl Mailbox {
#[allow(clippy::too_many_arguments)]
pub fn new(
id: Id,
name: impl Into<String>,
sort_order: u32,
total_emails: u32,
unread_emails: u32,
total_threads: u32,
unread_threads: u32,
my_rights: MailboxRights,
is_subscribed: bool,
) -> Self {
Self {
id,
name: name.into(),
sort_order,
total_emails,
unread_emails,
total_threads,
unread_threads,
my_rights,
is_subscribed,
parent_id: None,
role: None,
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MailboxFilterCondition {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub parent_id: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub role: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub has_any_role: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_subscribed: Option<bool>,
}