mailboxes/
mailboxes.rs

1/*
2 * Copyright Stalwart Labs LLC See the COPYING
3 * file at the top-level directory of this distribution.
4 *
5 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 * file at the top-level directory of this distribution.
8 *
9 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
10 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
11 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
12 * option. This file may not be copied, modified, or distributed
13 * except according to those terms.
14 */
15
16#[cfg(feature = "async")]
17use jmap_client::{
18    client::Client,
19    mailbox::{query::Filter, Role},
20};
21
22#[cfg(feature = "async")]
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}
68
69fn main() {
70    #[cfg(feature = "async")]
71    let _c = mailboxes();
72}