jmap_client/identity/
mod.rs

1/*
2 * Copyright Stalwart Labs LLC See the COPYING
3 * file at the top-level directory of this distribution.
4 *
5 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
8 * option. This file may not be copied, modified, or distributed
9 * except according to those terms.
10 */
11
12pub mod get;
13pub mod helpers;
14pub mod set;
15
16use std::fmt::Display;
17
18use crate::core::changes::ChangesObject;
19use crate::core::set::list_not_set;
20use crate::core::Object;
21use crate::Set;
22use crate::{email::EmailAddress, Get};
23use serde::{Deserialize, Serialize};
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct Identity<State = Get> {
27    #[serde(skip)]
28    _create_id: Option<usize>,
29
30    #[serde(skip)]
31    _state: std::marker::PhantomData<State>,
32
33    #[serde(rename = "id")]
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub id: Option<String>,
36
37    #[serde(rename = "name")]
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub name: Option<String>,
40
41    #[serde(rename = "email")]
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub email: Option<String>,
44
45    #[serde(rename = "replyTo")]
46    #[serde(skip_serializing_if = "list_not_set")]
47    pub reply_to: Option<Vec<EmailAddress>>,
48
49    #[serde(rename = "bcc")]
50    #[serde(skip_serializing_if = "list_not_set")]
51    pub bcc: Option<Vec<EmailAddress>>,
52
53    #[serde(rename = "textSignature")]
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub text_signature: Option<String>,
56
57    #[serde(rename = "htmlSignature")]
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub html_signature: Option<String>,
60
61    #[serde(rename = "mayDelete")]
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub may_delete: Option<bool>,
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Copy)]
67pub enum Property {
68    #[serde(rename = "id")]
69    Id,
70    #[serde(rename = "name")]
71    Name,
72    #[serde(rename = "email")]
73    Email,
74    #[serde(rename = "replyTo")]
75    ReplyTo,
76    #[serde(rename = "bcc")]
77    Bcc,
78    #[serde(rename = "textSignature")]
79    TextSignature,
80    #[serde(rename = "htmlSignature")]
81    HtmlSignature,
82    #[serde(rename = "mayDelete")]
83    MayDelete,
84}
85
86impl Display for Property {
87    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
88        match self {
89            Property::Id => write!(f, "id"),
90            Property::Name => write!(f, "name"),
91            Property::Email => write!(f, "email"),
92            Property::ReplyTo => write!(f, "replyTo"),
93            Property::Bcc => write!(f, "bcc"),
94            Property::TextSignature => write!(f, "textSignature"),
95            Property::HtmlSignature => write!(f, "htmlSignature"),
96            Property::MayDelete => write!(f, "mayDelete"),
97        }
98    }
99}
100
101impl Object for Identity<Set> {
102    type Property = Property;
103
104    fn requires_account_id() -> bool {
105        true
106    }
107}
108
109impl Object for Identity<Get> {
110    type Property = Property;
111
112    fn requires_account_id() -> bool {
113        true
114    }
115}
116
117impl ChangesObject for Identity<Set> {
118    type ChangesResponse = ();
119}
120
121impl ChangesObject for Identity<Get> {
122    type ChangesResponse = ();
123}