pub struct Mailbox<State = Get> { /* private fields */ }
Implementations§
Source§impl Mailbox<Get>
impl Mailbox<Get>
pub fn id(&self) -> Option<&str>
Sourcepub fn take_id(&mut self) -> String
pub fn take_id(&mut self) -> String
Examples found in repository?
examples/mailboxes.rs (line 36)
23async fn mailboxes() {
24 // Connect to the JMAP server using Basic authentication
25 let client = Client::new()
26 .credentials(("john@example.org", "secret"))
27 .connect("https://jmap.example.org")
28 .await
29 .unwrap();
30
31 // Create a mailbox
32 let mailbox_id = client
33 .mailbox_create("My Mailbox", None::<String>, Role::None)
34 .await
35 .unwrap()
36 .take_id();
37
38 // Rename a mailbox
39 client
40 .mailbox_rename(&mailbox_id, "My Renamed Mailbox")
41 .await
42 .unwrap();
43
44 // Query mailboxes to obtain Inbox's id
45 let inbox_id = client
46 .mailbox_query(Filter::role(Role::Inbox).into(), None::<Vec<_>>)
47 .await
48 .unwrap()
49 .take_ids()
50 .pop()
51 .unwrap();
52
53 // Print Inbox's details
54 println!(
55 "{:?}",
56 client.mailbox_get(&inbox_id, None::<Vec<_>>).await.unwrap()
57 );
58
59 // Move the newly created mailbox under Inbox
60 client
61 .mailbox_move(&mailbox_id, inbox_id.into())
62 .await
63 .unwrap();
64
65 // Delete the mailbox including any messages
66 client.mailbox_destroy(&mailbox_id, true).await.unwrap();
67}
More examples
examples/websocket.rs (line 65)
25async fn websocket() {
26 // Connect to the JMAP server using Basic authentication
27 let client = Client::new()
28 .credentials(("john@example.org", "secret"))
29 .connect("https://jmap.example.org")
30 .await
31 .unwrap();
32
33 // Connect to the WebSocket endpoint
34 let mut ws_stream = client.connect_ws().await.unwrap();
35
36 // Read WS messages on a separate thread
37 let (stream_tx, mut stream_rx) = mpsc::channel::<WebSocketMessage>(100);
38 tokio::spawn(async move {
39 while let Some(change) = ws_stream.next().await {
40 stream_tx.send(change.unwrap()).await.unwrap();
41 }
42 });
43
44 // Create a mailbox over WS
45 let mut request = client.build();
46 let create_id = request
47 .set_mailbox()
48 .create()
49 .name("WebSocket Test")
50 .create_id()
51 .unwrap();
52 let request_id = request.send_ws().await.unwrap();
53
54 // Read response from WS stream
55 let mailbox_id = if let Some(WebSocketMessage::Response(mut response)) = stream_rx.recv().await
56 {
57 assert_eq!(request_id, response.request_id().unwrap());
58 response
59 .pop_method_response()
60 .unwrap()
61 .unwrap_set_mailbox()
62 .unwrap()
63 .created(&create_id)
64 .unwrap()
65 .take_id()
66 } else {
67 unreachable!()
68 };
69
70 // Enable push notifications over WS
71 client
72 .enable_push_ws(None::<Vec<_>>, None::<&str>)
73 .await
74 .unwrap();
75
76 // Make changes over standard HTTP and expect a push notification via WS
77 client
78 .mailbox_update_sort_order(&mailbox_id, 1)
79 .await
80 .unwrap();
81 if let Some(WebSocketMessage::StateChange(changes)) = stream_rx.recv().await {
82 println!("Received changes: {:?}", changes);
83 } else {
84 unreachable!()
85 }
86}
pub fn name(&self) -> Option<&str>
pub fn parent_id(&self) -> Option<&str>
pub fn role(&self) -> Role
pub fn sort_order(&self) -> u32
pub fn total_emails(&self) -> usize
pub fn unread_emails(&self) -> usize
pub fn total_threads(&self) -> usize
pub fn unread_threads(&self) -> usize
pub fn is_subscribed(&self) -> bool
pub fn my_rights(&self) -> Option<&MailboxRights>
pub fn acl(&self) -> Option<&AHashMap<String, Vec<ACL>>>
pub fn take_acl(&mut self) -> Option<AHashMap<String, Vec<ACL>>>
Source§impl Mailbox<Set>
impl Mailbox<Set>
Sourcepub fn name(&mut self, name: impl Into<String>) -> &mut Self
pub fn name(&mut self, name: impl Into<String>) -> &mut Self
Examples found in repository?
examples/websocket.rs (line 49)
25async fn websocket() {
26 // Connect to the JMAP server using Basic authentication
27 let client = Client::new()
28 .credentials(("john@example.org", "secret"))
29 .connect("https://jmap.example.org")
30 .await
31 .unwrap();
32
33 // Connect to the WebSocket endpoint
34 let mut ws_stream = client.connect_ws().await.unwrap();
35
36 // Read WS messages on a separate thread
37 let (stream_tx, mut stream_rx) = mpsc::channel::<WebSocketMessage>(100);
38 tokio::spawn(async move {
39 while let Some(change) = ws_stream.next().await {
40 stream_tx.send(change.unwrap()).await.unwrap();
41 }
42 });
43
44 // Create a mailbox over WS
45 let mut request = client.build();
46 let create_id = request
47 .set_mailbox()
48 .create()
49 .name("WebSocket Test")
50 .create_id()
51 .unwrap();
52 let request_id = request.send_ws().await.unwrap();
53
54 // Read response from WS stream
55 let mailbox_id = if let Some(WebSocketMessage::Response(mut response)) = stream_rx.recv().await
56 {
57 assert_eq!(request_id, response.request_id().unwrap());
58 response
59 .pop_method_response()
60 .unwrap()
61 .unwrap_set_mailbox()
62 .unwrap()
63 .created(&create_id)
64 .unwrap()
65 .take_id()
66 } else {
67 unreachable!()
68 };
69
70 // Enable push notifications over WS
71 client
72 .enable_push_ws(None::<Vec<_>>, None::<&str>)
73 .await
74 .unwrap();
75
76 // Make changes over standard HTTP and expect a push notification via WS
77 client
78 .mailbox_update_sort_order(&mailbox_id, 1)
79 .await
80 .unwrap();
81 if let Some(WebSocketMessage::StateChange(changes)) = stream_rx.recv().await {
82 println!("Received changes: {:?}", changes);
83 } else {
84 unreachable!()
85 }
86}
pub fn parent_id(&mut self, parent_id: Option<impl Into<String>>) -> &mut Self
pub fn parent_id_ref(&mut self, parent_id_ref: &str) -> &mut Self
pub fn role(&mut self, role: Role) -> &mut Self
pub fn sort_order(&mut self, sort_order: u32) -> &mut Self
pub fn is_subscribed(&mut self, is_subscribed: bool) -> &mut Self
pub fn acls<T, U, V>(&mut self, acls: T) -> &mut Self
pub fn acl(&mut self, id: &str, acl: impl IntoIterator<Item = ACL>) -> &mut Self
pub fn acl_set(&mut self, id: &str, acl: ACL, set: bool) -> &mut Self
Trait Implementations§
Source§impl ChangesObject for Mailbox<Get>
impl ChangesObject for Mailbox<Get>
Source§impl ChangesObject for Mailbox<Set>
impl ChangesObject for Mailbox<Set>
Source§impl<'de, State> Deserialize<'de> for Mailbox<State>
impl<'de, State> Deserialize<'de> for Mailbox<State>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl QueryObject for Mailbox<Set>
impl QueryObject for Mailbox<Set>
Auto Trait Implementations§
impl<State> Freeze for Mailbox<State>
impl<State> RefUnwindSafe for Mailbox<State>where
State: RefUnwindSafe,
impl<State> Send for Mailbox<State>where
State: Send,
impl<State> Sync for Mailbox<State>where
State: Sync,
impl<State> Unpin for Mailbox<State>where
State: Unpin,
impl<State> UnwindSafe for Mailbox<State>where
State: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more