agentmail/client/
inboxes.rs1use crate::client::NoBody;
2use crate::client::scope::{Inboxes, Scoped};
3use crate::{Error, Page, types::*, util::urlish};
4
5impl<S: Inboxes> Scoped<'_, S> {
6 pub async fn create_inbox(&self, inbox: CreateInbox) -> Result<Inbox, Error> {
11 self.client
12 .request(
13 reqwest::Method::POST,
14 &format!("{}/inboxes", self.base()),
15 &[],
16 Some(&inbox),
17 )
18 .await
19 }
20
21 pub async fn list_inboxes(&self, page: Page) -> Result<InboxList, Error> {
23 self.client
24 .request(
25 reqwest::Method::GET,
26 &format!("{}/inboxes", self.base()),
27 &page.query(),
28 None::<&NoBody>,
29 )
30 .await
31 }
32
33 pub async fn list_all_inboxes(&self) -> Result<Vec<Inbox>, Error> {
35 let mut out = Vec::new();
36 let mut token = None;
37 loop {
38 let resp = self
39 .list_inboxes(Page {
40 limit: None,
41 page_token: token,
42 })
43 .await?;
44 let next = resp.next_page_token;
45 out.extend(resp.inboxes);
46 match next {
47 Some(t) => token = Some(t),
48 None => return Ok(out),
49 }
50 }
51 }
52
53 pub async fn get_inbox(&self, inbox_id: &str) -> Result<Inbox, Error> {
55 self.client
56 .request(
57 reqwest::Method::GET,
58 &format!("{}/inboxes/{}", self.base(), urlish(inbox_id)),
59 &[],
60 None::<&NoBody>,
61 )
62 .await
63 }
64
65 pub async fn update_inbox(&self, inbox_id: &str, update: UpdateInbox) -> Result<Inbox, Error> {
67 self.client
68 .request(
69 reqwest::Method::PATCH,
70 &format!("{}/inboxes/{}", self.base(), urlish(inbox_id)),
71 &[],
72 Some(&update),
73 )
74 .await
75 }
76
77 pub async fn delete_inbox(&self, inbox_id: &str) -> Result<(), Error> {
79 self.client
80 .request(
81 reqwest::Method::DELETE,
82 &format!("{}/inboxes/{}", self.base(), urlish(inbox_id)),
83 &[],
84 None::<&NoBody>,
85 )
86 .await
87 }
88}