From 38bc1369cc136c482f48d1ed3172b7f510ff7762 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Mon, 28 Aug 2023 14:52:00 +0300 Subject: [PATCH] melib/jmap: add an Identity type. Signed-off-by: Manos Pitsidianakis --- melib/src/jmap/objects.rs | 3 + melib/src/jmap/objects/email.rs | 4 +- melib/src/jmap/objects/identity.rs | 122 +++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 melib/src/jmap/objects/identity.rs diff --git a/melib/src/jmap/objects.rs b/melib/src/jmap/objects.rs index cf9b715d..8f61de5f 100644 --- a/melib/src/jmap/objects.rs +++ b/melib/src/jmap/objects.rs @@ -29,3 +29,6 @@ pub use mailbox::*; mod thread; pub use thread::*; + +mod identity; +pub use identity::*; diff --git a/melib/src/jmap/objects/email.rs b/melib/src/jmap/objects/email.rs index f727b03b..5ab37f10 100644 --- a/melib/src/jmap/objects/email.rs +++ b/melib/src/jmap/objects/email.rs @@ -211,7 +211,7 @@ impl EmailObject { _impl!(get keywords, keywords: IndexMap); } -#[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, diff --git a/melib/src/jmap/objects/identity.rs b/melib/src/jmap/objects/identity.rs new file mode 100644 index 00000000..e4709565 --- /dev/null +++ b/melib/src/jmap/objects/identity.rs @@ -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 . + */ + +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, + + /// 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>, + + /// 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>, + + /// 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 "" 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 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 for IdentitySet { + const NAME: &'static str = "Identity/set"; +} + +#[derive(Serialize, Clone, Copy, Debug)] +#[serde(rename_all = "camelCase")] +pub struct IdentityChanges; + +impl Method for IdentityChanges { + const NAME: &'static str = "Identity/changes"; +}