Skip to main content

io_jmap/rfc8621/identity/
types.rs

1//! JMAP Identity types (RFC 8621 §6).
2
3use alloc::{string::String, vec::Vec};
4use serde::{Deserialize, Serialize};
5
6use crate::rfc8621::email::JmapEmailAddress;
7
8/// A partial [`JmapIdentity`] object for `Identity/set` create requests.
9#[derive(Clone, Debug, Default, Serialize)]
10#[serde(rename_all = "camelCase")]
11pub struct JmapIdentityCreate {
12    pub name: String,
13    pub email: String,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub reply_to: Option<Vec<JmapEmailAddress>>,
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub bcc: Option<Vec<JmapEmailAddress>>,
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub text_signature: Option<String>,
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub html_signature: Option<String>,
22}
23
24/// Patch object for `Identity/set` update requests.
25///
26/// Only `Some` fields are serialized.
27#[derive(Clone, Debug, Default, Serialize)]
28#[serde(rename_all = "camelCase")]
29pub struct JmapIdentityUpdate {
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub name: Option<String>,
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub reply_to: Option<Vec<JmapEmailAddress>>,
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub bcc: Option<Vec<JmapEmailAddress>>,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub text_signature: Option<String>,
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub html_signature: Option<String>,
40}
41
42/// A JMAP Identity object (RFC 8621 §6.1).
43///
44/// An Identity describes a sender identity the user can send email
45/// from (name, email address, signature, etc.).
46#[derive(Clone, Debug, Serialize, Deserialize)]
47#[serde(rename_all = "camelCase")]
48pub struct JmapIdentity {
49    /// The server-assigned ID.
50    pub id: String,
51
52    /// The display name for the sender.
53    pub name: String,
54
55    /// The email address for the sender.
56    pub email: String,
57
58    /// `Reply-To` addresses to set on outgoing email.
59    pub reply_to: Option<Vec<JmapEmailAddress>>,
60
61    /// `Bcc` addresses to add to all outgoing email.
62    pub bcc: Option<Vec<JmapEmailAddress>>,
63
64    /// Plaintext signature to append to outgoing email.
65    pub text_signature: Option<String>,
66
67    /// HTML signature to append to outgoing email.
68    pub html_signature: Option<String>,
69
70    /// Whether the user may delete this identity.
71    #[serde(default)]
72    pub may_delete: bool,
73}
74
75/// Per-object error returned in `Identity/set` responses (RFC 8621 §6.4).
76#[derive(Clone, Debug, Deserialize)]
77#[serde(tag = "type", rename_all = "camelCase")]
78pub enum JmapIdentitySetItemError {
79    /// Standard set error (RFC 8620 §5.3): target id not found.
80    NotFound { description: Option<String> },
81    /// Standard set error (RFC 8620 §5.3): patch could not be applied.
82    InvalidPatch { description: Option<String> },
83    /// Standard set error (RFC 8620 §5.3): would destroy an object already
84    /// queued for destruction in the same request.
85    WillDestroy { description: Option<String> },
86    /// Standard set error (RFC 8620 §5.3): one or more properties were invalid.
87    InvalidProperties {
88        description: Option<String>,
89        #[serde(default)]
90        properties: Vec<String>,
91    },
92    /// Standard set error (RFC 8620 §5.3): tried to create/destroy a
93    /// server-managed singleton.
94    Singleton { description: Option<String> },
95    /// Catch-all for set errors not modelled above.
96    #[serde(other)]
97    Unknown,
98}