Skip to main content

jmap_mail_types/
identity.rs

1//! RFC 8621 §6 Identity object.
2//!
3//! Provides [`Identity`] — stores information about an email address or domain
4//! the user may send from.
5
6use crate::email::EmailAddress;
7use jmap_types::Id;
8use serde::{Deserialize, Serialize};
9
10/// An RFC 8621 §6 Identity object.
11///
12/// Stores information about an email address or domain the user may send from.
13#[non_exhaustive]
14#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct Identity {
17    /// The id of the Identity (immutable; server-set).
18    pub id: Id,
19    /// The "From" name the client SHOULD use when creating a new Email
20    /// from this Identity.  Defaults to `""`.
21    pub name: String,
22    /// The "From" email address the client MUST use (immutable).
23    pub email: String,
24    /// The Reply-To value the client SHOULD set.  `null` if not set.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub reply_to: Option<Vec<EmailAddress>>,
27    /// The Bcc value the client SHOULD set.  `null` if not set.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub bcc: Option<Vec<EmailAddress>>,
30    /// Plaintext signature.  Defaults to `""`.
31    pub text_signature: String,
32    /// HTML snippet signature.  Defaults to `""`.
33    pub html_signature: String,
34    /// Whether the user may delete this Identity (server-set).
35    pub may_delete: bool,
36}
37
38impl Identity {
39    /// Construct an [`Identity`] from its three identifying fields.
40    ///
41    /// `name`, `text_signature`, and `html_signature` default to `""`.
42    /// `reply_to` and `bcc` default to `None`.
43    pub fn new(id: Id, email: impl Into<String>, may_delete: bool) -> Self {
44        Self {
45            id,
46            email: email.into(),
47            may_delete,
48            name: String::new(),
49            reply_to: None,
50            bcc: None,
51            text_signature: String::new(),
52            html_signature: String::new(),
53        }
54    }
55}