From 5cc21ed1b534806baa63253fc72d58a8279c4174 Mon Sep 17 00:00:00 2001 From: Mauro D Date: Sun, 10 Jul 2022 16:24:52 +0000 Subject: [PATCH] More API improvements. --- src/blob/upload.rs | 2 +- src/client.rs | 1 + src/core/query.rs | 4 ++++ src/core/set.rs | 4 ++++ src/email/helpers.rs | 30 +++++++++++++++++++++++++++++- src/email/import.rs | 5 +++++ 6 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/blob/upload.rs b/src/blob/upload.rs index f1fc33d..c47448d 100644 --- a/src/blob/upload.rs +++ b/src/blob/upload.rs @@ -23,10 +23,10 @@ pub struct UploadResponse { impl Client { pub async fn upload( &self, + account_id: &str, blob: Vec, content_type: Option<&str>, ) -> crate::Result { - let account_id = self.default_account_id(); let mut upload_url = String::with_capacity(self.session().upload_url().len() + account_id.len()); diff --git a/src/client.rs b/src/client.rs index b8a038a..842d2be 100644 --- a/src/client.rs +++ b/src/client.rs @@ -25,6 +25,7 @@ use crate::{ const DEFAULT_TIMEOUT_MS: u64 = 10 * 1000; static USER_AGENT: &str = concat!("jmap-client/", env!("CARGO_PKG_VERSION")); +#[derive(Debug)] pub enum Credentials { Basic(String), Bearer(String), diff --git a/src/core/query.rs b/src/core/query.rs index 1b94536..c3f1a1a 100644 --- a/src/core/query.rs +++ b/src/core/query.rs @@ -203,6 +203,10 @@ impl QueryResponse { self.position } + pub fn unwrap_query_state(&mut self) -> String { + std::mem::take(&mut self.query_state) + } + pub fn query_state(&self) -> &str { &self.query_state } diff --git a/src/core/set.rs b/src/core/set.rs index fc2f683..79a9cc1 100644 --- a/src/core/set.rs +++ b/src/core/set.rs @@ -284,6 +284,10 @@ impl SetResponse { self.destroyed.as_ref().map(|list| list.iter()) } + pub fn unwrap_destroyed_ids(&mut self) -> Option> { + self.destroyed.take() + } + pub fn not_created_ids(&self) -> Option> { self.not_created.as_ref().map(|map| map.keys()) } diff --git a/src/email/helpers.rs b/src/email/helpers.rs index c148b60..d08861f 100644 --- a/src/email/helpers.rs +++ b/src/email/helpers.rs @@ -34,10 +34,38 @@ impl Client { V: IntoIterator, W: Into, { - let blob_id = self.upload(raw_message, None).await?.unwrap_blob_id(); + self.email_import_account( + self.default_account_id(), + raw_message, + mailbox_ids, + keywords, + received_at, + ) + .await + } + + pub async 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(account_id, raw_message, None) + .await? + .unwrap_blob_id(); let mut request = self.build(); let import_request = request .import_email() + .account_id(account_id) .email(blob_id) .mailbox_ids(mailbox_ids); diff --git a/src/email/import.rs b/src/email/import.rs index c89de3f..d2726ee 100644 --- a/src/email/import.rs +++ b/src/email/import.rs @@ -78,6 +78,11 @@ impl EmailImportRequest { } } + pub fn account_id(&mut self, account_id: impl Into) -> &mut Self { + self.account_id = account_id.into(); + self + } + pub fn if_in_state(&mut self, if_in_state: impl Into) -> &mut Self { self.if_in_state = Some(if_in_state.into()); self