melib/jmap: add an Identity type.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/279/head
Manos Pitsidianakis 2023-08-28 14:52:00 +03:00
parent 5d8f07c805
commit 38bc1369cc
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
3 changed files with 127 additions and 2 deletions

View File

@ -29,3 +29,6 @@ pub use mailbox::*;
mod thread;
pub use thread::*;
mod identity;
pub use identity::*;

View File

@ -211,7 +211,7 @@ impl EmailObject {
_impl!(get keywords, keywords: IndexMap<String, bool>);
}
#[derive(Deserialize, Serialize, Debug, Default)]
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Header {
pub name: String,
@ -228,7 +228,7 @@ where
Ok(v.into_iter().map(|t| (t.name, t.value)).collect())
}
#[derive(Deserialize, Serialize, Debug, Default)]
#[derive(Deserialize, Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct EmailAddress {
pub email: String,

View File

@ -0,0 +1,122 @@
/*
* meli - jmap module.
*
* Copyright 2023 Manos Pitsidianakis
*
* This file is part of meli.
*
* meli is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* meli is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
use super::*;
/// # Identity
///
/// An *Identity* object stores information about an email address or domain the
/// user may send from.
#[derive(Deserialize, Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IdentityObject {
/// id: `Id` (immutable; server-set)
/// The id of the `Identity`.
pub id: Id<IdentityObject>,
/// name: `String` (default: "")
/// The "From" name the client SHOULD use when creating a new Email
/// from this Identity.
#[serde(default)]
pub name: String,
/// email: `String` (immutable)
/// The "From" email address the client MUST use when creating a new
/// Email from this Identity. If the "mailbox" part of the address
/// (the section before the "@") is the single character "*" (e.g.,
/// "*@example.com"), the client may use any valid address ending in
/// that domain (e.g., "[email protected]").
pub email: String,
/// replyTo: `EmailAddress[]|null` (default: null)
/// The Reply-To value the client SHOULD set when creating a new Email
/// from this Identity.
#[serde(default)]
pub reply_to: Option<Vec<EmailAddress>>,
/// bcc: `EmailAddress[]|null` (default: null)
/// The Bcc value the client SHOULD set when creating a new Email from
/// this Identity.
#[serde(default)]
pub bcc: Option<Vec<EmailAddress>>,
/// textSignature: `String` (default: "")
/// A signature the client SHOULD insert into new plaintext messages
// that will be sent from this Identity. Clients MAY ignore this
// and/or combine this with a client-specific signature preference.
#[serde(default)]
pub text_signature: String,
/// htmlSignature: `String` (default: "")
/// A signature the client SHOULD insert into new HTML messages that
/// will be sent from this Identity. This text MUST be an HTML
/// snippet to be inserted into the "<body></body>" section of the
/// HTML. Clients MAY ignore this and/or combine this with a client-
/// specific signature preference.
#[serde(default)]
pub html_signature: String,
/// mayDelete: `Boolean` (server-set)
/// Is the user allowed to delete this Identity? Servers may wish to
/// set this to false for the user's username or other default
/// address. Attempts to destroy an Identity with "mayDelete: false"
/// will be rejected with a standard "forbidden" SetError.
#[serde(skip_serializing)]
pub may_delete: bool,
}
impl Object for IdentityObject {
const NAME: &'static str = "Identity";
}
#[derive(Serialize, Clone, Copy, Debug)]
#[serde(rename_all = "camelCase")]
pub struct IdentityGet;
impl Method<IdentityObject> for IdentityGet {
const NAME: &'static str = "Identity/get";
}
// [ref:TODO]: implement `forbiddenFrom` error for Identity/set.
/// `IdentitySet` method.
///
/// ```text
/// This is a standard "/set" method as described in [RFC8620],
/// Section 5.3. The following extra SetError types are defined:
/// For "create":
/// o "forbiddenFrom": The user is not allowed to send from the address
/// given as the "email" property of the Identity.
/// ```
#[derive(Serialize, Clone, Copy, Debug)]
#[serde(rename_all = "camelCase")]
pub struct IdentitySet;
impl Method<IdentityObject> for IdentitySet {
const NAME: &'static str = "Identity/set";
}
#[derive(Serialize, Clone, Copy, Debug)]
#[serde(rename_all = "camelCase")]
pub struct IdentityChanges;
impl Method<IdentityObject> for IdentityChanges {
const NAME: &'static str = "Identity/changes";
}