diff --git a/CHANGELOG.md b/CHANGELOG.md index e62964d..04054ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +jmap-client 0.2.1 +================================ +- Using maybe_async to reduce duplicate code. +- Added `accept_invalid_certs` option to builder. + jmap-client 0.2.0 ================================ - JMAP for Sieve Scripts support. diff --git a/Cargo.toml b/Cargo.toml index 811cf2f..57c5200 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "jmap-client" description = "JMAP client library for Rust" -version = "0.2.0" +version = "0.2.1" edition = "2018" authors = [ "Stalwart Labs Ltd. "] license = "Apache-2.0 OR MIT" @@ -12,8 +12,8 @@ categories = ["email"] readme = "README.md" [dependencies] -reqwest = { git = "https://github.com/stalwartlabs/reqwest.git", version = "0.11", default-features = false, features = ["rustls-tls"]} -tokio-tungstenite = { version = "0.17", features = ["rustls-tls-webpki-roots"], optional = true} +reqwest = { version = "0.11", default-features = false, features = ["rustls-tls"]} +tokio-tungstenite = { version = "0.18", features = ["rustls-tls-webpki-roots"], optional = true} tokio = { version = "1.16", default-features = false, features = ["io-util"], optional = true } futures-util = { version = "0.3", optional = true} async-stream = { version = "0.3", optional = true} @@ -23,13 +23,13 @@ chrono = { version = "0.4", features = ["serde"]} ahash = {version = "0.8", features = ["serde"]} parking_lot = "0.12" base64 = "0.13" +maybe-async = "0.2" [features] default = ["async"] async = ["futures-util", "async-stream", "reqwest/stream"] websockets = ["tokio", "tokio-tungstenite"] -blocking = ["reqwest/blocking"] -follow-trusted = [] +blocking = ["reqwest/blocking", "maybe-async/is_sync"] debug = [] [lib] diff --git a/examples/eventsource.rs b/examples/eventsource.rs index dfd09b5..5b156da 100644 --- a/examples/eventsource.rs +++ b/examples/eventsource.rs @@ -13,9 +13,12 @@ * except according to those terms. */ +#[cfg(feature = "async")] use futures_util::StreamExt; +#[cfg(feature = "async")] use jmap_client::{client::Client, TypeState}; +#[cfg(feature = "async")] async fn event_source() { // Connect to the JMAP server using Basic authentication let client = Client::new() @@ -58,5 +61,6 @@ async fn event_source() { } fn main() { + #[cfg(feature = "async")] let _c = event_source(); } diff --git a/examples/mailboxes.rs b/examples/mailboxes.rs index 4890d43..c3de469 100644 --- a/examples/mailboxes.rs +++ b/examples/mailboxes.rs @@ -13,11 +13,13 @@ * except according to those terms. */ +#[cfg(feature = "async")] use jmap_client::{ client::Client, mailbox::{query::Filter, Role}, }; +#[cfg(feature = "async")] async fn mailboxes() { // Connect to the JMAP server using Basic authentication let client = Client::new() @@ -65,5 +67,6 @@ async fn mailboxes() { } fn main() { + #[cfg(feature = "async")] let _c = mailboxes(); } diff --git a/examples/messages.rs b/examples/messages.rs index 5a2bd2b..4841508 100644 --- a/examples/messages.rs +++ b/examples/messages.rs @@ -13,6 +13,7 @@ * except according to those terms. */ +#[cfg(feature = "async")] use jmap_client::{ client::Client, core::query::Filter, @@ -20,6 +21,7 @@ use jmap_client::{ mailbox::{self, Role}, }; +#[cfg(feature = "async")] const TEST_MESSAGE: &[u8; 90] = br#"From: john@example.org To: jane@example.org Subject: Testing JMAP client @@ -27,6 +29,7 @@ Subject: Testing JMAP client This is a test. "#; +#[cfg(feature = "async")] async fn messages() { // Connect to the JMAP server using Basic authentication let client = Client::new() @@ -116,5 +119,6 @@ async fn messages() { } fn main() { + #[cfg(feature = "async")] let _c = messages(); } diff --git a/examples/result_reference.rs b/examples/result_reference.rs index 75aa4ae..6bcb596 100644 --- a/examples/result_reference.rs +++ b/examples/result_reference.rs @@ -13,8 +13,10 @@ * except according to those terms. */ +#[cfg(feature = "async")] use jmap_client::{client::Client, core::query, email, mailbox}; +#[cfg(feature = "async")] async fn result_reference() { // Connect to the JMAP server using Basic authentication let client = Client::new() @@ -97,5 +99,6 @@ async fn result_reference() { } fn main() { + #[cfg(feature = "async")] let _c = result_reference(); } diff --git a/src/blob/helpers.rs b/src/blob/helpers.rs index 8189b5d..aa89d5b 100644 --- a/src/blob/helpers.rs +++ b/src/blob/helpers.rs @@ -18,6 +18,7 @@ use crate::{ use super::copy::{CopyBlobRequest, CopyBlobResponse}; impl Client { + #[maybe_async::maybe_async] pub async fn blob_copy( &self, from_account_id: impl Into, @@ -34,6 +35,7 @@ impl Client { } impl Request<'_> { + #[maybe_async::maybe_async] pub fn copy_blob(&mut self, from_account_id: impl Into) -> &mut CopyBlobRequest { self.add_method_call( Method::CopyBlob, @@ -42,6 +44,7 @@ impl Request<'_> { .blob_copy_mut() } + #[maybe_async::maybe_async] pub async fn send_copy_blob(self) -> crate::Result { self.send_single().await } diff --git a/src/blob/helpers_blocking.rs b/src/blob/helpers_blocking.rs deleted file mode 100644 index b84ca1e..0000000 --- a/src/blob/helpers_blocking.rs +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright Stalwart Labs Ltd. See the COPYING - * file at the top-level directory of this distribution. - * - * Licensed under the Apache License, Version 2.0 or the MIT license - * , at your - * option. This file may not be copied, modified, or distributed - * except according to those terms. - */ - -use crate::{ - client::Client, - core::request::{Arguments, Request}, - Method, -}; - -use super::copy::{CopyBlobRequest, CopyBlobResponse}; - -impl Client { - pub fn blob_copy( - &self, - from_account_id: impl Into, - blob_id: impl Into, - ) -> crate::Result { - let blob_id = blob_id.into(); - let mut request = self.build(); - request.copy_blob(from_account_id).blob_id(&blob_id); - request.send_single::()?.copied(&blob_id) - } -} - -impl Request<'_> { - pub fn copy_blob(&mut self, from_account_id: impl Into) -> &mut CopyBlobRequest { - self.add_method_call( - Method::CopyBlob, - Arguments::blob_copy(self.params(Method::CopyBlob), from_account_id.into()), - ) - .blob_copy_mut() - } - - pub fn send_copy_blob(self) -> crate::Result { - self.send_single() - } -} diff --git a/src/blob/mod.rs b/src/blob/mod.rs index d9078a8..5b0d486 100644 --- a/src/blob/mod.rs +++ b/src/blob/mod.rs @@ -13,10 +13,7 @@ use crate::core::session::URLParser; pub mod copy; pub mod download; -#[cfg(feature = "async")] pub mod helpers; -#[cfg(feature = "blocking")] -pub mod helpers_blocking; pub mod upload; pub enum URLParameter { diff --git a/src/client.rs b/src/client.rs index 331aef2..1742f11 100644 --- a/src/client.rs +++ b/src/client.rs @@ -19,10 +19,15 @@ use std::{ }; use ahash::AHashSet; +#[cfg(feature = "blocking")] +use reqwest::blocking::{Client as HttpClient, Response}; use reqwest::{ header::{self}, redirect, }; +#[cfg(feature = "async")] +use reqwest::{Client as HttpClient, Response}; + use serde::de::DeserializeOwned; use crate::{ @@ -59,6 +64,7 @@ pub struct Client { headers: header::HeaderMap, default_account_id: String, timeout: u64, + accept_invalid_certs: bool, #[cfg(feature = "websockets")] pub(crate) authorization: String, @@ -70,6 +76,7 @@ pub struct ClientBuilder { credentials: Option, trusted_hosts: AHashSet, forwarded_for: Option, + accept_invalid_certs: bool, timeout: u64, } @@ -86,6 +93,7 @@ impl ClientBuilder { trusted_hosts: AHashSet::new(), timeout: DEFAULT_TIMEOUT_MS, forwarded_for: None, + accept_invalid_certs: false, } } @@ -99,6 +107,11 @@ impl ClientBuilder { self } + pub fn accept_invalid_certs(mut self, accept_invalid_certs: bool) -> Self { + self.accept_invalid_certs = accept_invalid_certs; + self + } + pub fn follow_redirects( mut self, trusted_hosts: impl IntoIterator>, @@ -115,7 +128,7 @@ impl ClientBuilder { self } - #[cfg(feature = "async")] + #[maybe_async::maybe_async] pub async fn connect(self, url: &str) -> crate::Result { let authorization = match self.credentials.expect("Missing credentials") { Credentials::Basic(s) => format!("Basic {}", s), @@ -143,22 +156,15 @@ impl ClientBuilder { let session_url = format!("{}/.well-known/jmap", url); let session: Session = serde_json::from_slice( &Client::handle_error( - reqwest::Client::builder() + HttpClient::builder() .timeout(Duration::from_millis(self.timeout)) + .danger_accept_invalid_certs(self.accept_invalid_certs) .redirect(redirect::Policy::custom(move |attempt| { if attempt.previous().len() > 5 { attempt.error("Too many redirects.") } else if matches!( attempt.url().host_str(), Some(host) if trusted_hosts_.contains(host) ) { - #[cfg(feature = "follow-trusted")] - { - attempt.follow_trusted() - } - - #[cfg(not(feature = "follow-trusted"))] - { attempt.follow() - } } else { let message = format!( "Aborting redirect request to unknown host '{}'.", @@ -198,90 +204,7 @@ impl ClientBuilder { session: parking_lot::Mutex::new(Arc::new(session)), session_url, session_updated: true.into(), - trusted_hosts, - #[cfg(feature = "websockets")] - authorization, - timeout: self.timeout, - headers, - default_account_id, - #[cfg(feature = "websockets")] - ws: None.into(), - }) - } - - #[cfg(feature = "blocking")] - pub fn connect(self, url: &str) -> crate::Result { - let authorization = match self.credentials.expect("Missing credentials") { - Credentials::Basic(s) => format!("Basic {}", s), - Credentials::Bearer(s) => format!("Bearer {}", s), - }; - let mut headers = header::HeaderMap::new(); - headers.insert( - header::USER_AGENT, - header::HeaderValue::from_static(USER_AGENT), - ); - headers.insert( - header::AUTHORIZATION, - header::HeaderValue::from_str(&authorization).unwrap(), - ); - if let Some(forwarded_for) = self.forwarded_for { - headers.insert( - header::FORWARDED, - header::HeaderValue::from_str(&forwarded_for).unwrap(), - ); - } - - let trusted_hosts = Arc::new(self.trusted_hosts); - - let trusted_hosts_ = trusted_hosts.clone(); - let session_url = format!("{}/.well-known/jmap", url); - let session: Session = serde_json::from_slice( - &Client::handle_error( - reqwest::blocking::Client::builder() - .timeout(Duration::from_millis(self.timeout)) - .redirect(redirect::Policy::custom(move |attempt| { - if attempt.previous().len() > 5 { - attempt.error("Too many redirects.") - } else if matches!( attempt.url().host_str(), Some(host) if trusted_hosts_.contains(host) ) - { - attempt.follow_trusted() - } else { - let message = format!( - "Aborting redirect request to unknown host '{}'.", - attempt.url().host_str().unwrap_or("") - ); - attempt.error(message) - } - })) - .default_headers(headers.clone()) - .build()? - .get(&session_url) - .send() - ?, - )? - .bytes()?, - )?; - - let default_account_id = session - .primary_accounts() - .next() - .map(|a| a.1.to_string()) - .unwrap_or_default(); - - headers.insert( - header::CONTENT_TYPE, - header::HeaderValue::from_static("application/json"), - ); - - Ok(Client { - download_url: URLPart::parse(session.download_url())?, - upload_url: URLPart::parse(session.upload_url())?, - #[cfg(feature = "async")] - event_source_url: URLPart::parse(session.event_source_url())?, - api_url: session.api_url().to_string(), - session: parking_lot::Mutex::new(Arc::new(session)), - session_url, - session_updated: true.into(), + accept_invalid_certs: self.accept_invalid_certs, trusted_hosts, #[cfg(feature = "websockets")] authorization, @@ -336,15 +259,7 @@ impl Client { attempt.error("Too many redirects.") } else if matches!( attempt.url().host_str(), Some(host) if trusted_hosts.contains(host) ) { - #[cfg(feature = "follow-trusted")] - { - attempt.follow_trusted() - } - - #[cfg(not(feature = "follow-trusted"))] - { - attempt.follow() - } + attempt.follow() } else { let message = format!( "Aborting redirect request to unknown host '{}'.", @@ -355,7 +270,7 @@ impl Client { }) } - #[cfg(feature = "async")] + #[maybe_async::maybe_async] pub async fn send( &self, request: &request::Request<'_>, @@ -365,8 +280,9 @@ impl Client { { let response: response::Response = serde_json::from_slice( &Client::handle_error( - reqwest::Client::builder() + HttpClient::builder() .redirect(self.redirect_policy()) + .danger_accept_invalid_certs(self.accept_invalid_certs) .timeout(Duration::from_millis(self.timeout)) .default_headers(self.headers.clone()) .build()? @@ -387,37 +303,11 @@ impl Client { Ok(response) } - #[cfg(feature = "blocking")] - pub fn send(&self, request: &request::Request<'_>) -> crate::Result> - where - R: DeserializeOwned, - { - let response: response::Response = serde_json::from_slice( - &Client::handle_error( - reqwest::blocking::Client::builder() - .redirect(self.redirect_policy()) - .timeout(Duration::from_millis(self.timeout)) - .default_headers(self.headers.clone()) - .build()? - .post(&self.api_url) - .body(serde_json::to_string(&request)?) - .send()?, - )? - .bytes()?, - )?; - - if response.session_state() != self.session.lock().state() { - self.session_updated.store(false, Ordering::Relaxed); - } - - Ok(response) - } - - #[cfg(feature = "async")] + #[maybe_async::maybe_async] pub async fn refresh_session(&self) -> crate::Result<()> { let session: Session = serde_json::from_slice( &Client::handle_error( - reqwest::Client::builder() + HttpClient::builder() .timeout(Duration::from_millis(DEFAULT_TIMEOUT_MS)) .redirect(self.redirect_policy()) .default_headers(self.headers.clone()) @@ -435,25 +325,6 @@ impl Client { Ok(()) } - #[cfg(feature = "blocking")] - pub async fn refresh_session(&self) -> crate::Result<()> { - let session: Session = serde_json::from_slice( - &Client::handle_error( - reqwest::blocking::Client::builder() - .timeout(Duration::from_millis(DEFAULT_TIMEOUT_MS)) - .redirect(self.redirect_policy()) - .default_headers(self.headers.clone()) - .build()? - .get(&self.session_url) - .send()?, - )? - .bytes()?, - )?; - *self.session.lock() = Arc::new(session); - self.session_updated.store(true, Ordering::Relaxed); - Ok(()) - } - pub fn is_session_updated(&self) -> bool { self.session_updated.load(Ordering::Relaxed) } @@ -484,8 +355,8 @@ impl Client { &self.event_source_url } - #[cfg(feature = "async")] - pub async fn handle_error(response: reqwest::Response) -> crate::Result { + #[maybe_async::maybe_async] + pub async fn handle_error(response: Response) -> crate::Result { if response.status().is_success() { Ok(response) } else if let Some(b"application/problem+json") = response @@ -500,23 +371,6 @@ impl Client { Err(Error::Server(format!("{}", response.status()))) } } - - #[cfg(feature = "blocking")] - pub fn handle_error( - response: reqwest::blocking::Response, - ) -> crate::Result { - if response.status().is_success() { - Ok(response) - } else if let Some(b"application/problem+json") = response - .headers() - .get(header::CONTENT_TYPE) - .map(|h| h.as_bytes()) - { - Err(Error::Problem(serde_json::from_slice(&response.bytes()?)?)) - } else { - Err(Error::Server(format!("{}", response.status()))) - } - } } impl Credentials { @@ -555,7 +409,7 @@ impl From<(String, String)> for Credentials { #[cfg(test)] mod tests { - use crate::core::{response::{Response, TaggedMethodResponse}}; + use crate::core::response::{Response, TaggedMethodResponse}; #[test] fn test_deserialize() { diff --git a/src/email/helpers.rs b/src/email/helpers.rs index d828293..9714124 100644 --- a/src/email/helpers.rs +++ b/src/email/helpers.rs @@ -32,6 +32,7 @@ use super::{ }; impl Client { + #[maybe_async::maybe_async] pub async fn email_import( &self, raw_message: Vec, @@ -55,6 +56,7 @@ impl Client { .await } + #[maybe_async::maybe_async] pub async fn email_import_account( &self, account_id: &str, @@ -92,6 +94,7 @@ impl Client { .created(&id) } + #[maybe_async::maybe_async] pub async fn email_set_mailbox( &self, id: &str, @@ -103,6 +106,7 @@ impl Client { request.send_single::().await?.updated(id) } + #[maybe_async::maybe_async] pub async fn email_set_mailboxes( &self, id: &str, @@ -117,6 +121,7 @@ impl Client { request.send_single::().await?.updated(id) } + #[maybe_async::maybe_async] pub async fn email_set_keyword( &self, id: &str, @@ -128,6 +133,7 @@ impl Client { request.send_single::().await?.updated(id) } + #[maybe_async::maybe_async] pub async fn email_set_keywords( &self, id: &str, @@ -142,6 +148,7 @@ impl Client { request.send_single::().await?.updated(id) } + #[maybe_async::maybe_async] pub async fn email_destroy(&self, id: &str) -> crate::Result<()> { let mut request = self.build(); request.set_email().destroy([id]); @@ -151,6 +158,7 @@ impl Client { .destroyed(id) } + #[maybe_async::maybe_async] pub async fn email_get( &self, id: &str, @@ -167,6 +175,7 @@ impl Client { .map(|mut r| r.take_list().pop()) } + #[maybe_async::maybe_async] pub async fn email_changes( &self, since_state: impl Into, @@ -180,6 +189,7 @@ impl Client { request.send_single().await } + #[maybe_async::maybe_async] pub async fn email_query( &self, filter: Option>>, @@ -196,6 +206,7 @@ impl Client { request.send_single::().await } + #[maybe_async::maybe_async] pub async fn email_query_changes( &self, since_query_state: impl Into, @@ -209,6 +220,7 @@ impl Client { request.send_single::().await } + #[maybe_async::maybe_async] pub async fn email_parse( &self, blob_id: &str, @@ -238,6 +250,7 @@ impl Client { .and_then(|mut r| r.parsed(blob_id)) } + #[maybe_async::maybe_async] pub async fn email_copy( &self, from_account_id: impl Into, @@ -273,6 +286,7 @@ impl Client { .created(&id) } + #[maybe_async::maybe_async] pub async fn search_snippet_get( &self, filter: Option>>, @@ -297,6 +311,7 @@ impl Request<'_> { .email_get_mut() } + #[maybe_async::maybe_async] pub async fn send_get_email(self) -> crate::Result { self.send_single().await } @@ -309,6 +324,7 @@ impl Request<'_> { .changes_mut() } + #[maybe_async::maybe_async] pub async fn send_changes_email(self) -> crate::Result>> { self.send_single().await } @@ -321,6 +337,7 @@ impl Request<'_> { .email_query_mut() } + #[maybe_async::maybe_async] pub async fn send_query_email(self) -> crate::Result { self.send_single().await } @@ -339,6 +356,7 @@ impl Request<'_> { .email_query_changes_mut() } + #[maybe_async::maybe_async] pub async fn send_query_email_changes(self) -> crate::Result { self.send_single().await } @@ -351,6 +369,7 @@ impl Request<'_> { .email_set_mut() } + #[maybe_async::maybe_async] pub async fn send_set_email(self) -> crate::Result { self.send_single().await } @@ -366,6 +385,7 @@ impl Request<'_> { .email_copy_mut() } + #[maybe_async::maybe_async] pub async fn send_copy_email(self) -> crate::Result { self.send_single().await } @@ -378,6 +398,7 @@ impl Request<'_> { .email_import_mut() } + #[maybe_async::maybe_async] pub async fn send_import_email(self) -> crate::Result { self.send_single().await } @@ -390,6 +411,7 @@ impl Request<'_> { .email_parse_mut() } + #[maybe_async::maybe_async] pub async fn send_parse_email(self) -> crate::Result { self.send_single().await } @@ -402,6 +424,7 @@ impl Request<'_> { .search_snippet_get_mut() } + #[maybe_async::maybe_async] pub async fn send_get_search_snippet(self) -> crate::Result { self.send_single().await } diff --git a/src/email/helpers_blocking.rs b/src/email/helpers_blocking.rs deleted file mode 100644 index 02089b8..0000000 --- a/src/email/helpers_blocking.rs +++ /dev/null @@ -1,392 +0,0 @@ -/* - * Copyright Stalwart Labs Ltd. See the COPYING - * file at the top-level directory of this distribution. - * - * Licensed under the Apache License, Version 2.0 or the MIT license - * , at your - * option. This file may not be copied, modified, or distributed - * except according to those terms. - */ - -use crate::{ - client::Client, - core::{ - changes::{ChangesRequest, ChangesResponse}, - copy::CopyRequest, - get::GetRequest, - query::{Comparator, Filter, QueryRequest, QueryResponse}, - query_changes::{QueryChangesRequest, QueryChangesResponse}, - request::{Arguments, Request}, - response::{EmailCopyResponse, EmailGetResponse, EmailSetResponse}, - set::SetRequest, - }, - Get, Method, Set, -}; - -use super::{ - import::{EmailImportRequest, EmailImportResponse}, - parse::{EmailParseRequest, EmailParseResponse}, - search_snippet::{SearchSnippetGetRequest, SearchSnippetGetResponse}, - BodyProperty, Email, Property, -}; - -impl Client { - pub fn email_import( - &self, - raw_message: Vec, - mailbox_ids: T, - keywords: Option, - received_at: Option, - ) -> crate::Result - where - T: IntoIterator, - U: Into, - V: IntoIterator, - W: Into, - { - self.email_import_account( - self.default_account_id(), - raw_message, - mailbox_ids, - keywords, - received_at, - ) - } - - pub fn email_import_account( - &self, - account_id: &str, - raw_message: Vec, - mailbox_ids: T, - keywords: Option, - received_at: Option, - ) -> crate::Result - where - T: IntoIterator, - U: Into, - V: IntoIterator, - W: Into, - { - let blob_id = self.upload(None, raw_message, None)?.take_blob_id(); - let mut request = self.build(); - let import_request = request - .import_email() - .account_id(account_id) - .email(blob_id) - .mailbox_ids(mailbox_ids); - - if let Some(keywords) = keywords { - import_request.keywords(keywords); - } - - if let Some(received_at) = received_at { - import_request.received_at(received_at); - } - - let id = import_request.create_id(); - request.send_single::()?.created(&id) - } - - pub fn email_set_mailbox( - &self, - id: &str, - mailbox_id: &str, - set: bool, - ) -> crate::Result> { - let mut request = self.build(); - request.set_email().update(id).mailbox_id(mailbox_id, set); - request.send_single::()?.updated(id) - } - - pub fn email_set_mailboxes( - &self, - id: &str, - mailbox_ids: T, - ) -> crate::Result> - where - T: IntoIterator, - U: Into, - { - let mut request = self.build(); - request.set_email().update(id).mailbox_ids(mailbox_ids); - request.send_single::()?.updated(id) - } - - pub fn email_set_keyword( - &self, - id: &str, - keyword: &str, - set: bool, - ) -> crate::Result> { - let mut request = self.build(); - request.set_email().update(id).keyword(keyword, set); - request.send_single::()?.updated(id) - } - - pub fn email_set_keywords(&self, id: &str, keywords: T) -> crate::Result> - where - T: IntoIterator, - U: Into, - { - let mut request = self.build(); - request.set_email().update(id).keywords(keywords); - request.send_single::()?.updated(id) - } - - pub fn email_destroy(&self, id: &str) -> crate::Result<()> { - let mut request = self.build(); - request.set_email().destroy([id]); - request.send_single::()?.destroyed(id) - } - - pub fn email_get( - &self, - id: &str, - properties: Option>, - ) -> crate::Result>> { - let mut request = self.build(); - let get_request = request.get_email().ids([id]); - if let Some(properties) = properties { - get_request.properties(properties); - } - request - .send_single::() - .map(|mut r| r.take_list().pop()) - } - - pub fn email_changes( - &self, - since_state: impl Into, - max_changes: Option, - ) -> crate::Result>> { - let mut request = self.build(); - let changes_request = request.changes_email(since_state); - if let Some(max_changes) = max_changes { - changes_request.max_changes(max_changes); - } - request.send_single() - } - - pub fn email_query( - &self, - filter: Option>>, - sort: Option>>, - ) -> crate::Result { - let mut request = self.build(); - let query_request = request.query_email(); - if let Some(filter) = filter { - query_request.filter(filter); - } - if let Some(sort) = sort { - query_request.sort(sort.into_iter()); - } - request.send_single::() - } - - pub fn email_query_changes( - &self, - since_query_state: impl Into, - filter: Option>>, - ) -> crate::Result { - let mut request = self.build(); - let query_request = request.query_email_changes(since_query_state); - if let Some(filter) = filter { - query_request.filter(filter); - } - request.send_single::() - } - - pub fn email_parse( - &self, - blob_id: &str, - properties: Option>, - body_properties: Option>, - max_body_value_bytes: Option, - ) -> crate::Result { - let mut request = self.build(); - let parse_request = request.parse_email().blob_ids([blob_id]); - if let Some(properties) = properties { - parse_request.properties(properties); - } - - if let Some(body_properties) = body_properties { - parse_request.body_properties(body_properties); - } - - if let Some(max_body_value_bytes) = max_body_value_bytes { - parse_request - .fetch_all_body_values(true) - .max_body_value_bytes(max_body_value_bytes); - } - - request - .send_single::() - .and_then(|mut r| r.parsed(blob_id)) - } - - pub fn email_copy( - &self, - from_account_id: impl Into, - id: impl Into, - mailbox_ids: T, - keywords: Option, - received_at: Option, - ) -> crate::Result - where - T: IntoIterator, - U: Into, - V: IntoIterator, - W: Into, - { - let id = id.into(); - let mut request = self.build(); - let email = request - .copy_email(from_account_id) - .create(id.clone()) - .mailbox_ids(mailbox_ids); - - if let Some(keywords) = keywords { - email.keywords(keywords); - } - - if let Some(received_at) = received_at { - email.received_at(received_at); - } - - request.send_single::()?.created(&id) - } - - pub fn search_snippet_get( - &self, - filter: Option>>, - email_ids: impl IntoIterator>, - ) -> crate::Result { - let mut request = self.build(); - let snippet_request = request.get_search_snippet(); - if let Some(filter) = filter { - snippet_request.filter(filter); - } - snippet_request.email_ids(email_ids); - request.send_single::() - } -} - -impl Request<'_> { - pub fn get_email(&mut self) -> &mut GetRequest> { - self.add_method_call( - Method::GetEmail, - Arguments::email_get(self.params(Method::GetEmail)), - ) - .email_get_mut() - } - - pub fn send_get_email(self) -> crate::Result { - self.send_single() - } - - pub fn changes_email(&mut self, since_state: impl Into) -> &mut ChangesRequest { - self.add_method_call( - Method::ChangesEmail, - Arguments::changes(self.params(Method::ChangesEmail), since_state.into()), - ) - .changes_mut() - } - - pub fn send_changes_email(self) -> crate::Result>> { - self.send_single() - } - - pub fn query_email(&mut self) -> &mut QueryRequest> { - self.add_method_call( - Method::QueryEmail, - Arguments::email_query(self.params(Method::QueryEmail)), - ) - .email_query_mut() - } - - pub fn send_query_email(self) -> crate::Result { - self.send_single() - } - - pub fn query_email_changes( - &mut self, - since_query_state: impl Into, - ) -> &mut QueryChangesRequest> { - self.add_method_call( - Method::QueryChangesEmail, - Arguments::email_query_changes( - self.params(Method::QueryChangesEmail), - since_query_state.into(), - ), - ) - .email_query_changes_mut() - } - - pub fn send_query_email_changes(self) -> crate::Result { - self.send_single() - } - - pub fn set_email(&mut self) -> &mut SetRequest> { - self.add_method_call( - Method::SetEmail, - Arguments::email_set(self.params(Method::SetEmail)), - ) - .email_set_mut() - } - - pub fn send_set_email(self) -> crate::Result { - self.send_single() - } - - pub fn copy_email( - &mut self, - from_account_id: impl Into, - ) -> &mut CopyRequest> { - self.add_method_call( - Method::CopyEmail, - Arguments::email_copy(self.params(Method::CopyEmail), from_account_id.into()), - ) - .email_copy_mut() - } - - pub fn send_copy_email(self) -> crate::Result { - self.send_single() - } - - pub fn import_email(&mut self) -> &mut EmailImportRequest { - self.add_method_call( - Method::ImportEmail, - Arguments::email_import(self.params(Method::ImportEmail)), - ) - .email_import_mut() - } - - pub fn send_import_email(self) -> crate::Result { - self.send_single() - } - - pub fn parse_email(&mut self) -> &mut EmailParseRequest { - self.add_method_call( - Method::ParseEmail, - Arguments::email_parse(self.params(Method::ParseEmail)), - ) - .email_parse_mut() - } - - pub fn send_parse_email(self) -> crate::Result { - self.send_single() - } - - pub fn get_search_snippet(&mut self) -> &mut SearchSnippetGetRequest { - self.add_method_call( - Method::GetSearchSnippet, - Arguments::search_snippet_get(self.params(Method::GetSearchSnippet)), - ) - .search_snippet_get_mut() - } - - pub fn send_get_search_snippet(self) -> crate::Result { - self.send_single() - } -} diff --git a/src/email/mod.rs b/src/email/mod.rs index 75327f2..72d084b 100644 --- a/src/email/mod.rs +++ b/src/email/mod.rs @@ -10,10 +10,7 @@ */ pub mod get; -#[cfg(feature = "async")] pub mod helpers; -#[cfg(feature = "blocking")] -pub mod helpers_blocking; pub mod import; pub mod parse; pub mod query; diff --git a/src/email_submission/helpers.rs b/src/email_submission/helpers.rs index 08af1fa..ca9b324 100644 --- a/src/email_submission/helpers.rs +++ b/src/email_submission/helpers.rs @@ -26,6 +26,7 @@ use crate::{ use super::{Address, EmailSubmission, Property, UndoStatus}; impl Client { + #[maybe_async::maybe_async] pub async fn email_submission_create( &self, email_id: impl Into, @@ -45,6 +46,7 @@ impl Client { .created(&id) } + #[maybe_async::maybe_async] pub async fn email_submission_create_envelope( &self, email_id: impl Into, @@ -72,6 +74,7 @@ impl Client { .created(&id) } + #[maybe_async::maybe_async] pub async fn email_submission_change_status( &self, id: &str, @@ -88,6 +91,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn email_submission_destroy(&self, id: &str) -> crate::Result<()> { let mut request = self.build(); request.set_email_submission().destroy([id]); @@ -97,6 +101,7 @@ impl Client { .destroyed(id) } + #[maybe_async::maybe_async] pub async fn email_submission_get( &self, id: &str, @@ -113,6 +118,7 @@ impl Client { .map(|mut r| r.take_list().pop()) } + #[maybe_async::maybe_async] pub async fn email_submission_query( &self, filter: Option>>, @@ -129,6 +135,7 @@ impl Client { request.send_single::().await } + #[maybe_async::maybe_async] pub async fn email_submission_changes( &self, since_state: impl Into, @@ -152,6 +159,7 @@ impl Request<'_> { .email_submission_get_mut() } + #[maybe_async::maybe_async] pub async fn send_get_email_submission(self) -> crate::Result { self.send_single().await } @@ -171,6 +179,7 @@ impl Request<'_> { .changes_mut() } + #[maybe_async::maybe_async] pub async fn send_changes_email_submission( self, ) -> crate::Result>> { @@ -186,6 +195,7 @@ impl Request<'_> { .email_submission_query_mut() } + #[maybe_async::maybe_async] pub async fn send_query_email_submission(self) -> crate::Result { self.send_single().await } @@ -205,6 +215,7 @@ impl Request<'_> { .email_submission_query_changes_mut() } + #[maybe_async::maybe_async] pub async fn send_query_email_submission_changes(self) -> crate::Result { self.send_single().await } @@ -218,6 +229,7 @@ impl Request<'_> { .email_submission_set_mut() } + #[maybe_async::maybe_async] pub async fn send_set_email_submission(self) -> crate::Result { self.send_single().await } diff --git a/src/email_submission/helpers_blocking.rs b/src/email_submission/helpers_blocking.rs deleted file mode 100644 index 9c815c0..0000000 --- a/src/email_submission/helpers_blocking.rs +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright Stalwart Labs Ltd. See the COPYING - * file at the top-level directory of this distribution. - * - * Licensed under the Apache License, Version 2.0 or the MIT license - * , at your - * option. This file may not be copied, modified, or distributed - * except according to those terms. - */ - -use crate::{ - client::Client, - core::{ - changes::{ChangesRequest, ChangesResponse}, - get::GetRequest, - query::{Comparator, Filter, QueryRequest, QueryResponse}, - query_changes::{QueryChangesRequest, QueryChangesResponse}, - request::{Arguments, Request}, - response::{EmailSubmissionGetResponse, EmailSubmissionSetResponse}, - set::{SetObject, SetRequest}, - }, - Get, Method, Set, URI, -}; - -use super::{Address, EmailSubmission, Property, UndoStatus}; - -impl Client { - pub fn email_submission_create( - &self, - email_id: impl Into, - identity_id: impl Into, - ) -> crate::Result> { - let mut request = self.build(); - let id = request - .set_email_submission() - .create() - .email_id(email_id) - .identity_id(identity_id) - .create_id() - .unwrap(); - request - .send_single::()? - .created(&id) - } - - pub fn email_submission_create_envelope( - &self, - email_id: impl Into, - identity_id: impl Into, - mail_from: S, - rcpt_to: T, - ) -> crate::Result> - where - S: Into
, - T: IntoIterator, - U: Into
, - { - let mut request = self.build(); - let id = request - .set_email_submission() - .create() - .email_id(email_id) - .identity_id(identity_id) - .envelope(mail_from, rcpt_to) - .create_id() - .unwrap(); - request - .send_single::()? - .created(&id) - } - - pub fn email_submission_change_status( - &self, - id: &str, - undo_status: UndoStatus, - ) -> crate::Result> { - let mut request = self.build(); - request - .set_email_submission() - .update(id) - .undo_status(undo_status); - request - .send_single::()? - .updated(id) - } - - pub fn email_submission_destroy(&self, id: &str) -> crate::Result<()> { - let mut request = self.build(); - request.set_email_submission().destroy([id]); - request - .send_single::()? - .destroyed(id) - } - - pub fn email_submission_get( - &self, - id: &str, - properties: Option>, - ) -> crate::Result> { - let mut request = self.build(); - let get_request = request.get_email_submission().ids([id]); - if let Some(properties) = properties { - get_request.properties(properties.into_iter()); - } - request - .send_single::() - .map(|mut r| r.take_list().pop()) - } - - pub fn email_submission_query( - &self, - filter: Option>>, - sort: Option>>, - ) -> crate::Result { - let mut request = self.build(); - let query_request = request.query_email_submission(); - if let Some(filter) = filter { - query_request.filter(filter); - } - if let Some(sort) = sort { - query_request.sort(sort.into_iter()); - } - request.send_single::() - } - - pub fn email_submission_changes( - &self, - since_state: impl Into, - max_changes: usize, - ) -> crate::Result>> { - let mut request = self.build(); - request - .changes_email_submission(since_state) - .max_changes(max_changes); - request.send_single() - } -} - -impl Request<'_> { - pub fn get_email_submission(&mut self) -> &mut GetRequest> { - self.add_capability(URI::Submission); - self.add_method_call( - Method::GetEmailSubmission, - Arguments::email_submission_get(self.params(Method::GetEmailSubmission)), - ) - .email_submission_get_mut() - } - - pub fn send_get_email_submission(self) -> crate::Result { - self.send_single() - } - - pub fn changes_email_submission( - &mut self, - since_state: impl Into, - ) -> &mut ChangesRequest { - self.add_capability(URI::Submission); - self.add_method_call( - Method::ChangesEmailSubmission, - Arguments::changes( - self.params(Method::ChangesEmailSubmission), - since_state.into(), - ), - ) - .changes_mut() - } - - pub fn send_changes_email_submission( - self, - ) -> crate::Result>> { - self.send_single() - } - - pub fn query_email_submission(&mut self) -> &mut QueryRequest> { - self.add_capability(URI::Submission); - self.add_method_call( - Method::QueryEmailSubmission, - Arguments::email_submission_query(self.params(Method::QueryEmailSubmission)), - ) - .email_submission_query_mut() - } - - pub fn send_query_email_submission(self) -> crate::Result { - self.send_single() - } - - pub fn query_email_submission_changes( - &mut self, - since_query_state: impl Into, - ) -> &mut QueryChangesRequest> { - self.add_capability(URI::Submission); - self.add_method_call( - Method::QueryChangesEmailSubmission, - Arguments::email_submission_query_changes( - self.params(Method::QueryChangesEmailSubmission), - since_query_state.into(), - ), - ) - .email_submission_query_changes_mut() - } - - pub fn send_query_email_submission_changes(self) -> crate::Result { - self.send_single() - } - - pub fn set_email_submission(&mut self) -> &mut SetRequest> { - self.add_capability(URI::Submission); - self.add_method_call( - Method::SetEmailSubmission, - Arguments::email_submission_set(self.params(Method::SetEmailSubmission)), - ) - .email_submission_set_mut() - } - - pub fn send_set_email_submission(self) -> crate::Result { - self.send_single() - } -} diff --git a/src/email_submission/mod.rs b/src/email_submission/mod.rs index f9821f6..8dd2c60 100644 --- a/src/email_submission/mod.rs +++ b/src/email_submission/mod.rs @@ -10,10 +10,7 @@ */ pub mod get; -#[cfg(feature = "async")] pub mod helpers; -#[cfg(feature = "blocking")] -pub mod helpers_blocking; pub mod query; pub mod set; diff --git a/src/identity/helpers.rs b/src/identity/helpers.rs index c2445d0..be10096 100644 --- a/src/identity/helpers.rs +++ b/src/identity/helpers.rs @@ -24,6 +24,7 @@ use crate::{ use super::{Identity, Property}; impl Client { + #[maybe_async::maybe_async] pub async fn identity_create( &self, name: impl Into, @@ -43,6 +44,7 @@ impl Client { .created(&id) } + #[maybe_async::maybe_async] pub async fn identity_destroy(&self, id: &str) -> crate::Result<()> { let mut request = self.build(); request.set_identity().destroy([id]); @@ -52,6 +54,7 @@ impl Client { .destroyed(id) } + #[maybe_async::maybe_async] pub async fn identity_get( &self, id: &str, @@ -68,6 +71,7 @@ impl Client { .map(|mut r| r.take_list().pop()) } + #[maybe_async::maybe_async] pub async fn identity_changes( &self, since_state: impl Into, @@ -90,6 +94,7 @@ impl Request<'_> { .identity_get_mut() } + #[maybe_async::maybe_async] pub async fn send_get_identity(self) -> crate::Result { self.send_single().await } @@ -102,6 +107,7 @@ impl Request<'_> { .identity_set_mut() } + #[maybe_async::maybe_async] pub async fn send_set_identity(self) -> crate::Result { self.send_single().await } @@ -114,6 +120,7 @@ impl Request<'_> { .changes_mut() } + #[maybe_async::maybe_async] pub async fn send_changes_identity(self) -> crate::Result>> { self.send_single().await } diff --git a/src/identity/helpers_blocking.rs b/src/identity/helpers_blocking.rs deleted file mode 100644 index d8041c3..0000000 --- a/src/identity/helpers_blocking.rs +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright Stalwart Labs Ltd. See the COPYING - * file at the top-level directory of this distribution. - * - * Licensed under the Apache License, Version 2.0 or the MIT license - * , at your - * option. This file may not be copied, modified, or distributed - * except according to those terms. - */ - -use crate::{ - client::Client, - core::{ - changes::{ChangesRequest, ChangesResponse}, - get::GetRequest, - request::{Arguments, Request}, - response::{IdentityGetResponse, IdentitySetResponse}, - set::{SetObject, SetRequest}, - }, - Get, Method, Set, -}; - -use super::{Identity, Property}; - -impl Client { - pub fn identity_create( - &self, - name: impl Into, - email: impl Into, - ) -> crate::Result { - let mut request = self.build(); - let id = request - .set_identity() - .create() - .name(name) - .email(email) - .create_id() - .unwrap(); - request.send_single::()?.created(&id) - } - - pub fn identity_destroy(&self, id: &str) -> crate::Result<()> { - let mut request = self.build(); - request.set_identity().destroy([id]); - request.send_single::()?.destroyed(id) - } - - pub fn identity_get( - &self, - id: &str, - properties: Option>, - ) -> crate::Result> { - let mut request = self.build(); - let get_request = request.get_identity().ids([id]); - if let Some(properties) = properties { - get_request.properties(properties.into_iter()); - } - request - .send_single::() - .map(|mut r| r.take_list().pop()) - } - - pub fn identity_changes( - &self, - since_state: impl Into, - max_changes: usize, - ) -> crate::Result>> { - let mut request = self.build(); - request - .changes_identity(since_state) - .max_changes(max_changes); - request.send_single() - } -} - -impl Request<'_> { - pub fn get_identity(&mut self) -> &mut GetRequest> { - self.add_method_call( - Method::GetIdentity, - Arguments::identity_get(self.params(Method::GetIdentity)), - ) - .identity_get_mut() - } - - pub fn send_get_identity(self) -> crate::Result { - self.send_single() - } - - pub fn set_identity(&mut self) -> &mut SetRequest> { - self.add_method_call( - Method::SetIdentity, - Arguments::identity_set(self.params(Method::SetIdentity)), - ) - .identity_set_mut() - } - - pub fn send_set_identity(self) -> crate::Result { - self.send_single() - } - - pub fn changes_identity(&mut self, since_state: impl Into) -> &mut ChangesRequest { - self.add_method_call( - Method::ChangesIdentity, - Arguments::changes(self.params(Method::ChangesIdentity), since_state.into()), - ) - .changes_mut() - } - - pub fn send_changes_identity(self) -> crate::Result>> { - self.send_single() - } -} diff --git a/src/identity/mod.rs b/src/identity/mod.rs index 6d5f8a4..4728bd6 100644 --- a/src/identity/mod.rs +++ b/src/identity/mod.rs @@ -10,10 +10,7 @@ */ pub mod get; -#[cfg(feature = "async")] pub mod helpers; -#[cfg(feature = "blocking")] -pub mod helpers_blocking; pub mod set; use std::fmt::Display; diff --git a/src/lib.rs b/src/lib.rs index 78fa1e4..46ab810 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -365,7 +365,7 @@ pub enum Error { Transport(reqwest::Error), Parse(serde_json::Error), Internal(String), - Problem(ProblemDetails), + Problem(Box), Server(String), Method(MethodError), Set(SetError), @@ -395,7 +395,7 @@ impl From for Error { impl From for Error { fn from(e: ProblemDetails) -> Self { - Error::Problem(e) + Error::Problem(Box::new(e)) } } diff --git a/src/mailbox/helpers.rs b/src/mailbox/helpers.rs index 0f2687f..dc210ec 100644 --- a/src/mailbox/helpers.rs +++ b/src/mailbox/helpers.rs @@ -27,6 +27,7 @@ use crate::{ use super::{Mailbox, Property, Role}; impl Client { + #[maybe_async::maybe_async] pub async fn mailbox_create( &self, name: impl Into, @@ -48,6 +49,7 @@ impl Client { .created(&id) } + #[maybe_async::maybe_async] pub async fn mailbox_rename( &self, id: &str, @@ -61,6 +63,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn mailbox_move( &self, id: &str, @@ -74,6 +77,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn mailbox_update_role( &self, id: &str, @@ -87,6 +91,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn mailbox_update_acl( &self, id: &str, @@ -101,6 +106,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn mailbox_update_sort_order( &self, id: &str, @@ -114,6 +120,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn mailbox_subscribe( &self, id: &str, @@ -130,6 +137,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn mailbox_destroy(&self, id: &str, delete_emails: bool) -> crate::Result<()> { let mut request = self.build(); request @@ -143,6 +151,7 @@ impl Client { .destroyed(id) } + #[maybe_async::maybe_async] pub async fn mailbox_get( &self, id: &str, @@ -159,6 +168,7 @@ impl Client { .map(|mut r| r.take_list().pop()) } + #[maybe_async::maybe_async] pub async fn mailbox_query( &self, filter: Option>>, @@ -175,6 +185,7 @@ impl Client { request.send_single::().await } + #[maybe_async::maybe_async] pub async fn mailbox_changes( &self, since_state: impl Into, @@ -197,6 +208,7 @@ impl Request<'_> { .mailbox_get_mut() } + #[maybe_async::maybe_async] pub async fn send_get_mailbox(self) -> crate::Result { self.send_single().await } @@ -209,6 +221,7 @@ impl Request<'_> { .changes_mut() } + #[maybe_async::maybe_async] pub async fn send_changes_mailbox(self) -> crate::Result>> { self.send_single().await } @@ -221,6 +234,7 @@ impl Request<'_> { .mailbox_query_mut() } + #[maybe_async::maybe_async] pub async fn send_query_mailbox(self) -> crate::Result { self.send_single().await } @@ -239,6 +253,7 @@ impl Request<'_> { .mailbox_query_changes_mut() } + #[maybe_async::maybe_async] pub async fn send_query_mailbox_changes(self) -> crate::Result { self.send_single().await } @@ -251,6 +266,7 @@ impl Request<'_> { .mailbox_set_mut() } + #[maybe_async::maybe_async] pub async fn send_set_mailbox(self) -> crate::Result { self.send_single().await } diff --git a/src/mailbox/helpers_blocking.rs b/src/mailbox/helpers_blocking.rs deleted file mode 100644 index f752f24..0000000 --- a/src/mailbox/helpers_blocking.rs +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright Stalwart Labs Ltd. See the COPYING - * file at the top-level directory of this distribution. - * - * Licensed under the Apache License, Version 2.0 or the MIT license - * , at your - * option. This file may not be copied, modified, or distributed - * except according to those terms. - */ - -use crate::{ - client::Client, - core::{ - changes::{ChangesRequest, ChangesResponse}, - get::GetRequest, - query::{Comparator, Filter, QueryRequest, QueryResponse}, - query_changes::{QueryChangesRequest, QueryChangesResponse}, - request::{Arguments, Request}, - response::{MailboxGetResponse, MailboxSetResponse}, - set::{SetObject, SetRequest}, - }, - principal::ACL, - Get, Method, Set, -}; - -use super::{Mailbox, Property, Role}; - -impl Client { - pub fn mailbox_create( - &self, - name: impl Into, - parent_id: Option>, - role: Role, - ) -> crate::Result { - let mut request = self.build(); - let id = request - .set_mailbox() - .create() - .name(name) - .role(role) - .parent_id(parent_id) - .create_id() - .unwrap(); - request.send_single::()?.created(&id) - } - - pub fn mailbox_rename( - &self, - id: &str, - name: impl Into, - ) -> crate::Result> { - let mut request = self.build(); - request.set_mailbox().update(id).name(name); - request.send_single::()?.updated(id) - } - - pub fn mailbox_move( - &self, - id: &str, - parent_id: Option>, - ) -> crate::Result> { - let mut request = self.build(); - request.set_mailbox().update(id).parent_id(parent_id); - request.send_single::()?.updated(id) - } - - pub fn mailbox_update_role(&self, id: &str, role: Role) -> crate::Result> { - let mut request = self.build(); - request.set_mailbox().update(id).role(role); - request.send_single::()?.updated(id) - } - - pub fn mailbox_update_acl( - &self, - id: &str, - account_id: &str, - acl: impl IntoIterator, - ) -> crate::Result> { - let mut request = self.build(); - request.set_mailbox().update(id).acl(account_id, acl); - request.send_single::()?.updated(id) - } - - pub fn mailbox_update_sort_order( - &self, - id: &str, - sort_order: u32, - ) -> crate::Result> { - let mut request = self.build(); - request.set_mailbox().update(id).sort_order(sort_order); - request.send_single::()?.updated(id) - } - - pub fn mailbox_subscribe( - &self, - id: &str, - is_subscribed: bool, - ) -> crate::Result> { - let mut request = self.build(); - request - .set_mailbox() - .update(id) - .is_subscribed(is_subscribed); - request.send_single::()?.updated(id) - } - - pub fn mailbox_destroy(&self, id: &str, delete_emails: bool) -> crate::Result<()> { - let mut request = self.build(); - request - .set_mailbox() - .destroy([id]) - .arguments() - .on_destroy_remove_emails(delete_emails); - request.send_single::()?.destroyed(id) - } - - pub fn mailbox_get( - &self, - id: &str, - properties: Option>, - ) -> crate::Result> { - let mut request = self.build(); - let get_request = request.get_mailbox().ids([id]); - if let Some(properties) = properties { - get_request.properties(properties.into_iter()); - } - request - .send_single::() - .map(|mut r| r.take_list().pop()) - } - - pub fn mailbox_query( - &self, - filter: Option>>, - sort: Option>>, - ) -> crate::Result { - let mut request = self.build(); - let query_request = request.query_mailbox(); - if let Some(filter) = filter { - query_request.filter(filter); - } - if let Some(sort) = sort { - query_request.sort(sort.into_iter()); - } - request.send_single::() - } - - pub fn mailbox_changes( - &self, - since_state: impl Into, - max_changes: usize, - ) -> crate::Result>> { - let mut request = self.build(); - request - .changes_mailbox(since_state) - .max_changes(max_changes); - request.send_single() - } -} - -impl Request<'_> { - pub fn get_mailbox(&mut self) -> &mut GetRequest> { - self.add_method_call( - Method::GetMailbox, - Arguments::mailbox_get(self.params(Method::GetMailbox)), - ) - .mailbox_get_mut() - } - - pub fn send_get_mailbox(self) -> crate::Result { - self.send_single() - } - - pub fn changes_mailbox(&mut self, since_state: impl Into) -> &mut ChangesRequest { - self.add_method_call( - Method::ChangesMailbox, - Arguments::changes(self.params(Method::ChangesMailbox), since_state.into()), - ) - .changes_mut() - } - - pub fn send_changes_mailbox(self) -> crate::Result>> { - self.send_single() - } - - pub fn query_mailbox(&mut self) -> &mut QueryRequest> { - self.add_method_call( - Method::QueryMailbox, - Arguments::mailbox_query(self.params(Method::QueryMailbox)), - ) - .mailbox_query_mut() - } - - pub fn send_query_mailbox(self) -> crate::Result { - self.send_single() - } - - pub fn query_mailbox_changes( - &mut self, - since_query_state: impl Into, - ) -> &mut QueryChangesRequest> { - self.add_method_call( - Method::QueryChangesMailbox, - Arguments::mailbox_query_changes( - self.params(Method::QueryChangesMailbox), - since_query_state.into(), - ), - ) - .mailbox_query_changes_mut() - } - - pub fn send_query_mailbox_changes(self) -> crate::Result { - self.send_single() - } - - pub fn set_mailbox(&mut self) -> &mut SetRequest> { - self.add_method_call( - Method::SetMailbox, - Arguments::mailbox_set(self.params(Method::SetMailbox)), - ) - .mailbox_set_mut() - } - - pub fn send_set_mailbox(self) -> crate::Result { - self.send_single() - } -} diff --git a/src/mailbox/mod.rs b/src/mailbox/mod.rs index 610707c..528e257 100644 --- a/src/mailbox/mod.rs +++ b/src/mailbox/mod.rs @@ -10,10 +10,7 @@ */ pub mod get; -#[cfg(feature = "async")] pub mod helpers; -#[cfg(feature = "blocking")] -pub mod helpers_blocking; pub mod query; pub mod set; @@ -116,7 +113,7 @@ pub(crate) enum ACLPatch { Set(bool), } -#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)] #[serde(rename_all = "lowercase")] pub enum Role { #[serde(rename = "archive", alias = "ARCHIVE")] @@ -133,15 +130,10 @@ pub enum Role { Sent, #[serde(rename = "trash", alias = "TRASH")] Trash, + #[default] None, } -impl Default for Role { - fn default() -> Self { - Role::None - } -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct MailboxRights { #[serde(rename = "mayReadItems")] diff --git a/src/principal/helpers.rs b/src/principal/helpers.rs index 454b69a..5711d8e 100644 --- a/src/principal/helpers.rs +++ b/src/principal/helpers.rs @@ -26,6 +26,7 @@ use crate::{ use super::{Principal, Property, Type, DKIM}; impl Client { + #[maybe_async::maybe_async] pub async fn individual_create( &self, email: impl Into, @@ -48,6 +49,7 @@ impl Client { .created(&id) } + #[maybe_async::maybe_async] pub async fn domain_create(&self, name: impl Into) -> crate::Result { let mut request = self.build(); let id = request @@ -63,6 +65,7 @@ impl Client { .created(&id) } + #[maybe_async::maybe_async] pub async fn domain_enable_dkim( &self, id: &str, @@ -82,6 +85,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn list_create( &self, email: impl Into, @@ -104,6 +108,7 @@ impl Client { .created(&id) } + #[maybe_async::maybe_async] pub async fn group_create( &self, email: impl Into, @@ -126,6 +131,7 @@ impl Client { .created(&id) } + #[maybe_async::maybe_async] pub async fn principal_set_name( &self, id: &str, @@ -139,6 +145,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn principal_set_secret( &self, id: &str, @@ -152,6 +159,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn principal_set_email( &self, id: &str, @@ -165,6 +173,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn principal_set_timezone( &self, id: &str, @@ -178,6 +187,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn principal_set_members( &self, id: &str, @@ -191,6 +201,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn principal_set_aliases( &self, id: &str, @@ -204,6 +215,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn principal_set_capabilities( &self, id: &str, @@ -220,6 +232,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn principal_destroy(&self, id: &str) -> crate::Result<()> { let mut request = self.build(); request.set_principal().destroy([id]).arguments(); @@ -229,6 +242,7 @@ impl Client { .destroyed(id) } + #[maybe_async::maybe_async] pub async fn principal_get( &self, id: &str, @@ -245,6 +259,7 @@ impl Client { .map(|mut r| r.take_list().pop()) } + #[maybe_async::maybe_async] pub async fn principal_query( &self, filter: Option>>, @@ -261,6 +276,7 @@ impl Client { request.send_single::().await } + #[maybe_async::maybe_async] pub async fn principal_changes( &self, since_state: impl Into, @@ -283,6 +299,7 @@ impl Request<'_> { .principal_get_mut() } + #[maybe_async::maybe_async] pub async fn send_get_principal(self) -> crate::Result { self.send_single().await } @@ -295,6 +312,7 @@ impl Request<'_> { .changes_mut() } + #[maybe_async::maybe_async] pub async fn send_changes_principal(self) -> crate::Result>> { self.send_single().await } @@ -307,6 +325,7 @@ impl Request<'_> { .principal_query_mut() } + #[maybe_async::maybe_async] pub async fn send_query_principal(self) -> crate::Result { self.send_single().await } @@ -325,6 +344,7 @@ impl Request<'_> { .principal_query_changes_mut() } + #[maybe_async::maybe_async] pub async fn send_query_principal_changes(self) -> crate::Result { self.send_single().await } @@ -337,6 +357,7 @@ impl Request<'_> { .principal_set_mut() } + #[maybe_async::maybe_async] pub async fn send_set_principal(self) -> crate::Result { self.send_single().await } diff --git a/src/principal/helpers_blocking.rs b/src/principal/helpers_blocking.rs deleted file mode 100644 index 11d4a86..0000000 --- a/src/principal/helpers_blocking.rs +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Copyright Stalwart Labs Ltd. See the COPYING - * file at the top-level directory of this distribution. - * - * Licensed under the Apache License, Version 2.0 or the MIT license - * , at your - * option. This file may not be copied, modified, or distributed - * except according to those terms. - */ - -use crate::{ - client::Client, - core::{ - changes::{ChangesRequest, ChangesResponse}, - get::GetRequest, - query::{Comparator, Filter, QueryRequest, QueryResponse}, - query_changes::{QueryChangesRequest, QueryChangesResponse}, - request::{Arguments, Request}, - response::{PrincipalGetResponse, PrincipalSetResponse}, - set::{SetObject, SetRequest}, - }, - Get, Method, Set, -}; - -use super::{Principal, Property, Type}; - -impl Client { - pub fn individual_create( - &self, - email: impl Into, - secret: impl Into, - name: impl Into, - ) -> crate::Result { - let mut request = self.build(); - let id = request - .set_principal() - .create() - .name(name) - .secret(secret) - .email(email) - .ptype(Type::Individual) - .create_id() - .unwrap(); - request.send_single::()?.created(&id) - } - - pub fn domain_create(&self, name: impl Into) -> crate::Result { - let mut request = self.build(); - let id = request - .set_principal() - .create() - .name(name) - .ptype(Type::Domain) - .create_id() - .unwrap(); - request.send_single::()?.created(&id) - } - - pub fn list_create( - &self, - email: impl Into, - name: impl Into, - members: impl IntoIterator>, - ) -> crate::Result { - let mut request = self.build(); - let id = request - .set_principal() - .create() - .name(name) - .email(email) - .ptype(Type::List) - .members(members.into()) - .create_id() - .unwrap(); - request.send_single::()?.created(&id) - } - - pub fn group_create( - &self, - email: impl Into, - name: impl Into, - members: impl IntoIterator>, - ) -> crate::Result { - let mut request = self.build(); - let id = request - .set_principal() - .create() - .name(name) - .email(email) - .ptype(Type::Group) - .members(members.into()) - .create_id() - .unwrap(); - request.send_single::()?.created(&id) - } - - pub fn principal_set_name( - &self, - id: &str, - name: impl Into, - ) -> crate::Result> { - let mut request = self.build(); - request.set_principal().update(id).name(name); - request.send_single::()?.updated(id) - } - - pub fn principal_set_secret( - &self, - id: &str, - secret: impl Into, - ) -> crate::Result> { - let mut request = self.build(); - request.set_principal().update(id).secret(secret); - request.send_single::()?.updated(id) - } - - pub fn principal_set_email( - &self, - id: &str, - email: impl Into, - ) -> crate::Result> { - let mut request = self.build(); - request.set_principal().update(id).email(email); - request.send_single::()?.updated(id) - } - - pub fn principal_set_timezone( - &self, - id: &str, - timezone: Option>, - ) -> crate::Result> { - let mut request = self.build(); - request.set_principal().update(id).timezone(timezone); - request.send_single::()?.updated(id) - } - - pub fn principal_set_members( - &self, - id: &str, - members: Option>>, - ) -> crate::Result> { - let mut request = self.build(); - request.set_principal().update(id).members(members); - request.send_single::()?.updated(id) - } - - pub fn principal_set_aliases( - &self, - id: &str, - aliases: Option>>, - ) -> crate::Result> { - let mut request = self.build(); - request.set_principal().update(id).aliases(aliases); - request.send_single::()?.updated(id) - } - - pub fn principal_set_capabilities( - &self, - id: &str, - capabilities: Option>>, - ) -> crate::Result> { - let mut request = self.build(); - request - .set_principal() - .update(id) - .capabilities(capabilities); - request.send_single::()?.updated(id) - } - - pub fn principal_destroy(&self, id: &str) -> crate::Result<()> { - let mut request = self.build(); - request.set_principal().destroy([id]).arguments(); - request.send_single::()?.destroyed(id) - } - - pub fn principal_get( - &self, - id: &str, - properties: Option>, - ) -> crate::Result> { - let mut request = self.build(); - let get_request = request.get_principal().ids([id]); - if let Some(properties) = properties { - get_request.properties(properties.into_iter()); - } - request - .send_single::() - .map(|mut r| r.take_list().pop()) - } - - pub fn principal_query( - &self, - filter: Option>>, - sort: Option>>, - ) -> crate::Result { - let mut request = self.build(); - let query_request = request.query_principal(); - if let Some(filter) = filter { - query_request.filter(filter); - } - if let Some(sort) = sort { - query_request.sort(sort.into_iter()); - } - request.send_single::() - } - - pub fn principal_changes( - &self, - since_state: impl Into, - max_changes: usize, - ) -> crate::Result>> { - let mut request = self.build(); - request - .changes_principal(since_state) - .max_changes(max_changes); - request.send_single() - } -} - -impl Request<'_> { - pub fn get_principal(&mut self) -> &mut GetRequest> { - self.add_method_call( - Method::GetPrincipal, - Arguments::principal_get(self.params(Method::GetPrincipal)), - ) - .principal_get_mut() - } - - pub fn send_get_principal(self) -> crate::Result { - self.send_single() - } - - pub fn changes_principal(&mut self, since_state: impl Into) -> &mut ChangesRequest { - self.add_method_call( - Method::ChangesPrincipal, - Arguments::changes(self.params(Method::ChangesPrincipal), since_state.into()), - ) - .changes_mut() - } - - pub fn send_changes_principal(self) -> crate::Result>> { - self.send_single() - } - - pub fn query_principal(&mut self) -> &mut QueryRequest> { - self.add_method_call( - Method::QueryPrincipal, - Arguments::principal_query(self.params(Method::QueryPrincipal)), - ) - .principal_query_mut() - } - - pub fn send_query_principal(self) -> crate::Result { - self.send_single() - } - - pub fn query_principal_changes( - &mut self, - since_query_state: impl Into, - ) -> &mut QueryChangesRequest> { - self.add_method_call( - Method::QueryChangesPrincipal, - Arguments::principal_query_changes( - self.params(Method::QueryChangesPrincipal), - since_query_state.into(), - ), - ) - .principal_query_changes_mut() - } - - pub fn send_query_principal_changes(self) -> crate::Result { - self.send_single() - } - - pub fn set_principal(&mut self) -> &mut SetRequest> { - self.add_method_call( - Method::SetPrincipal, - Arguments::principal_set(self.params(Method::SetPrincipal)), - ) - .principal_set_mut() - } - - pub fn send_set_principal(self) -> crate::Result { - self.send_single() - } -} diff --git a/src/principal/mod.rs b/src/principal/mod.rs index 7867f3b..371fb51 100644 --- a/src/principal/mod.rs +++ b/src/principal/mod.rs @@ -10,10 +10,7 @@ */ pub mod get; -#[cfg(feature = "async")] pub mod helpers; -#[cfg(feature = "blocking")] -pub mod helpers_blocking; pub mod query; pub mod set; diff --git a/src/push_subscription/helpers.rs b/src/push_subscription/helpers.rs index 3ff67a6..117f306 100644 --- a/src/push_subscription/helpers.rs +++ b/src/push_subscription/helpers.rs @@ -23,6 +23,7 @@ use crate::{ use super::{Keys, PushSubscription}; impl Client { + #[maybe_async::maybe_async] pub async fn push_subscription_create( &self, device_client_id: impl Into, @@ -47,6 +48,7 @@ impl Client { .created(&id) } + #[maybe_async::maybe_async] pub async fn push_subscription_verify( &self, id: &str, @@ -63,6 +65,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn push_subscription_update_types( &self, id: &str, @@ -76,6 +79,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn push_subscription_destroy(&self, id: &str) -> crate::Result<()> { let mut request = self.build(); request.set_push_subscription().destroy([id]); @@ -95,6 +99,7 @@ impl Request<'_> { .push_get_mut() } + #[maybe_async::maybe_async] pub async fn send_get_push_subscription(self) -> crate::Result { self.send_single().await } @@ -107,6 +112,7 @@ impl Request<'_> { .push_set_mut() } + #[maybe_async::maybe_async] pub async fn send_set_push_subscription(self) -> crate::Result { self.send_single().await } diff --git a/src/push_subscription/helpers_blocking.rs b/src/push_subscription/helpers_blocking.rs deleted file mode 100644 index 52ab774..0000000 --- a/src/push_subscription/helpers_blocking.rs +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright Stalwart Labs Ltd. See the COPYING - * file at the top-level directory of this distribution. - * - * Licensed under the Apache License, Version 2.0 or the MIT license - * , at your - * option. This file may not be copied, modified, or distributed - * except according to those terms. - */ - -use crate::{ - client::Client, - core::{ - get::GetRequest, - request::{Arguments, Request}, - response::{PushSubscriptionGetResponse, PushSubscriptionSetResponse}, - set::{SetObject, SetRequest}, - }, - Method, Set, TypeState, -}; - -use super::{Keys, PushSubscription}; - -impl Client { - pub fn push_subscription_create( - &self, - device_client_id: impl Into, - url: impl Into, - keys: Option, - ) -> crate::Result { - let mut request = self.build(); - let create_req = request - .set_push_subscription() - .create() - .device_client_id(device_client_id) - .url(url); - - if let Some(keys) = keys { - create_req.keys(keys); - } - - let id = create_req.create_id().unwrap(); - request - .send_single::()? - .created(&id) - } - - pub fn push_subscription_verify( - &self, - id: &str, - verification_code: impl Into, - ) -> crate::Result> { - let mut request = self.build(); - request - .set_push_subscription() - .update(id) - .verification_code(verification_code); - request - .send_single::()? - .updated(id) - } - - pub fn push_subscription_update_types( - &self, - id: &str, - types: Option>, - ) -> crate::Result> { - let mut request = self.build(); - request.set_push_subscription().update(id).types(types); - request - .send_single::()? - .updated(id) - } - - pub fn push_subscription_destroy(&self, id: &str) -> crate::Result<()> { - let mut request = self.build(); - request.set_push_subscription().destroy([id]); - request - .send_single::()? - .destroyed(id) - } -} - -impl Request<'_> { - pub fn get_push_subscription(&mut self) -> &mut GetRequest> { - self.add_method_call( - Method::GetPushSubscription, - Arguments::push_get(self.params(Method::GetPushSubscription)), - ) - .push_get_mut() - } - - pub fn send_get_push_subscription(self) -> crate::Result { - self.send_single() - } - - pub fn set_push_subscription(&mut self) -> &mut SetRequest> { - self.add_method_call( - Method::SetPushSubscription, - Arguments::push_set(self.params(Method::SetPushSubscription)), - ) - .push_set_mut() - } - - pub fn send_set_push_subscription(self) -> crate::Result { - self.send_single() - } -} diff --git a/src/push_subscription/mod.rs b/src/push_subscription/mod.rs index 68f8dbb..3cdd77c 100644 --- a/src/push_subscription/mod.rs +++ b/src/push_subscription/mod.rs @@ -10,10 +10,7 @@ */ pub mod get; -#[cfg(feature = "async")] pub mod helpers; -#[cfg(feature = "blocking")] -pub mod helpers_blocking; pub mod set; use std::fmt::Display; diff --git a/src/push_subscription/set.rs b/src/push_subscription/set.rs index ffddf2b..40d3294 100644 --- a/src/push_subscription/set.rs +++ b/src/push_subscription/set.rs @@ -86,8 +86,8 @@ impl SetObject for PushSubscription { impl Keys { pub fn new(p256dh: &[u8], auth: &[u8]) -> Self { Keys { - p256dh: base64::encode_config(&p256dh, base64::URL_SAFE), - auth: base64::encode_config(&auth, base64::URL_SAFE), + p256dh: base64::encode_config(p256dh, base64::URL_SAFE), + auth: base64::encode_config(auth, base64::URL_SAFE), } } } diff --git a/src/sieve/helpers.rs b/src/sieve/helpers.rs index fc21392..c134647 100644 --- a/src/sieve/helpers.rs +++ b/src/sieve/helpers.rs @@ -27,6 +27,7 @@ use super::{ }; impl Client { + #[maybe_async::maybe_async] pub async fn sieve_script_create( &self, name: impl Into, @@ -53,6 +54,7 @@ impl Client { .created(&id) } + #[maybe_async::maybe_async] pub async fn sieve_script_replace( &self, id: &str, @@ -72,6 +74,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn sieve_script_rename( &self, id: &str, @@ -90,6 +93,7 @@ impl Client { .updated(id) } + #[maybe_async::maybe_async] pub async fn sieve_script_activate(&self, id: &str) -> crate::Result<()> { let mut request = self.build(); request @@ -102,6 +106,7 @@ impl Client { .unwrap_update_errors() } + #[maybe_async::maybe_async] pub async fn sieve_script_deactivate(&self) -> crate::Result<()> { let mut request = self.build(); request @@ -114,6 +119,7 @@ impl Client { .unwrap_update_errors() } + #[maybe_async::maybe_async] pub async fn sieve_script_destroy(&self, id: &str) -> crate::Result<()> { let mut request = self.build(); request.set_sieve_script().destroy([id]); @@ -123,6 +129,7 @@ impl Client { .destroyed(id) } + #[maybe_async::maybe_async] pub async fn sieve_script_get( &self, id: &str, @@ -139,6 +146,7 @@ impl Client { .map(|mut r| r.take_list().pop()) } + #[maybe_async::maybe_async] pub async fn sieve_script_query( &self, filter: Option>>, @@ -155,6 +163,7 @@ impl Client { request.send_single::().await } + #[maybe_async::maybe_async] pub async fn sieve_script_validate(&self, script: impl Into>) -> crate::Result<()> { let blob_id = self.upload(None, script.into(), None).await?.take_blob_id(); let mut request = self.build(); @@ -176,6 +185,7 @@ impl Request<'_> { .sieve_script_get_mut() } + #[maybe_async::maybe_async] pub async fn send_get_sieve_script(self) -> crate::Result { self.send_single().await } @@ -189,6 +199,7 @@ impl Request<'_> { .sieve_script_set_mut() } + #[maybe_async::maybe_async] pub async fn send_set_sieve_script(self) -> crate::Result { self.send_single().await } @@ -205,6 +216,7 @@ impl Request<'_> { .sieve_script_validate_mut() } + #[maybe_async::maybe_async] pub async fn send_validate_sieve_script(self) -> crate::Result { self.send_single().await } @@ -218,6 +230,7 @@ impl Request<'_> { .sieve_script_query_mut() } + #[maybe_async::maybe_async] pub async fn send_query_sieve_script(self) -> crate::Result { self.send_single().await } diff --git a/src/sieve/helpers_blocking.rs b/src/sieve/helpers_blocking.rs deleted file mode 100644 index 52bac36..0000000 --- a/src/sieve/helpers_blocking.rs +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright Stalwart Labs Ltd. See the COPYING - * file at the top-level directory of this distribution. - * - * Licensed under the Apache License, Version 2.0 or the MIT license - * , at your - * option. This file may not be copied, modified, or distributed - * except according to those terms. - */ - -use crate::{ - client::Client, - core::{ - get::GetRequest, - query::{Comparator, Filter, QueryRequest, QueryResponse}, - request::{Arguments, Request}, - response::{SieveScriptGetResponse, SieveScriptSetResponse}, - set::{SetObject, SetRequest}, - }, - Method, Set, URI, -}; - -use super::{ - validate::{SieveScriptValidateRequest, SieveScriptValidateResponse}, - Property, SieveScript, -}; - -impl Client { - pub fn sieve_script_create( - &self, - name: impl Into, - script: impl Into>, - activate: bool, - ) -> crate::Result { - let blob_id = self.upload(None, script.into(), None)?.take_blob_id(); - let mut request = self.build(); - let set_request = request.set_sieve_script(); - let id = set_request - .create() - .name(name) - .blob_id(blob_id) - .create_id() - .unwrap(); - if activate { - set_request - .arguments() - .on_success_activate_script(id.clone()); - } - request - .send_single::()? - .created(&id) - } - - pub fn sieve_script_replace( - &self, - id: &str, - script: impl Into>, - activate: bool, - ) -> crate::Result> { - let blob_id = self.upload(None, script.into(), None)?.take_blob_id(); - let mut request = self.build(); - let set_request = request.set_sieve_script(); - set_request.update(id).blob_id(blob_id); - if activate { - set_request.arguments().on_success_activate_script_id(id); - } - request.send_single::()?.updated(id) - } - - pub fn sieve_script_rename( - &self, - id: &str, - name: impl Into, - activate: bool, - ) -> crate::Result> { - let mut request = self.build(); - let set_request = request.set_sieve_script(); - set_request.update(id).name(name); - if activate { - set_request.arguments().on_success_activate_script_id(id); - } - request.send_single::()?.updated(id) - } - - pub fn sieve_script_activate(&self, id: &str) -> crate::Result<()> { - let mut request = self.build(); - request - .set_sieve_script() - .arguments() - .on_success_activate_script_id(id); - request - .send_single::()? - .unwrap_update_errors() - } - - pub fn sieve_script_deactivate(&self) -> crate::Result<()> { - let mut request = self.build(); - request - .set_sieve_script() - .arguments() - .on_success_deactivate_scripts(); - request - .send_single::()? - .unwrap_update_errors() - } - - pub fn sieve_script_destroy(&self, id: &str) -> crate::Result<()> { - let mut request = self.build(); - request.set_sieve_script().destroy([id]); - request - .send_single::()? - .destroyed(id) - } - - pub fn sieve_script_get( - &self, - id: &str, - properties: Option>, - ) -> crate::Result> { - let mut request = self.build(); - let get_request = request.get_sieve_script().ids([id]); - if let Some(properties) = properties { - get_request.properties(properties.into_iter()); - } - request - .send_single::() - .map(|mut r| r.take_list().pop()) - } - - pub fn sieve_script_query( - &self, - filter: Option>>, - sort: Option>>, - ) -> crate::Result { - let mut request = self.build(); - let query_request = request.query_sieve_script(); - if let Some(filter) = filter { - query_request.filter(filter); - } - if let Some(sort) = sort { - query_request.sort(sort.into_iter()); - } - request.send_single::() - } - - pub fn sieve_script_validate(&self, script: impl Into>) -> crate::Result<()> { - let blob_id = self.upload(None, script.into(), None)?.take_blob_id(); - let mut request = self.build(); - request.validate_sieve_script(blob_id); - request - .send_single::()? - .unwrap_error() - } -} - -impl Request<'_> { - pub fn get_sieve_script(&mut self) -> &mut GetRequest> { - self.add_capability(URI::Sieve); - self.add_method_call( - Method::GetSieveScript, - Arguments::sieve_script_get(self.params(Method::GetSieveScript)), - ) - .sieve_script_get_mut() - } - - pub fn send_get_sieve_script(self) -> crate::Result { - self.send_single() - } - - pub fn set_sieve_script(&mut self) -> &mut SetRequest> { - self.add_capability(URI::Sieve); - self.add_method_call( - Method::SetSieveScript, - Arguments::sieve_script_set(self.params(Method::SetSieveScript)), - ) - .sieve_script_set_mut() - } - - pub fn send_set_sieve_script(self) -> crate::Result { - self.send_single() - } - - pub fn validate_sieve_script( - &mut self, - blob_id: impl Into, - ) -> &mut SieveScriptValidateRequest { - self.add_capability(URI::Sieve); - self.add_method_call( - Method::ValidateSieveScript, - Arguments::sieve_script_validate(self.params(Method::ValidateSieveScript), blob_id), - ) - .sieve_script_validate_mut() - } - - pub fn send_validate_sieve_script(self) -> crate::Result { - self.send_single() - } - - pub fn query_sieve_script(&mut self) -> &mut QueryRequest> { - self.add_capability(URI::Sieve); - self.add_method_call( - Method::QuerySieveScript, - Arguments::sieve_script_query(self.params(Method::QuerySieveScript)), - ) - .sieve_script_query_mut() - } - - pub fn send_query_sieve_script(self) -> crate::Result { - self.send_single() - } -} diff --git a/src/sieve/mod.rs b/src/sieve/mod.rs index d83856b..dc07631 100644 --- a/src/sieve/mod.rs +++ b/src/sieve/mod.rs @@ -10,10 +10,7 @@ */ pub mod get; -#[cfg(feature = "async")] pub mod helpers; -#[cfg(feature = "blocking")] -pub mod helpers_blocking; pub mod query; pub mod set; pub mod validate; diff --git a/src/thread/helpers.rs b/src/thread/helpers.rs index 03dc0c5..0c31348 100644 --- a/src/thread/helpers.rs +++ b/src/thread/helpers.rs @@ -23,6 +23,7 @@ use crate::{ use super::Thread; impl Client { + #[maybe_async::maybe_async] pub async fn thread_get(&self, id: &str) -> crate::Result> { let mut request = self.build(); request.get_thread().ids([id]); @@ -42,6 +43,7 @@ impl Request<'_> { .thread_get_mut() } + #[maybe_async::maybe_async] pub async fn send_get_thread(self) -> crate::Result { self.send_single().await } @@ -54,6 +56,7 @@ impl Request<'_> { .changes_mut() } + #[maybe_async::maybe_async] pub async fn send_changes_thread(self) -> crate::Result> { self.send_single().await } diff --git a/src/thread/helpers_blocking.rs b/src/thread/helpers_blocking.rs deleted file mode 100644 index b4fb0d1..0000000 --- a/src/thread/helpers_blocking.rs +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright Stalwart Labs Ltd. See the COPYING - * file at the top-level directory of this distribution. - * - * Licensed under the Apache License, Version 2.0 or the MIT license - * , at your - * option. This file may not be copied, modified, or distributed - * except according to those terms. - */ - -use crate::{ - client::Client, - core::{ - changes::{ChangesRequest, ChangesResponse}, - get::GetRequest, - request::{Arguments, Request}, - response::ThreadGetResponse, - }, - Method, -}; - -use super::Thread; - -impl Client { - pub fn thread_get(&self, id: &str) -> crate::Result> { - let mut request = self.build(); - request.get_thread().ids([id]); - request - .send_single::() - .map(|mut r| r.take_list().pop()) - } -} - -impl Request<'_> { - pub fn get_thread(&mut self) -> &mut GetRequest { - self.add_method_call( - Method::GetThread, - Arguments::thread_get(self.params(Method::GetThread)), - ) - .thread_get_mut() - } - - pub fn send_get_thread(self) -> crate::Result { - self.send_single() - } - - pub fn changes_thread(&mut self, since_state: impl Into) -> &mut ChangesRequest { - self.add_method_call( - Method::ChangesThread, - Arguments::changes(self.params(Method::ChangesThread), since_state.into()), - ) - .changes_mut() - } - - pub fn send_changes_thread(self) -> crate::Result> { - self.send_single() - } -} diff --git a/src/thread/mod.rs b/src/thread/mod.rs index 7fcfab3..dcc029b 100644 --- a/src/thread/mod.rs +++ b/src/thread/mod.rs @@ -10,10 +10,7 @@ */ pub mod get; -#[cfg(feature = "async")] pub mod helpers; -#[cfg(feature = "blocking")] -pub mod helpers_blocking; use std::fmt::Display; diff --git a/src/vacation_response/helpers_blocking.rs b/src/vacation_response/helpers_blocking.rs deleted file mode 100644 index 83c0344..0000000 --- a/src/vacation_response/helpers_blocking.rs +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright Stalwart Labs Ltd. See the COPYING - * file at the top-level directory of this distribution. - * - * Licensed under the Apache License, Version 2.0 or the MIT license - * , at your - * option. This file may not be copied, modified, or distributed - * except according to those terms. - */ - -use crate::{ - client::Client, - core::{ - get::GetRequest, - request::{Arguments, Request}, - response::{VacationResponseGetResponse, VacationResponseSetResponse}, - set::{SetObject, SetRequest}, - }, - Method, Set, URI, -}; - -use super::{Property, VacationResponse}; - -impl Client { - pub fn vacation_response_create( - &self, - subject: impl Into, - text_body: Option>, - html_body: Option>, - ) -> crate::Result { - let mut request = self.build(); - let created_id = request - .set_vacation_response() - .create() - .is_enabled(true) - .subject(Some(subject)) - .text_body(text_body) - .html_body(html_body) - .create_id() - .unwrap(); - - request - .send_single::()? - .created(&created_id) - } - - pub fn vacation_response_enable( - &self, - subject: impl Into, - text_body: Option>, - html_body: Option>, - ) -> crate::Result> { - let mut request = self.build(); - request - .set_vacation_response() - .update("singleton") - .is_enabled(true) - .subject(Some(subject)) - .text_body(text_body) - .html_body(html_body); - - request - .send_single::()? - .updated("singleton") - } - - pub fn vacation_response_disable(&self) -> crate::Result> { - let mut request = self.build(); - request - .set_vacation_response() - .update("singleton") - .is_enabled(false); - - request - .send_single::()? - .updated("singleton") - } - - pub fn vacation_response_set_dates( - &self, - from_date: Option, - to_date: Option, - ) -> crate::Result> { - let mut request = self.build(); - request - .set_vacation_response() - .update("singleton") - .is_enabled(true) - .from_date(from_date) - .to_date(to_date); - - request - .send_single::()? - .updated("singleton") - } - - pub fn vacation_response_get( - &self, - properties: Option>, - ) -> crate::Result> { - let mut request = self.build(); - let get_request = request.get_vacation_response().ids(["singleton"]); - if let Some(properties) = properties { - get_request.properties(properties.into_iter()); - } - request - .send_single::() - .map(|mut r| r.take_list().pop()) - } - - pub fn vacation_response_destroy(&self) -> crate::Result<()> { - let mut request = self.build(); - request.set_vacation_response().destroy(["singleton"]); - request - .send_single::()? - .destroyed("singleton") - } -} - -impl Request<'_> { - pub fn get_vacation_response(&mut self) -> &mut GetRequest> { - self.add_capability(URI::VacationResponse); - self.add_method_call( - Method::GetVacationResponse, - Arguments::vacation_response_get(self.params(Method::GetVacationResponse)), - ) - .vacation_response_get_mut() - } - - pub fn send_get_vacation_response(self) -> crate::Result { - self.send_single() - } - - pub fn set_vacation_response(&mut self) -> &mut SetRequest> { - self.add_capability(URI::VacationResponse); - self.add_method_call( - Method::SetVacationResponse, - Arguments::vacation_response_set(self.params(Method::GetVacationResponse)), - ) - .vacation_response_set_mut() - } - - pub fn send_set_vacation_response(self) -> crate::Result { - self.send_single() - } -}