main
Mauro D 2023-04-16 17:06:55 +00:00
parent d340fabdc3
commit 3168352160
37 changed files with 160 additions and 2026 deletions

View File

@ -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.

View File

@ -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. <hello@stalw.art>"]
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]

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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<String>,
@ -34,6 +35,7 @@ impl Client {
}
impl Request<'_> {
#[maybe_async::maybe_async]
pub fn copy_blob(&mut self, from_account_id: impl Into<String>) -> &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<CopyBlobResponse> {
self.send_single().await
}

View File

@ -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 <LICENSE-APACHE or
* https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or https://opensource.org/licenses/MIT>, 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<String>,
blob_id: impl Into<String>,
) -> crate::Result<String> {
let blob_id = blob_id.into();
let mut request = self.build();
request.copy_blob(from_account_id).blob_id(&blob_id);
request.send_single::<CopyBlobResponse>()?.copied(&blob_id)
}
}
impl Request<'_> {
pub fn copy_blob(&mut self, from_account_id: impl Into<String>) -> &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<CopyBlobResponse> {
self.send_single()
}
}

View File

@ -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 {

View File

@ -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<Credentials>,
trusted_hosts: AHashSet<String>,
forwarded_for: Option<String>,
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<Item = impl Into<String>>,
@ -115,7 +128,7 @@ impl ClientBuilder {
self
}
#[cfg(feature = "async")]
#[maybe_async::maybe_async]
pub async fn connect(self, url: &str) -> crate::Result<Client> {
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<Client> {
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<R>(
&self,
request: &request::Request<'_>,
@ -365,8 +280,9 @@ impl Client {
{
let response: response::Response<R> = 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<R>(&self, request: &request::Request<'_>) -> crate::Result<response::Response<R>>
where
R: DeserializeOwned,
{
let response: response::Response<R> = 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<reqwest::Response> {
#[maybe_async::maybe_async]
pub async fn handle_error(response: Response) -> crate::Result<Response> {
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<reqwest::blocking::Response> {
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() {

View File

@ -32,6 +32,7 @@ use super::{
};
impl Client {
#[maybe_async::maybe_async]
pub async fn email_import<T, U, V, W>(
&self,
raw_message: Vec<u8>,
@ -55,6 +56,7 @@ impl Client {
.await
}
#[maybe_async::maybe_async]
pub async fn email_import_account<T, U, V, W>(
&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::<EmailSetResponse>().await?.updated(id)
}
#[maybe_async::maybe_async]
pub async fn email_set_mailboxes<T, U>(
&self,
id: &str,
@ -117,6 +121,7 @@ impl Client {
request.send_single::<EmailSetResponse>().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::<EmailSetResponse>().await?.updated(id)
}
#[maybe_async::maybe_async]
pub async fn email_set_keywords<T, U>(
&self,
id: &str,
@ -142,6 +148,7 @@ impl Client {
request.send_single::<EmailSetResponse>().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<String>,
@ -180,6 +189,7 @@ impl Client {
request.send_single().await
}
#[maybe_async::maybe_async]
pub async fn email_query(
&self,
filter: Option<impl Into<Filter<super::query::Filter>>>,
@ -196,6 +206,7 @@ impl Client {
request.send_single::<QueryResponse>().await
}
#[maybe_async::maybe_async]
pub async fn email_query_changes(
&self,
since_query_state: impl Into<String>,
@ -209,6 +220,7 @@ impl Client {
request.send_single::<QueryChangesResponse>().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<T, U, V, W>(
&self,
from_account_id: impl Into<String>,
@ -273,6 +286,7 @@ impl Client {
.created(&id)
}
#[maybe_async::maybe_async]
pub async fn search_snippet_get(
&self,
filter: Option<impl Into<Filter<super::query::Filter>>>,
@ -297,6 +311,7 @@ impl Request<'_> {
.email_get_mut()
}
#[maybe_async::maybe_async]
pub async fn send_get_email(self) -> crate::Result<EmailGetResponse> {
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<ChangesResponse<Email<Get>>> {
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<QueryResponse> {
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<QueryChangesResponse> {
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<EmailSetResponse> {
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<EmailCopyResponse> {
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<EmailImportResponse> {
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<EmailParseResponse> {
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<SearchSnippetGetResponse> {
self.send_single().await
}

View File

@ -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 <LICENSE-APACHE or
* https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or https://opensource.org/licenses/MIT>, 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<T, U, V, W>(
&self,
raw_message: Vec<u8>,
mailbox_ids: T,
keywords: Option<V>,
received_at: Option<i64>,
) -> crate::Result<Email>
where
T: IntoIterator<Item = U>,
U: Into<String>,
V: IntoIterator<Item = W>,
W: Into<String>,
{
self.email_import_account(
self.default_account_id(),
raw_message,
mailbox_ids,
keywords,
received_at,
)
}
pub fn email_import_account<T, U, V, W>(
&self,
account_id: &str,
raw_message: Vec<u8>,
mailbox_ids: T,
keywords: Option<V>,
received_at: Option<i64>,
) -> crate::Result<Email>
where
T: IntoIterator<Item = U>,
U: Into<String>,
V: IntoIterator<Item = W>,
W: Into<String>,
{
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::<EmailImportResponse>()?.created(&id)
}
pub fn email_set_mailbox(
&self,
id: &str,
mailbox_id: &str,
set: bool,
) -> crate::Result<Option<Email>> {
let mut request = self.build();
request.set_email().update(id).mailbox_id(mailbox_id, set);
request.send_single::<EmailSetResponse>()?.updated(id)
}
pub fn email_set_mailboxes<T, U>(
&self,
id: &str,
mailbox_ids: T,
) -> crate::Result<Option<Email>>
where
T: IntoIterator<Item = U>,
U: Into<String>,
{
let mut request = self.build();
request.set_email().update(id).mailbox_ids(mailbox_ids);
request.send_single::<EmailSetResponse>()?.updated(id)
}
pub fn email_set_keyword(
&self,
id: &str,
keyword: &str,
set: bool,
) -> crate::Result<Option<Email>> {
let mut request = self.build();
request.set_email().update(id).keyword(keyword, set);
request.send_single::<EmailSetResponse>()?.updated(id)
}
pub fn email_set_keywords<T, U>(&self, id: &str, keywords: T) -> crate::Result<Option<Email>>
where
T: IntoIterator<Item = U>,
U: Into<String>,
{
let mut request = self.build();
request.set_email().update(id).keywords(keywords);
request.send_single::<EmailSetResponse>()?.updated(id)
}
pub fn email_destroy(&self, id: &str) -> crate::Result<()> {
let mut request = self.build();
request.set_email().destroy([id]);
request.send_single::<EmailSetResponse>()?.destroyed(id)
}
pub fn email_get(
&self,
id: &str,
properties: Option<impl IntoIterator<Item = Property>>,
) -> crate::Result<Option<Email<Get>>> {
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::<EmailGetResponse>()
.map(|mut r| r.take_list().pop())
}
pub fn email_changes(
&self,
since_state: impl Into<String>,
max_changes: Option<usize>,
) -> crate::Result<ChangesResponse<Email<Get>>> {
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<impl Into<Filter<super::query::Filter>>>,
sort: Option<impl IntoIterator<Item = Comparator<super::query::Comparator>>>,
) -> crate::Result<QueryResponse> {
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::<QueryResponse>()
}
pub fn email_query_changes(
&self,
since_query_state: impl Into<String>,
filter: Option<impl Into<Filter<super::query::Filter>>>,
) -> crate::Result<QueryChangesResponse> {
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::<QueryChangesResponse>()
}
pub fn email_parse(
&self,
blob_id: &str,
properties: Option<impl IntoIterator<Item = Property>>,
body_properties: Option<impl IntoIterator<Item = BodyProperty>>,
max_body_value_bytes: Option<usize>,
) -> crate::Result<Email> {
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::<EmailParseResponse>()
.and_then(|mut r| r.parsed(blob_id))
}
pub fn email_copy<T, U, V, W>(
&self,
from_account_id: impl Into<String>,
id: impl Into<String>,
mailbox_ids: T,
keywords: Option<V>,
received_at: Option<i64>,
) -> crate::Result<Email>
where
T: IntoIterator<Item = U>,
U: Into<String>,
V: IntoIterator<Item = W>,
W: Into<String>,
{
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::<EmailCopyResponse>()?.created(&id)
}
pub fn search_snippet_get(
&self,
filter: Option<impl Into<Filter<super::query::Filter>>>,
email_ids: impl IntoIterator<Item = impl Into<String>>,
) -> crate::Result<SearchSnippetGetResponse> {
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::<SearchSnippetGetResponse>()
}
}
impl Request<'_> {
pub fn get_email(&mut self) -> &mut GetRequest<Email<Set>> {
self.add_method_call(
Method::GetEmail,
Arguments::email_get(self.params(Method::GetEmail)),
)
.email_get_mut()
}
pub fn send_get_email(self) -> crate::Result<EmailGetResponse> {
self.send_single()
}
pub fn changes_email(&mut self, since_state: impl Into<String>) -> &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<ChangesResponse<Email<Get>>> {
self.send_single()
}
pub fn query_email(&mut self) -> &mut QueryRequest<Email<Set>> {
self.add_method_call(
Method::QueryEmail,
Arguments::email_query(self.params(Method::QueryEmail)),
)
.email_query_mut()
}
pub fn send_query_email(self) -> crate::Result<QueryResponse> {
self.send_single()
}
pub fn query_email_changes(
&mut self,
since_query_state: impl Into<String>,
) -> &mut QueryChangesRequest<Email<Set>> {
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<QueryChangesResponse> {
self.send_single()
}
pub fn set_email(&mut self) -> &mut SetRequest<Email<Set>> {
self.add_method_call(
Method::SetEmail,
Arguments::email_set(self.params(Method::SetEmail)),
)
.email_set_mut()
}
pub fn send_set_email(self) -> crate::Result<EmailSetResponse> {
self.send_single()
}
pub fn copy_email(
&mut self,
from_account_id: impl Into<String>,
) -> &mut CopyRequest<Email<Set>> {
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<EmailCopyResponse> {
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<EmailImportResponse> {
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<EmailParseResponse> {
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<SearchSnippetGetResponse> {
self.send_single()
}
}

View File

@ -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;

View File

@ -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<String>,
@ -45,6 +46,7 @@ impl Client {
.created(&id)
}
#[maybe_async::maybe_async]
pub async fn email_submission_create_envelope<S, T, U>(
&self,
email_id: impl Into<String>,
@ -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<impl Into<Filter<super::query::Filter>>>,
@ -129,6 +135,7 @@ impl Client {
request.send_single::<QueryResponse>().await
}
#[maybe_async::maybe_async]
pub async fn email_submission_changes(
&self,
since_state: impl Into<String>,
@ -152,6 +159,7 @@ impl Request<'_> {
.email_submission_get_mut()
}
#[maybe_async::maybe_async]
pub async fn send_get_email_submission(self) -> crate::Result<EmailSubmissionGetResponse> {
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<ChangesResponse<EmailSubmission<Get>>> {
@ -186,6 +195,7 @@ impl Request<'_> {
.email_submission_query_mut()
}
#[maybe_async::maybe_async]
pub async fn send_query_email_submission(self) -> crate::Result<QueryResponse> {
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<QueryChangesResponse> {
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<EmailSubmissionSetResponse> {
self.send_single().await
}

View File

@ -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 <LICENSE-APACHE or
* https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or https://opensource.org/licenses/MIT>, 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<String>,
identity_id: impl Into<String>,
) -> crate::Result<EmailSubmission<Get>> {
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::<EmailSubmissionSetResponse>()?
.created(&id)
}
pub fn email_submission_create_envelope<S, T, U>(
&self,
email_id: impl Into<String>,
identity_id: impl Into<String>,
mail_from: S,
rcpt_to: T,
) -> crate::Result<EmailSubmission<Get>>
where
S: Into<Address>,
T: IntoIterator<Item = U>,
U: Into<Address>,
{
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::<EmailSubmissionSetResponse>()?
.created(&id)
}
pub fn email_submission_change_status(
&self,
id: &str,
undo_status: UndoStatus,
) -> crate::Result<Option<EmailSubmission>> {
let mut request = self.build();
request
.set_email_submission()
.update(id)
.undo_status(undo_status);
request
.send_single::<EmailSubmissionSetResponse>()?
.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::<EmailSubmissionSetResponse>()?
.destroyed(id)
}
pub fn email_submission_get(
&self,
id: &str,
properties: Option<Vec<Property>>,
) -> crate::Result<Option<EmailSubmission>> {
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::<EmailSubmissionGetResponse>()
.map(|mut r| r.take_list().pop())
}
pub fn email_submission_query(
&self,
filter: Option<impl Into<Filter<super::query::Filter>>>,
sort: Option<impl IntoIterator<Item = Comparator<super::query::Comparator>>>,
) -> crate::Result<QueryResponse> {
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::<QueryResponse>()
}
pub fn email_submission_changes(
&self,
since_state: impl Into<String>,
max_changes: usize,
) -> crate::Result<ChangesResponse<EmailSubmission<Get>>> {
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<EmailSubmission<Set>> {
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<EmailSubmissionGetResponse> {
self.send_single()
}
pub fn changes_email_submission(
&mut self,
since_state: impl Into<String>,
) -> &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<ChangesResponse<EmailSubmission<Get>>> {
self.send_single()
}
pub fn query_email_submission(&mut self) -> &mut QueryRequest<EmailSubmission<Set>> {
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<QueryResponse> {
self.send_single()
}
pub fn query_email_submission_changes(
&mut self,
since_query_state: impl Into<String>,
) -> &mut QueryChangesRequest<EmailSubmission<Set>> {
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<QueryChangesResponse> {
self.send_single()
}
pub fn set_email_submission(&mut self) -> &mut SetRequest<EmailSubmission<Set>> {
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<EmailSubmissionSetResponse> {
self.send_single()
}
}

View File

@ -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;

View File

@ -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<String>,
@ -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<String>,
@ -90,6 +94,7 @@ impl Request<'_> {
.identity_get_mut()
}
#[maybe_async::maybe_async]
pub async fn send_get_identity(self) -> crate::Result<IdentityGetResponse> {
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<IdentitySetResponse> {
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<ChangesResponse<Identity<Get>>> {
self.send_single().await
}

View File

@ -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 <LICENSE-APACHE or
* https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or https://opensource.org/licenses/MIT>, 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<String>,
email: impl Into<String>,
) -> crate::Result<Identity> {
let mut request = self.build();
let id = request
.set_identity()
.create()
.name(name)
.email(email)
.create_id()
.unwrap();
request.send_single::<IdentitySetResponse>()?.created(&id)
}
pub fn identity_destroy(&self, id: &str) -> crate::Result<()> {
let mut request = self.build();
request.set_identity().destroy([id]);
request.send_single::<IdentitySetResponse>()?.destroyed(id)
}
pub fn identity_get(
&self,
id: &str,
properties: Option<Vec<Property>>,
) -> crate::Result<Option<Identity>> {
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::<IdentityGetResponse>()
.map(|mut r| r.take_list().pop())
}
pub fn identity_changes(
&self,
since_state: impl Into<String>,
max_changes: usize,
) -> crate::Result<ChangesResponse<Identity<Get>>> {
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<Identity<Set>> {
self.add_method_call(
Method::GetIdentity,
Arguments::identity_get(self.params(Method::GetIdentity)),
)
.identity_get_mut()
}
pub fn send_get_identity(self) -> crate::Result<IdentityGetResponse> {
self.send_single()
}
pub fn set_identity(&mut self) -> &mut SetRequest<Identity<Set>> {
self.add_method_call(
Method::SetIdentity,
Arguments::identity_set(self.params(Method::SetIdentity)),
)
.identity_set_mut()
}
pub fn send_set_identity(self) -> crate::Result<IdentitySetResponse> {
self.send_single()
}
pub fn changes_identity(&mut self, since_state: impl Into<String>) -> &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<ChangesResponse<Identity<Get>>> {
self.send_single()
}
}

View File

@ -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;

View File

@ -365,7 +365,7 @@ pub enum Error {
Transport(reqwest::Error),
Parse(serde_json::Error),
Internal(String),
Problem(ProblemDetails),
Problem(Box<ProblemDetails>),
Server(String),
Method(MethodError),
Set(SetError<String>),
@ -395,7 +395,7 @@ impl From<MethodError> for Error {
impl From<ProblemDetails> for Error {
fn from(e: ProblemDetails) -> Self {
Error::Problem(e)
Error::Problem(Box::new(e))
}
}

View File

@ -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<String>,
@ -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<impl Into<Filter<super::query::Filter>>>,
@ -175,6 +185,7 @@ impl Client {
request.send_single::<QueryResponse>().await
}
#[maybe_async::maybe_async]
pub async fn mailbox_changes(
&self,
since_state: impl Into<String>,
@ -197,6 +208,7 @@ impl Request<'_> {
.mailbox_get_mut()
}
#[maybe_async::maybe_async]
pub async fn send_get_mailbox(self) -> crate::Result<MailboxGetResponse> {
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<ChangesResponse<Mailbox<Get>>> {
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<QueryResponse> {
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<QueryChangesResponse> {
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<MailboxSetResponse> {
self.send_single().await
}

View File

@ -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 <LICENSE-APACHE or
* https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or https://opensource.org/licenses/MIT>, 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<String>,
parent_id: Option<impl Into<String>>,
role: Role,
) -> crate::Result<Mailbox> {
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::<MailboxSetResponse>()?.created(&id)
}
pub fn mailbox_rename(
&self,
id: &str,
name: impl Into<String>,
) -> crate::Result<Option<Mailbox>> {
let mut request = self.build();
request.set_mailbox().update(id).name(name);
request.send_single::<MailboxSetResponse>()?.updated(id)
}
pub fn mailbox_move(
&self,
id: &str,
parent_id: Option<impl Into<String>>,
) -> crate::Result<Option<Mailbox>> {
let mut request = self.build();
request.set_mailbox().update(id).parent_id(parent_id);
request.send_single::<MailboxSetResponse>()?.updated(id)
}
pub fn mailbox_update_role(&self, id: &str, role: Role) -> crate::Result<Option<Mailbox>> {
let mut request = self.build();
request.set_mailbox().update(id).role(role);
request.send_single::<MailboxSetResponse>()?.updated(id)
}
pub fn mailbox_update_acl(
&self,
id: &str,
account_id: &str,
acl: impl IntoIterator<Item = ACL>,
) -> crate::Result<Option<Mailbox>> {
let mut request = self.build();
request.set_mailbox().update(id).acl(account_id, acl);
request.send_single::<MailboxSetResponse>()?.updated(id)
}
pub fn mailbox_update_sort_order(
&self,
id: &str,
sort_order: u32,
) -> crate::Result<Option<Mailbox>> {
let mut request = self.build();
request.set_mailbox().update(id).sort_order(sort_order);
request.send_single::<MailboxSetResponse>()?.updated(id)
}
pub fn mailbox_subscribe(
&self,
id: &str,
is_subscribed: bool,
) -> crate::Result<Option<Mailbox>> {
let mut request = self.build();
request
.set_mailbox()
.update(id)
.is_subscribed(is_subscribed);
request.send_single::<MailboxSetResponse>()?.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::<MailboxSetResponse>()?.destroyed(id)
}
pub fn mailbox_get(
&self,
id: &str,
properties: Option<impl IntoIterator<Item = Property>>,
) -> crate::Result<Option<Mailbox>> {
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::<MailboxGetResponse>()
.map(|mut r| r.take_list().pop())
}
pub fn mailbox_query(
&self,
filter: Option<impl Into<Filter<super::query::Filter>>>,
sort: Option<impl IntoIterator<Item = Comparator<super::query::Comparator>>>,
) -> crate::Result<QueryResponse> {
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::<QueryResponse>()
}
pub fn mailbox_changes(
&self,
since_state: impl Into<String>,
max_changes: usize,
) -> crate::Result<ChangesResponse<Mailbox<Get>>> {
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<Mailbox<Set>> {
self.add_method_call(
Method::GetMailbox,
Arguments::mailbox_get(self.params(Method::GetMailbox)),
)
.mailbox_get_mut()
}
pub fn send_get_mailbox(self) -> crate::Result<MailboxGetResponse> {
self.send_single()
}
pub fn changes_mailbox(&mut self, since_state: impl Into<String>) -> &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<ChangesResponse<Mailbox<Get>>> {
self.send_single()
}
pub fn query_mailbox(&mut self) -> &mut QueryRequest<Mailbox<Set>> {
self.add_method_call(
Method::QueryMailbox,
Arguments::mailbox_query(self.params(Method::QueryMailbox)),
)
.mailbox_query_mut()
}
pub fn send_query_mailbox(self) -> crate::Result<QueryResponse> {
self.send_single()
}
pub fn query_mailbox_changes(
&mut self,
since_query_state: impl Into<String>,
) -> &mut QueryChangesRequest<Mailbox<Set>> {
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<QueryChangesResponse> {
self.send_single()
}
pub fn set_mailbox(&mut self) -> &mut SetRequest<Mailbox<Set>> {
self.add_method_call(
Method::SetMailbox,
Arguments::mailbox_set(self.params(Method::SetMailbox)),
)
.mailbox_set_mut()
}
pub fn send_set_mailbox(self) -> crate::Result<MailboxSetResponse> {
self.send_single()
}
}

View File

@ -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")]

View File

@ -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<String>,
@ -48,6 +49,7 @@ impl Client {
.created(&id)
}
#[maybe_async::maybe_async]
pub async fn domain_create(&self, name: impl Into<String>) -> crate::Result<Principal> {
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<String>,
@ -104,6 +108,7 @@ impl Client {
.created(&id)
}
#[maybe_async::maybe_async]
pub async fn group_create(
&self,
email: impl Into<String>,
@ -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<impl Into<Filter<super::query::Filter>>>,
@ -261,6 +276,7 @@ impl Client {
request.send_single::<QueryResponse>().await
}
#[maybe_async::maybe_async]
pub async fn principal_changes(
&self,
since_state: impl Into<String>,
@ -283,6 +299,7 @@ impl Request<'_> {
.principal_get_mut()
}
#[maybe_async::maybe_async]
pub async fn send_get_principal(self) -> crate::Result<PrincipalGetResponse> {
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<ChangesResponse<Principal<Get>>> {
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<QueryResponse> {
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<QueryChangesResponse> {
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<PrincipalSetResponse> {
self.send_single().await
}

View File

@ -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 <LICENSE-APACHE or
* https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or https://opensource.org/licenses/MIT>, 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<String>,
secret: impl Into<String>,
name: impl Into<String>,
) -> crate::Result<Principal> {
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::<PrincipalSetResponse>()?.created(&id)
}
pub fn domain_create(&self, name: impl Into<String>) -> crate::Result<Principal> {
let mut request = self.build();
let id = request
.set_principal()
.create()
.name(name)
.ptype(Type::Domain)
.create_id()
.unwrap();
request.send_single::<PrincipalSetResponse>()?.created(&id)
}
pub fn list_create(
&self,
email: impl Into<String>,
name: impl Into<String>,
members: impl IntoIterator<Item = impl Into<String>>,
) -> crate::Result<Principal> {
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::<PrincipalSetResponse>()?.created(&id)
}
pub fn group_create(
&self,
email: impl Into<String>,
name: impl Into<String>,
members: impl IntoIterator<Item = impl Into<String>>,
) -> crate::Result<Principal> {
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::<PrincipalSetResponse>()?.created(&id)
}
pub fn principal_set_name(
&self,
id: &str,
name: impl Into<String>,
) -> crate::Result<Option<Principal>> {
let mut request = self.build();
request.set_principal().update(id).name(name);
request.send_single::<PrincipalSetResponse>()?.updated(id)
}
pub fn principal_set_secret(
&self,
id: &str,
secret: impl Into<String>,
) -> crate::Result<Option<Principal>> {
let mut request = self.build();
request.set_principal().update(id).secret(secret);
request.send_single::<PrincipalSetResponse>()?.updated(id)
}
pub fn principal_set_email(
&self,
id: &str,
email: impl Into<String>,
) -> crate::Result<Option<Principal>> {
let mut request = self.build();
request.set_principal().update(id).email(email);
request.send_single::<PrincipalSetResponse>()?.updated(id)
}
pub fn principal_set_timezone(
&self,
id: &str,
timezone: Option<impl Into<String>>,
) -> crate::Result<Option<Principal>> {
let mut request = self.build();
request.set_principal().update(id).timezone(timezone);
request.send_single::<PrincipalSetResponse>()?.updated(id)
}
pub fn principal_set_members(
&self,
id: &str,
members: Option<impl IntoIterator<Item = impl Into<String>>>,
) -> crate::Result<Option<Principal>> {
let mut request = self.build();
request.set_principal().update(id).members(members);
request.send_single::<PrincipalSetResponse>()?.updated(id)
}
pub fn principal_set_aliases(
&self,
id: &str,
aliases: Option<impl IntoIterator<Item = impl Into<String>>>,
) -> crate::Result<Option<Principal>> {
let mut request = self.build();
request.set_principal().update(id).aliases(aliases);
request.send_single::<PrincipalSetResponse>()?.updated(id)
}
pub fn principal_set_capabilities(
&self,
id: &str,
capabilities: Option<impl IntoIterator<Item = impl Into<String>>>,
) -> crate::Result<Option<Principal>> {
let mut request = self.build();
request
.set_principal()
.update(id)
.capabilities(capabilities);
request.send_single::<PrincipalSetResponse>()?.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::<PrincipalSetResponse>()?.destroyed(id)
}
pub fn principal_get(
&self,
id: &str,
properties: Option<impl IntoIterator<Item = Property>>,
) -> crate::Result<Option<Principal>> {
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::<PrincipalGetResponse>()
.map(|mut r| r.take_list().pop())
}
pub fn principal_query(
&self,
filter: Option<impl Into<Filter<super::query::Filter>>>,
sort: Option<impl IntoIterator<Item = Comparator<super::query::Comparator>>>,
) -> crate::Result<QueryResponse> {
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::<QueryResponse>()
}
pub fn principal_changes(
&self,
since_state: impl Into<String>,
max_changes: usize,
) -> crate::Result<ChangesResponse<Principal<Get>>> {
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<Principal<Set>> {
self.add_method_call(
Method::GetPrincipal,
Arguments::principal_get(self.params(Method::GetPrincipal)),
)
.principal_get_mut()
}
pub fn send_get_principal(self) -> crate::Result<PrincipalGetResponse> {
self.send_single()
}
pub fn changes_principal(&mut self, since_state: impl Into<String>) -> &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<ChangesResponse<Principal<Get>>> {
self.send_single()
}
pub fn query_principal(&mut self) -> &mut QueryRequest<Principal<Set>> {
self.add_method_call(
Method::QueryPrincipal,
Arguments::principal_query(self.params(Method::QueryPrincipal)),
)
.principal_query_mut()
}
pub fn send_query_principal(self) -> crate::Result<QueryResponse> {
self.send_single()
}
pub fn query_principal_changes(
&mut self,
since_query_state: impl Into<String>,
) -> &mut QueryChangesRequest<Principal<Set>> {
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<QueryChangesResponse> {
self.send_single()
}
pub fn set_principal(&mut self) -> &mut SetRequest<Principal<Set>> {
self.add_method_call(
Method::SetPrincipal,
Arguments::principal_set(self.params(Method::SetPrincipal)),
)
.principal_set_mut()
}
pub fn send_set_principal(self) -> crate::Result<PrincipalSetResponse> {
self.send_single()
}
}

View File

@ -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;

View File

@ -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<String>,
@ -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<PushSubscriptionGetResponse> {
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<PushSubscriptionSetResponse> {
self.send_single().await
}

View File

@ -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 <LICENSE-APACHE or
* https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or https://opensource.org/licenses/MIT>, 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<String>,
url: impl Into<String>,
keys: Option<Keys>,
) -> crate::Result<PushSubscription> {
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::<PushSubscriptionSetResponse>()?
.created(&id)
}
pub fn push_subscription_verify(
&self,
id: &str,
verification_code: impl Into<String>,
) -> crate::Result<Option<PushSubscription>> {
let mut request = self.build();
request
.set_push_subscription()
.update(id)
.verification_code(verification_code);
request
.send_single::<PushSubscriptionSetResponse>()?
.updated(id)
}
pub fn push_subscription_update_types(
&self,
id: &str,
types: Option<impl IntoIterator<Item = TypeState>>,
) -> crate::Result<Option<PushSubscription>> {
let mut request = self.build();
request.set_push_subscription().update(id).types(types);
request
.send_single::<PushSubscriptionSetResponse>()?
.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::<PushSubscriptionSetResponse>()?
.destroyed(id)
}
}
impl Request<'_> {
pub fn get_push_subscription(&mut self) -> &mut GetRequest<PushSubscription<Set>> {
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<PushSubscriptionGetResponse> {
self.send_single()
}
pub fn set_push_subscription(&mut self) -> &mut SetRequest<PushSubscription<Set>> {
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<PushSubscriptionSetResponse> {
self.send_single()
}
}

View File

@ -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;

View File

@ -86,8 +86,8 @@ impl SetObject for PushSubscription<Get> {
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),
}
}
}

View File

@ -27,6 +27,7 @@ use super::{
};
impl Client {
#[maybe_async::maybe_async]
pub async fn sieve_script_create(
&self,
name: impl Into<String>,
@ -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<impl Into<Filter<super::query::Filter>>>,
@ -155,6 +163,7 @@ impl Client {
request.send_single::<QueryResponse>().await
}
#[maybe_async::maybe_async]
pub async fn sieve_script_validate(&self, script: impl Into<Vec<u8>>) -> 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<SieveScriptGetResponse> {
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<SieveScriptSetResponse> {
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<SieveScriptValidateResponse> {
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<QueryResponse> {
self.send_single().await
}

View File

@ -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 <LICENSE-APACHE or
* https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or https://opensource.org/licenses/MIT>, 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<String>,
script: impl Into<Vec<u8>>,
activate: bool,
) -> crate::Result<SieveScript> {
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::<SieveScriptSetResponse>()?
.created(&id)
}
pub fn sieve_script_replace(
&self,
id: &str,
script: impl Into<Vec<u8>>,
activate: bool,
) -> crate::Result<Option<SieveScript>> {
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::<SieveScriptSetResponse>()?.updated(id)
}
pub fn sieve_script_rename(
&self,
id: &str,
name: impl Into<String>,
activate: bool,
) -> crate::Result<Option<SieveScript>> {
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::<SieveScriptSetResponse>()?.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::<SieveScriptSetResponse>()?
.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::<SieveScriptSetResponse>()?
.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::<SieveScriptSetResponse>()?
.destroyed(id)
}
pub fn sieve_script_get(
&self,
id: &str,
properties: Option<impl IntoIterator<Item = Property>>,
) -> crate::Result<Option<SieveScript>> {
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::<SieveScriptGetResponse>()
.map(|mut r| r.take_list().pop())
}
pub fn sieve_script_query(
&self,
filter: Option<impl Into<Filter<super::query::Filter>>>,
sort: Option<impl IntoIterator<Item = Comparator<super::query::Comparator>>>,
) -> crate::Result<QueryResponse> {
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::<QueryResponse>()
}
pub fn sieve_script_validate(&self, script: impl Into<Vec<u8>>) -> 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::<SieveScriptValidateResponse>()?
.unwrap_error()
}
}
impl Request<'_> {
pub fn get_sieve_script(&mut self) -> &mut GetRequest<SieveScript<Set>> {
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<SieveScriptGetResponse> {
self.send_single()
}
pub fn set_sieve_script(&mut self) -> &mut SetRequest<SieveScript<Set>> {
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<SieveScriptSetResponse> {
self.send_single()
}
pub fn validate_sieve_script(
&mut self,
blob_id: impl Into<String>,
) -> &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<SieveScriptValidateResponse> {
self.send_single()
}
pub fn query_sieve_script(&mut self) -> &mut QueryRequest<SieveScript<Set>> {
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<QueryResponse> {
self.send_single()
}
}

View File

@ -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;

View File

@ -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<Option<Thread>> {
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<ThreadGetResponse> {
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<ChangesResponse<Thread>> {
self.send_single().await
}

View File

@ -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 <LICENSE-APACHE or
* https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or https://opensource.org/licenses/MIT>, 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<Option<Thread>> {
let mut request = self.build();
request.get_thread().ids([id]);
request
.send_single::<ThreadGetResponse>()
.map(|mut r| r.take_list().pop())
}
}
impl Request<'_> {
pub fn get_thread(&mut self) -> &mut GetRequest<Thread> {
self.add_method_call(
Method::GetThread,
Arguments::thread_get(self.params(Method::GetThread)),
)
.thread_get_mut()
}
pub fn send_get_thread(self) -> crate::Result<ThreadGetResponse> {
self.send_single()
}
pub fn changes_thread(&mut self, since_state: impl Into<String>) -> &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<ChangesResponse<Thread>> {
self.send_single()
}
}

View File

@ -10,10 +10,7 @@
*/
pub mod get;
#[cfg(feature = "async")]
pub mod helpers;
#[cfg(feature = "blocking")]
pub mod helpers_blocking;
use std::fmt::Display;

View File

@ -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 <LICENSE-APACHE or
* https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or https://opensource.org/licenses/MIT>, 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<String>,
text_body: Option<impl Into<String>>,
html_body: Option<impl Into<String>>,
) -> crate::Result<VacationResponse> {
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::<VacationResponseSetResponse>()?
.created(&created_id)
}
pub fn vacation_response_enable(
&self,
subject: impl Into<String>,
text_body: Option<impl Into<String>>,
html_body: Option<impl Into<String>>,
) -> crate::Result<Option<VacationResponse>> {
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::<VacationResponseSetResponse>()?
.updated("singleton")
}
pub fn vacation_response_disable(&self) -> crate::Result<Option<VacationResponse>> {
let mut request = self.build();
request
.set_vacation_response()
.update("singleton")
.is_enabled(false);
request
.send_single::<VacationResponseSetResponse>()?
.updated("singleton")
}
pub fn vacation_response_set_dates(
&self,
from_date: Option<i64>,
to_date: Option<i64>,
) -> crate::Result<Option<VacationResponse>> {
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::<VacationResponseSetResponse>()?
.updated("singleton")
}
pub fn vacation_response_get(
&self,
properties: Option<impl IntoIterator<Item = Property>>,
) -> crate::Result<Option<VacationResponse>> {
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::<VacationResponseGetResponse>()
.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::<VacationResponseSetResponse>()?
.destroyed("singleton")
}
}
impl Request<'_> {
pub fn get_vacation_response(&mut self) -> &mut GetRequest<VacationResponse<Set>> {
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<VacationResponseGetResponse> {
self.send_single()
}
pub fn set_vacation_response(&mut self) -> &mut SetRequest<VacationResponse<Set>> {
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<VacationResponseSetResponse> {
self.send_single()
}
}