More API improvements.

main
Mauro D 2022-07-10 16:24:52 +00:00
parent 890bfa3a70
commit 5cc21ed1b5
6 changed files with 44 additions and 2 deletions

View File

@ -23,10 +23,10 @@ pub struct UploadResponse {
impl Client { impl Client {
pub async fn upload( pub async fn upload(
&self, &self,
account_id: &str,
blob: Vec<u8>, blob: Vec<u8>,
content_type: Option<&str>, content_type: Option<&str>,
) -> crate::Result<UploadResponse> { ) -> crate::Result<UploadResponse> {
let account_id = self.default_account_id();
let mut upload_url = let mut upload_url =
String::with_capacity(self.session().upload_url().len() + account_id.len()); String::with_capacity(self.session().upload_url().len() + account_id.len());

View File

@ -25,6 +25,7 @@ use crate::{
const DEFAULT_TIMEOUT_MS: u64 = 10 * 1000; const DEFAULT_TIMEOUT_MS: u64 = 10 * 1000;
static USER_AGENT: &str = concat!("jmap-client/", env!("CARGO_PKG_VERSION")); static USER_AGENT: &str = concat!("jmap-client/", env!("CARGO_PKG_VERSION"));
#[derive(Debug)]
pub enum Credentials { pub enum Credentials {
Basic(String), Basic(String),
Bearer(String), Bearer(String),

View File

@ -203,6 +203,10 @@ impl QueryResponse {
self.position self.position
} }
pub fn unwrap_query_state(&mut self) -> String {
std::mem::take(&mut self.query_state)
}
pub fn query_state(&self) -> &str { pub fn query_state(&self) -> &str {
&self.query_state &self.query_state
} }

View File

@ -284,6 +284,10 @@ impl<O: SetObject> SetResponse<O> {
self.destroyed.as_ref().map(|list| list.iter()) self.destroyed.as_ref().map(|list| list.iter())
} }
pub fn unwrap_destroyed_ids(&mut self) -> Option<Vec<String>> {
self.destroyed.take()
}
pub fn not_created_ids(&self) -> Option<impl Iterator<Item = &String>> { pub fn not_created_ids(&self) -> Option<impl Iterator<Item = &String>> {
self.not_created.as_ref().map(|map| map.keys()) self.not_created.as_ref().map(|map| map.keys())
} }

View File

@ -34,10 +34,38 @@ impl Client {
V: IntoIterator<Item = W>, V: IntoIterator<Item = W>,
W: Into<String>, W: Into<String>,
{ {
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<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(account_id, raw_message, None)
.await?
.unwrap_blob_id();
let mut request = self.build(); let mut request = self.build();
let import_request = request let import_request = request
.import_email() .import_email()
.account_id(account_id)
.email(blob_id) .email(blob_id)
.mailbox_ids(mailbox_ids); .mailbox_ids(mailbox_ids);

View File

@ -78,6 +78,11 @@ impl EmailImportRequest {
} }
} }
pub fn account_id(&mut self, account_id: impl Into<String>) -> &mut Self {
self.account_id = account_id.into();
self
}
pub fn if_in_state(&mut self, if_in_state: impl Into<String>) -> &mut Self { pub fn if_in_state(&mut self, if_in_state: impl Into<String>) -> &mut Self {
self.if_in_state = Some(if_in_state.into()); self.if_in_state = Some(if_in_state.into());
self self