From b95f778335bebd480f69fe66fabec4f8a6e2b587 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Mon, 28 Aug 2023 12:44:04 +0300 Subject: [PATCH] melib/jmap: move JmapSession to its own module Signed-off-by: Manos Pitsidianakis --- melib/src/jmap/connection.rs | 6 ++-- melib/src/jmap/mod.rs | 5 ++- melib/src/jmap/rfc8620.rs | 52 +++------------------------ melib/src/jmap/session.rs | 69 ++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 52 deletions(-) create mode 100644 melib/src/jmap/session.rs diff --git a/melib/src/jmap/connection.rs b/melib/src/jmap/connection.rs index 543df1c6..57e6a501 100644 --- a/melib/src/jmap/connection.rs +++ b/melib/src/jmap/connection.rs @@ -28,7 +28,7 @@ use crate::error::NetworkErrorKind; #[derive(Debug)] pub struct JmapConnection { - pub session: Arc>, + pub session: Arc>, pub request_no: Arc>, pub client: Arc, pub server_conf: JmapServerConf, @@ -153,7 +153,7 @@ impl JmapConnection { Ok(s) => s, }; - let session: JmapSession = match deserialize_from_str(&res_text) { + let session: Session = match deserialize_from_str(&res_text) { Err(err) => { let err = Error::new(format!( "Could not connect to JMAP server endpoint for {}. Is your server url setting \ @@ -211,7 +211,7 @@ impl JmapConnection { self.session.lock().unwrap().primary_accounts[JMAP_MAIL_CAPABILITY].clone() } - pub fn session_guard(&'_ self) -> MutexGuard<'_, JmapSession> { + pub fn session_guard(&'_ self) -> MutexGuard<'_, Session> { self.session.lock().unwrap() } diff --git a/melib/src/jmap/mod.rs b/melib/src/jmap/mod.rs index 1ac04bf8..19f91365 100644 --- a/melib/src/jmap/mod.rs +++ b/melib/src/jmap/mod.rs @@ -79,6 +79,9 @@ use connection::*; pub mod protocol; use protocol::*; +pub mod session; +use session::*; + pub mod rfc8620; use rfc8620::*; @@ -197,7 +200,7 @@ pub struct Store { pub mailbox_state: Arc>>, pub online_status: Arc)>>, pub is_subscribed: Arc, - pub core_capabilities: Arc>>, + pub core_capabilities: Arc>>, pub event_consumer: BackendEventConsumer, } diff --git a/melib/src/jmap/rfc8620.rs b/melib/src/jmap/rfc8620.rs index 9e9c15dd..bd700d05 100644 --- a/melib/src/jmap/rfc8620.rs +++ b/melib/src/jmap/rfc8620.rs @@ -22,16 +22,16 @@ use std::{ hash::{Hash, Hasher}, marker::PhantomData, - sync::Arc, }; +use indexmap::IndexMap; use serde::{ de::DeserializeOwned, ser::{Serialize, SerializeStruct, Serializer}, }; use serde_json::{value::RawValue, Value}; -use crate::email::parser::BytesExt; +use crate::{email::parser::BytesExt, jmap::session::Session}; mod filters; pub use filters::*; @@ -39,8 +39,6 @@ mod comparator; pub use comparator::*; mod argument; pub use argument::*; -use indexmap::IndexMap; - pub type PatchObject = Value; impl Object for PatchObject { @@ -230,48 +228,6 @@ impl State { } } -#[derive(Deserialize, Serialize, Debug, Clone, Default)] -#[serde(rename_all = "camelCase")] -pub struct JmapSession { - pub capabilities: IndexMap, - pub accounts: IndexMap, Account>, - pub primary_accounts: IndexMap>, - pub username: String, - pub api_url: Arc, - pub download_url: Arc, - - pub upload_url: Arc, - pub event_source_url: Arc, - pub state: State, - #[serde(flatten)] - pub extra_properties: IndexMap, -} - -impl Object for JmapSession { - const NAME: &'static str = "Session"; -} - -#[derive(Deserialize, Serialize, Clone, Default, Debug)] -#[serde(rename_all = "camelCase")] -pub struct CapabilitiesObject { - #[serde(default)] - pub max_size_upload: u64, - #[serde(default)] - pub max_concurrent_upload: u64, - #[serde(default)] - pub max_size_request: u64, - #[serde(default)] - pub max_concurrent_requests: u64, - #[serde(default)] - pub max_calls_in_request: u64, - #[serde(default)] - pub max_objects_in_get: u64, - #[serde(default)] - pub max_objects_in_set: u64, - #[serde(default)] - pub collation_algorithms: Vec, -} - #[derive(Deserialize, Serialize, Clone, Debug)] #[serde(rename_all = "camelCase")] pub struct Account { @@ -284,7 +240,7 @@ pub struct Account { } impl Object for Account { - const NAME: &'static str = "Account"; + const NAME: &'static str = stringify!(Account); } #[derive(Copy, Clone, Debug)] @@ -441,7 +397,7 @@ pub struct MethodResponse<'a> { #[serde(default)] pub created_ids: IndexMap, Id>, #[serde(default)] - pub session_state: State, + pub session_state: State, } #[derive(Serialize, Deserialize, Clone, Debug)] diff --git a/melib/src/jmap/session.rs b/melib/src/jmap/session.rs new file mode 100644 index 00000000..38556c01 --- /dev/null +++ b/melib/src/jmap/session.rs @@ -0,0 +1,69 @@ +/* + * meli - jmap module. + * + * Copyright 2019 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 std::sync::Arc; + +use indexmap::IndexMap; +use serde_json::Value; + +use crate::jmap::rfc8620::{Account, Id, Object, State}; + +#[derive(Deserialize, Serialize, Debug, Clone, Default)] +#[serde(rename_all = "camelCase")] +pub struct Session { + pub capabilities: IndexMap, + pub accounts: IndexMap, Account>, + pub primary_accounts: IndexMap>, + pub username: String, + pub api_url: Arc, + pub download_url: Arc, + + pub upload_url: Arc, + pub event_source_url: Arc, + pub state: State, + #[serde(flatten)] + pub extra_properties: IndexMap, +} + +impl Object for Session { + const NAME: &'static str = stringify!(Session); +} + +#[derive(Deserialize, Serialize, Clone, Default, Debug)] +#[serde(rename_all = "camelCase")] +pub struct CapabilitiesObject { + #[serde(default)] + pub max_size_upload: u64, + #[serde(default)] + pub max_concurrent_upload: u64, + #[serde(default)] + pub max_size_request: u64, + #[serde(default)] + pub max_concurrent_requests: u64, + #[serde(default)] + pub max_calls_in_request: u64, + #[serde(default)] + pub max_objects_in_get: u64, + #[serde(default)] + pub max_objects_in_set: u64, + #[serde(default)] + pub collation_algorithms: Vec, +}