jmap/rfc8620.rs: split to methods.rs and objects.rs

Split rfc8620 to two separate files.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/405/head
Manos Pitsidianakis 4 months ago
parent a78f3f261d
commit f7838b1ddf
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -21,10 +21,7 @@
use std::hash::Hash; use std::hash::Hash;
use crate::jmap::{ use crate::jmap::{methods::ResultField, objects::Object, protocol::Method};
protocol::Method,
rfc8620::{Object, ResultField},
};
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] #[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[serde(rename_all = "camelCase", untagged)] #[serde(rename_all = "camelCase", untagged)]

@ -27,7 +27,7 @@ use crate::{
jmap::{ jmap::{
email::EmailObject, email::EmailObject,
mailbox::{JmapRights, MailboxObject}, mailbox::{JmapRights, MailboxObject},
rfc8620::{Id, State}, objects::{Id, State},
}, },
Mailbox, MailboxHash, Mailbox, MailboxHash,
}; };

@ -21,7 +21,7 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use crate::jmap::rfc8620::Object; use crate::jmap::objects::Object;
#[derive(Clone, Debug, Serialize)] #[derive(Clone, Debug, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]

@ -42,11 +42,12 @@ use crate::{
filters::Filter, filters::Filter,
identity::{IdentityGet, IdentityObject, IdentitySet}, identity::{IdentityGet, IdentityObject, IdentitySet},
mailbox::MailboxObject, mailbox::MailboxObject,
protocol::{self, JmapMailCapability, Request}, methods::{
rfc8620::{ AddedItem, Changes, ChangesResponse, Get, GetResponse, MethodResponse, QueryChanges,
AddedItem, Changes, ChangesResponse, Get, GetResponse, Id, MethodResponse, QueryChangesResponse, ResultField, Set,
QueryChanges, QueryChangesResponse, ResultField, Set, State,
}, },
objects::{Id, State},
protocol::{self, JmapMailCapability, Request},
session::Session, session::Session,
JmapServerConf, Store, JmapServerConf, Store,
}, },

@ -32,11 +32,12 @@ use crate::{
deserialize_from_str, deserialize_from_str,
filters::{Filter, FilterCondition, FilterTrait}, filters::{Filter, FilterCondition, FilterTrait},
mailbox::MailboxObject, mailbox::MailboxObject,
protocol::Method, methods::{
rfc8620::{ bool_false, u64_zero, Changes, Get, Query, QueryChanges, QueryChangesResponse,
bool_false, u64_zero, BlobObject, Changes, Get, Id, Object, Query, QueryChanges, ResultField, Set,
QueryChangesResponse, ResultField, Set,
}, },
objects::{BlobObject, Id, Object},
protocol::Method,
thread::ThreadObject, thread::ThreadObject,
UtcDate, UtcDate,
}, },

@ -28,8 +28,8 @@ use crate::{
deserialize_from_str, deserialize_from_str,
email::EmailObject, email::EmailObject,
mailbox::MailboxObject, mailbox::MailboxObject,
objects::{Account, BlobObject, Id, State},
protocol::Method, protocol::Method,
rfc8620::{Account, BlobObject, Id, State},
thread::ThreadObject, thread::ThreadObject,
}, },
}; };
@ -141,33 +141,35 @@ pub enum EmailImportError {
/// `RFC5322`, or even just with the same Message-ID `RFC5322`, to /// `RFC5322`, or even just with the same Message-ID `RFC5322`, to
/// coexist within an account. In this case, it MUST reject attempts to /// coexist within an account. In this case, it MUST reject attempts to
/// import an Email considered to be a duplicate with an `alreadyExists` /// import an Email considered to be a duplicate with an `alreadyExists`
/// [`SetError`]. /// [`SetError`](crate::jmap::methods::SetError`).
AlreadyExists { AlreadyExists {
description: Option<String>, description: Option<String>,
/// An `existingId` property of type `Id` MUST be included on /// An `existingId` property of type `Id` MUST be included on
/// the [`SetError`] object with the id of the existing Email. If /// the [`SetError`](crate::jmap::methods::SetError`) object with the id
/// duplicates are allowed, the newly created Email object MUST /// of the existing Email. If duplicates are allowed, the newly
/// have a separate id and independent mutable properties to the /// created Email object MUST have a separate id and independent
/// existing object. /// mutable properties to the existing object.
existing_id: Id<EmailObject>, existing_id: Id<EmailObject>,
}, },
/// If the `blobId`, `mailboxIds`, or `keywords` properties are invalid /// If the `blobId`, `mailboxIds`, or `keywords` properties are invalid
/// (e.g., missing, wrong type, id not found), the server MUST reject the /// (e.g., missing, wrong type, id not found), the server MUST reject the
/// import with an `invalidProperties` [`SetError`]. /// import with an `invalidProperties`
/// [`SetError`](crate::jmap::methods::SetError`).
InvalidProperties { InvalidProperties {
description: Option<String>, description: Option<String>,
properties: Vec<String>, properties: Vec<String>,
}, },
/// If the Email cannot be imported because it would take the account /// If the Email cannot be imported because it would take the account
/// over quota, the import should be rejected with an `overQuota` /// over quota, the import should be rejected with an `overQuota`
/// [`SetError`]. /// [`SetError`](crate::jmap::methods::SetError`).
OverQuota { description: Option<String> }, OverQuota { description: Option<String> },
/// If the blob referenced is not a valid message `RFC5322`, the server /// If the blob referenced is not a valid message `RFC5322`, the server
/// MAY modify the message to fix errors (such as removing NUL octets or /// MAY modify the message to fix errors (such as removing NUL octets or
/// fixing invalid headers). If it does this, the `blobId` on the /// fixing invalid headers). If it does this, the `blobId` on the
/// response MUST represent the new representation and therefore be /// response MUST represent the new representation and therefore be
/// different to the `blobId` on the [`EmailImport`] object. Alternatively, /// different to the `blobId` on the [`EmailImport`] object. Alternatively,
/// the server MAY reject the import with an `invalidEmail` [`SetError`]. /// the server MAY reject the import with an `invalidEmail`
/// [`SetError`](crate::jmap::methods::SetError`).
InvalidEmail { description: Option<String> }, InvalidEmail { description: Option<String> },
/// An `ifInState` argument was supplied, and it does not match the current /// An `ifInState` argument was supplied, and it does not match the current
/// state. /// state.
@ -199,7 +201,8 @@ pub struct EmailImportResponse {
pub created: Option<IndexMap<Id<EmailObject>, EmailImportResult>>, pub created: Option<IndexMap<Id<EmailObject>, EmailImportResult>>,
/// o notCreated: `Id[SetError]|null` /// o notCreated: `Id[SetError]|null`
/// A map of the creation id to a [`SetError`] object for each Email that /// A map of the creation id to a
/// [`SetError`](crate::jmap::methods::SetError`) object for each Email that
/// failed to be created, or null if all successful. The possible /// failed to be created, or null if all successful. The possible
/// errors are defined above. /// errors are defined above.
pub not_created: Option<IndexMap<Id<EmailObject>, EmailImportError>>, pub not_created: Option<IndexMap<Id<EmailObject>, EmailImportError>>,

@ -21,7 +21,7 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use crate::jmap::rfc8620::Object; use crate::jmap::objects::Object;
pub trait FilterTrait<T>: Default + Send + Sync {} pub trait FilterTrait<T>: Default + Send + Sync {}

@ -21,8 +21,9 @@
use crate::jmap::{ use crate::jmap::{
email::EmailAddress, email::EmailAddress,
methods::{Changes, Get, Set},
objects::{Id, Object},
protocol::Method, protocol::Method,
rfc8620::{Changes, Get, Id, Object, Set},
}; };
/// # Identity /// # Identity
@ -38,27 +39,27 @@ pub struct IdentityObject {
/// name: `String` (default: "") /// name: `String` (default: "")
/// The "From" name the client SHOULD use when creating a new /// The "From" name the client SHOULD use when creating a new
/// [`Email`](EmailObject) from this Identity. /// [`Email`](crate::jmap::email::EmailObject) from this Identity.
#[serde(default)] #[serde(default)]
pub name: String, pub name: String,
/// email: `String` (immutable) /// email: `String` (immutable)
/// The "From" email address the client MUST use when creating a new /// The "From" email address the client MUST use when creating a new
/// [`Email`](EmailObject) from this Identity. If the "mailbox" part of the /// [`Email`](crate::jmap::email::EmailObject) from this Identity. If the
/// address (the section before the "@") is the single character "*" /// "mailbox" part of the address (the section before the "@") is the
/// (e.g., "*@example.com"), the client may use any valid address ending /// single character "*" (e.g., "*@example.com"), the client may use any
/// in that domain (e.g., "[email protected]"). /// valid address ending in that domain (e.g., "[email protected]").
pub email: String, pub email: String,
/// replyTo: `EmailAddress[]|null` (default: null) /// replyTo: `EmailAddress[]|null` (default: null)
/// The Reply-To value the client SHOULD set when creating a new /// The Reply-To value the client SHOULD set when creating a new
/// [`Email`](EmailObject) from this Identity. /// [`Email`](crate::jmap::email::EmailObject) from this Identity.
#[serde(default)] #[serde(default)]
pub reply_to: Option<Vec<EmailAddress>>, pub reply_to: Option<Vec<EmailAddress>>,
/// bcc: `EmailAddress[]|null` (default: null) /// bcc: `EmailAddress[]|null` (default: null)
/// The Bcc value the client SHOULD set when creating a new /// The Bcc value the client SHOULD set when creating a new
/// [`Email`](EmailObject) from this Identity. /// [`Email`](crate::jmap::email::EmailObject) from this Identity.
#[serde(default)] #[serde(default)]
pub bcc: Option<Vec<EmailAddress>>, pub bcc: Option<Vec<EmailAddress>>,
@ -82,7 +83,8 @@ pub struct IdentityObject {
/// Is the user allowed to delete this Identity? Servers may wish to /// Is the user allowed to delete this Identity? Servers may wish to
/// set this to `false` for the user's username or other default /// set this to `false` for the user's username or other default
/// address. Attempts to destroy an Identity with "mayDelete: false" /// address. Attempts to destroy an Identity with "mayDelete: false"
/// will be rejected with a standard "forbidden" [`SetError`]. /// will be rejected with a standard "forbidden"
/// [`crate::jmap::methods::SetError`].
#[serde(skip_serializing)] #[serde(skip_serializing)]
pub may_delete: bool, pub may_delete: bool,
} }
@ -106,7 +108,7 @@ impl Method<IdentityObject> for IdentityChanges {
/// ///
/// ```text /// ```text
/// This is a standard "/set" method as described in [RFC8620], /// This is a standard "/set" method as described in [RFC8620],
/// Section 5.3. The following extra [`SetError`] types are defined: /// Section 5.3. The following extra [`crate::jmap::methods::SetError`] types are defined:
/// For "create": /// For "create":
/// o "forbiddenFrom": The user is not allowed to send from the address /// o "forbiddenFrom": The user is not allowed to send from the address
/// given as the "email" property of the Identity. /// given as the "email" property of the Identity.

@ -21,8 +21,9 @@
use crate::{ use crate::{
jmap::{ jmap::{
methods::{Get, Set},
objects::{Id, Object},
protocol::Method, protocol::Method,
rfc8620::{Get, Id, Object, Set},
}, },
MailboxHash, MailboxHash,
}; };
@ -105,17 +106,19 @@ impl Method<MailboxObject> for MailboxGet {
/// Section 5.3 but with the following additional request argument: /// Section 5.3 but with the following additional request argument:
/// ///
/// ///
/// The following extra [`SetError`] types are defined: /// The following extra [`crate::jmap::methods::SetError`] types are defined:
/// ///
/// For `destroy`: /// For `destroy`:
/// ///
/// - `mailboxHasChild`: The [`Mailbox`](MailboxObject) still has at least one /// - `mailboxHasChild`: The [`Mailbox`](crate::jmap::mailbox::MailboxObject)
/// child [`Mailbox`](MailboxObject). The client MUST remove these before it /// still has at least one child
/// can delete the parent [`Mailbox`](MailboxObject). /// [`Mailbox`](crate::jmap::mailbox::MailboxObject). The client MUST remove
/// these before it can delete the parent
/// [`Mailbox`](crate::jmap::mailbox::MailboxObject).
/// ///
/// - `mailboxHasEmail`: The [`Mailbox`](MailboxObject) has at least one /// - `mailboxHasEmail`: The [`Mailbox`](crate::jmap::mailbox::MailboxObject)
/// [`Email`](EmailObject) assigned to it, and the `onDestroyRemoveEmails` /// has at least one [`Email`](crate::jmap::email::EmailObject) assigned to
/// argument was false. /// it, and the `onDestroyRemoveEmails` argument was false.
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct MailboxSet { pub struct MailboxSet {
@ -123,13 +126,16 @@ pub struct MailboxSet {
pub set_call: Set<MailboxObject>, pub set_call: Set<MailboxObject>,
/// onDestroyRemoveEmails: `Boolean` (default: false) /// onDestroyRemoveEmails: `Boolean` (default: false)
/// ///
/// If false, any attempt to destroy a [`Mailbox`](MailboxObject) that still /// If false, any attempt to destroy a
/// has [`Email`s](EmailObject) in it will be rejected with a /// [`Mailbox`](crate::jmap::mailbox::MailboxObject) that still
/// `mailboxHasEmail` [`SetError`]. If /// has [`Email`s](crate::jmap::email::EmailObject) in it will be rejected
/// true, any [`Email`s](EmailObject) that were in the /// with a `mailboxHasEmail` [`crate::jmap::methods::SetError`]. If
/// [`Mailbox`](MailboxObject) will be removed from it, and if in no /// true, any [`Email`s](crate::jmap::email::EmailObject) that were in the
/// other [`Mailbox`es](MailboxObject), they will be destroyed when the /// [`Mailbox`](crate::jmap::mailbox::MailboxObject) will be removed from
/// [`Mailbox`](MailboxObject) is destroyed. /// it, and if in no
/// other [`Mailbox`es](crate::jmap::mailbox::MailboxObject), they will be
/// destroyed when the [`Mailbox`](crate::jmap::mailbox::MailboxObject)
/// is destroyed.
#[serde(default)] #[serde(default)]
pub on_destroy_remove_emails: bool, pub on_destroy_remove_emails: bool,
} }

File diff suppressed because it is too large Load Diff

@ -88,10 +88,13 @@ use protocol::*;
pub mod session; pub mod session;
use session::*; use session::*;
pub mod rfc8620; pub mod objects;
use rfc8620::{ use objects::{BlobObject, Id, Object, State};
download_request_format, upload_request_format, BlobObject, Get, GetResponse, Id,
MethodResponse, Object, Query, QueryResponse, Set, SetResponse, State, UploadResponse, pub mod methods;
use methods::{
upload_request_format, Get, GetResponse, MethodResponse, Query, QueryResponse, Set,
SetResponse, UploadResponse,
}; };
pub mod backend_mailbox; pub mod backend_mailbox;

File diff suppressed because it is too large Load Diff

@ -25,7 +25,7 @@ use futures::lock::Mutex as FutureMutex;
use isahc::AsyncReadResponseExt; use isahc::AsyncReadResponseExt;
use crate::{ use crate::{
jmap::{connection::JmapConnection, download_request_format, Store}, jmap::{connection::JmapConnection, methods::download_request_format, Store},
BackendOp, EnvelopeHash, ResultFuture, BackendOp, EnvelopeHash, ResultFuture,
}; };

@ -42,7 +42,8 @@ use crate::{
email::{EmailFilterCondition, EmailGet, EmailObject, EmailQuery}, email::{EmailFilterCondition, EmailGet, EmailObject, EmailQuery},
filters::Filter, filters::Filter,
mailbox::{MailboxGet, MailboxObject}, mailbox::{MailboxGet, MailboxObject},
rfc8620::{Get, GetResponse, Id, MethodResponse, Object, Query, QueryResponse, State}, methods::{Get, GetResponse, MethodResponse, Query, QueryResponse},
objects::{Id, Object, State},
JmapConnection, Store, JmapConnection, Store,
}, },
Flag, LazyCountSet, MailboxHash, Flag, LazyCountSet, MailboxHash,

@ -27,8 +27,8 @@ use url::Url;
use crate::jmap::{ use crate::jmap::{
identity::IdentityObject, identity::IdentityObject,
objects::{Account, Id, Object, State},
protocol::JmapMailCapability, protocol::JmapMailCapability,
rfc8620::{Account, Id, Object, State},
}; };
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]

@ -27,8 +27,9 @@ use crate::jmap::{
argument::Argument, argument::Argument,
email::EmailObject, email::EmailObject,
identity::IdentityObject, identity::IdentityObject,
methods::Set,
objects::{Account, BlobObject, Id, Object, PatchObject},
protocol::Method, protocol::Method,
rfc8620::{Account, BlobObject, Id, Object, PatchObject, Set},
thread::ThreadObject, thread::ThreadObject,
}; };

@ -29,8 +29,8 @@ fn test_jmap_query() {
use crate::jmap::{ use crate::jmap::{
email::{EmailFilterCondition, EmailObject, EmailQuery}, email::{EmailFilterCondition, EmailObject, EmailQuery},
filters::Filter, filters::Filter,
methods::Query,
protocol::Request, protocol::Request,
rfc8620::Query,
}; };
let q: crate::search::Query = crate::search::Query::try_from( let q: crate::search::Query = crate::search::Query::try_from(
"subject:wah or (from:Manos and (subject:foo or subject:bar))", "subject:wah or (from:Manos and (subject:foo or subject:bar))",
@ -79,7 +79,7 @@ fn test_jmap_undo_status() {
use crate::jmap::{ use crate::jmap::{
email::EmailObject, email::EmailObject,
identity::IdentityObject, identity::IdentityObject,
rfc8620::{Account, Id}, objects::{Account, Id},
submission::{EmailSubmissionObject, UndoStatus}, submission::{EmailSubmissionObject, UndoStatus},
}; };
let account_id: Id<Account> = "blahblah".into(); let account_id: Id<Account> = "blahblah".into();
@ -143,7 +143,8 @@ fn test_jmap_email_submission_object() {
argument::Argument, argument::Argument,
email::{EmailImport, EmailObject}, email::{EmailImport, EmailObject},
identity::IdentityObject, identity::IdentityObject,
rfc8620::{Account, Id, ResultField}, methods::ResultField,
objects::{Account, Id},
submission::{EmailSubmissionObject, UndoStatus}, submission::{EmailSubmissionObject, UndoStatus},
}; };
let account_id: Id<Account> = "blahblah".into(); let account_id: Id<Account> = "blahblah".into();
@ -203,8 +204,9 @@ fn test_jmap_identity_methods() {
use crate::jmap::{ use crate::jmap::{
identity::{IdentityGet, IdentityObject, IdentitySet}, identity::{IdentityGet, IdentityObject, IdentitySet},
methods::Set,
objects::Id,
protocol::Request, protocol::Request,
rfc8620::{Id, Set},
}; };
let account_id = "blahblah"; let account_id = "blahblah";
let prev_seq = 33; let prev_seq = 33;
@ -284,8 +286,9 @@ fn test_jmap_argument_serde() {
argument::Argument, argument::Argument,
email::{EmailImport, EmailImportObject, EmailObject}, email::{EmailImport, EmailImportObject, EmailObject},
mailbox::MailboxObject, mailbox::MailboxObject,
methods::{ResultField, Set},
objects::{BlobObject, Id},
protocol::Request, protocol::Request,
rfc8620::{BlobObject, Id, ResultField, Set},
submission::{EmailSubmissionObject, EmailSubmissionSet}, submission::{EmailSubmissionObject, EmailSubmissionSet},
}; };

@ -23,8 +23,9 @@ use std::marker::PhantomData;
use crate::jmap::{ use crate::jmap::{
email::{EmailGet, EmailObject}, email::{EmailGet, EmailObject},
methods::{Changes, Get, ResultField},
objects::{Id, Object},
protocol::Method, protocol::Method,
rfc8620::{Changes, Get, Id, Object, ResultField},
}; };
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]

Loading…
Cancel
Save