pub struct Client { /* private fields */ }
Implementations§
Source§impl Client
impl Client
Sourcepub fn new() -> ClientBuilder
pub fn new() -> ClientBuilder
Examples found in repository?
examples/mailboxes.rs (line 25)
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/eventsource.rs (line 24)
22async fn event_source() {
23 // Connect to the JMAP server using Basic authentication
24 let client = Client::new()
25 .credentials(("john@example.org", "secret"))
26 .connect("https://jmap.example.org")
27 .await
28 .unwrap();
29
30 // Open EventSource connection
31 let mut stream = client
32 .event_source(
33 [
34 TypeState::Email,
35 TypeState::EmailDelivery,
36 TypeState::Mailbox,
37 TypeState::EmailSubmission,
38 TypeState::Identity,
39 ]
40 .into(),
41 false,
42 60.into(),
43 None,
44 )
45 .await
46 .unwrap();
47
48 // Consume events
49 while let Some(event) = stream.next().await {
50 let changes = event.unwrap();
51 println!("-> Change id: {:?}", changes.id());
52 for account_id in changes.changed_accounts() {
53 println!(" Account {} has changes:", account_id);
54 if let Some(account_changes) = changes.changes(account_id) {
55 for (type_state, state_id) in account_changes {
56 println!(" Type {:?} has a new state {}.", type_state, state_id);
57 }
58 }
59 }
60 }
61}
examples/websocket.rs (line 27)
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}
examples/messages.rs (line 35)
33async fn messages() {
34 // Connect to the JMAP server using Basic authentication
35 let client = Client::new()
36 .credentials(("john@example.org", "secret"))
37 .connect("https://jmap.example.org")
38 .await
39 .unwrap();
40
41 // Query mailboxes to obtain Inbox and Trash folder id
42 let inbox_id = client
43 .mailbox_query(
44 mailbox::query::Filter::role(Role::Inbox).into(),
45 None::<Vec<_>>,
46 )
47 .await
48 .unwrap()
49 .take_ids()
50 .pop()
51 .unwrap();
52 let trash_id = client
53 .mailbox_query(
54 mailbox::query::Filter::role(Role::Trash).into(),
55 None::<Vec<_>>,
56 )
57 .await
58 .unwrap()
59 .take_ids()
60 .pop()
61 .unwrap();
62
63 // Import message into inbox
64 client
65 .email_import(TEST_MESSAGE.to_vec(), [&inbox_id], ["$draft"].into(), None)
66 .await
67 .unwrap();
68
69 // Query mailbox
70 let email_id = client
71 .email_query(
72 Filter::and([
73 email::query::Filter::subject("test"),
74 email::query::Filter::in_mailbox(&inbox_id),
75 email::query::Filter::has_keyword("$draft"),
76 ])
77 .into(),
78 [email::query::Comparator::from()].into(),
79 )
80 .await
81 .unwrap()
82 .take_ids()
83 .pop()
84 .unwrap();
85
86 // Fetch message
87 let email = client
88 .email_get(
89 &email_id,
90 [Property::Subject, Property::Preview, Property::Keywords].into(),
91 )
92 .await
93 .unwrap()
94 .unwrap();
95 assert_eq!(email.preview().unwrap(), "This is a test.");
96 assert_eq!(email.subject().unwrap(), "Testing JMAP client");
97 assert_eq!(email.keywords(), ["$draft"]);
98
99 // Remove the $draft keyword
100 client
101 .email_set_keyword(&email_id, "$draft", false)
102 .await
103 .unwrap();
104
105 // Replace all keywords
106 client
107 .email_set_keywords(&email_id, ["$seen", "$important"])
108 .await
109 .unwrap();
110
111 // Move the message to the Trash folder
112 client
113 .email_set_mailboxes(&email_id, [&trash_id])
114 .await
115 .unwrap();
116
117 // Destroy the e-mail
118 client.email_destroy(&email_id).await.unwrap();
119}
examples/result_reference.rs (line 22)
20async fn result_reference() {
21 // Connect to the JMAP server using Basic authentication
22 let client = Client::new()
23 .credentials(("john@example.org", "secret"))
24 .connect("https://jmap.example.org")
25 .await
26 .unwrap();
27
28 // Delete e-mails matching a filter
29 let mut request = client.build();
30 let result_ref = request
31 .query_email()
32 .filter(query::Filter::and([
33 email::query::Filter::has_keyword("$draft"),
34 email::query::Filter::from("bill"),
35 ]))
36 .result_reference();
37 request.set_email().destroy_ref(result_ref);
38 let _destroyed_ids = request
39 .send()
40 .await
41 .unwrap()
42 .unwrap_method_responses()
43 .pop()
44 .unwrap()
45 .unwrap_set_email()
46 .unwrap()
47 .take_destroyed_ids();
48
49 // Fetch mailboxes matching a filter
50 let mut request = client.build();
51 let query_result = request
52 .query_mailbox()
53 .filter(query::Filter::and([
54 mailbox::query::Filter::has_any_role(false),
55 mailbox::query::Filter::is_subscribed(true),
56 ]))
57 .result_reference();
58 request.get_mailbox().ids_ref(query_result).properties([
59 mailbox::Property::Id,
60 mailbox::Property::Name,
61 mailbox::Property::ParentId,
62 mailbox::Property::TotalEmails,
63 mailbox::Property::UnreadEmails,
64 ]);
65 let _mailboxes = request
66 .send()
67 .await
68 .unwrap()
69 .unwrap_method_responses()
70 .pop()
71 .unwrap()
72 .unwrap_get_mailbox()
73 .unwrap()
74 .take_list();
75
76 // Fetch only the updated properties of all mailboxes that changed
77 // since a state.
78 let mut request = client.build();
79 let changes_request = request.changes_mailbox("n").max_changes(0);
80 let properties_ref = changes_request.updated_properties_reference();
81 let updated_ref = changes_request.updated_reference();
82 request
83 .get_mailbox()
84 .ids_ref(updated_ref)
85 .properties_ref(properties_ref);
86 for mailbox in request
87 .send()
88 .await
89 .unwrap()
90 .unwrap_method_responses()
91 .pop()
92 .unwrap()
93 .unwrap_get_mailbox()
94 .unwrap()
95 .take_list()
96 {
97 println!("Changed mailbox: {:#?}", mailbox);
98 }
99}
pub fn set_timeout(&mut self, timeout: Duration) -> &mut Self
pub fn set_follow_redirects( &mut self, trusted_hosts: impl IntoIterator<Item = impl Into<String>>, ) -> &mut Self
pub fn timeout(&self) -> Duration
pub fn session(&self) -> Arc<Session>
pub fn session_url(&self) -> &str
pub fn headers(&self) -> &HeaderMap
pub async fn send<R>(&self, request: &Request<'_>) -> Result<Response<R>>where
R: DeserializeOwned,
pub async fn refresh_session(&self) -> Result<()>
pub fn is_session_updated(&self) -> bool
pub fn set_default_account_id( &mut self, defaul_account_id: impl Into<String>, ) -> &mut Self
pub fn default_account_id(&self) -> &str
Sourcepub fn build(&self) -> Request<'_>
pub fn build(&self) -> Request<'_>
Examples found in repository?
examples/websocket.rs (line 45)
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}
More examples
examples/result_reference.rs (line 29)
20async fn result_reference() {
21 // Connect to the JMAP server using Basic authentication
22 let client = Client::new()
23 .credentials(("john@example.org", "secret"))
24 .connect("https://jmap.example.org")
25 .await
26 .unwrap();
27
28 // Delete e-mails matching a filter
29 let mut request = client.build();
30 let result_ref = request
31 .query_email()
32 .filter(query::Filter::and([
33 email::query::Filter::has_keyword("$draft"),
34 email::query::Filter::from("bill"),
35 ]))
36 .result_reference();
37 request.set_email().destroy_ref(result_ref);
38 let _destroyed_ids = request
39 .send()
40 .await
41 .unwrap()
42 .unwrap_method_responses()
43 .pop()
44 .unwrap()
45 .unwrap_set_email()
46 .unwrap()
47 .take_destroyed_ids();
48
49 // Fetch mailboxes matching a filter
50 let mut request = client.build();
51 let query_result = request
52 .query_mailbox()
53 .filter(query::Filter::and([
54 mailbox::query::Filter::has_any_role(false),
55 mailbox::query::Filter::is_subscribed(true),
56 ]))
57 .result_reference();
58 request.get_mailbox().ids_ref(query_result).properties([
59 mailbox::Property::Id,
60 mailbox::Property::Name,
61 mailbox::Property::ParentId,
62 mailbox::Property::TotalEmails,
63 mailbox::Property::UnreadEmails,
64 ]);
65 let _mailboxes = request
66 .send()
67 .await
68 .unwrap()
69 .unwrap_method_responses()
70 .pop()
71 .unwrap()
72 .unwrap_get_mailbox()
73 .unwrap()
74 .take_list();
75
76 // Fetch only the updated properties of all mailboxes that changed
77 // since a state.
78 let mut request = client.build();
79 let changes_request = request.changes_mailbox("n").max_changes(0);
80 let properties_ref = changes_request.updated_properties_reference();
81 let updated_ref = changes_request.updated_reference();
82 request
83 .get_mailbox()
84 .ids_ref(updated_ref)
85 .properties_ref(properties_ref);
86 for mailbox in request
87 .send()
88 .await
89 .unwrap()
90 .unwrap_method_responses()
91 .pop()
92 .unwrap()
93 .unwrap_get_mailbox()
94 .unwrap()
95 .take_list()
96 {
97 println!("Changed mailbox: {:#?}", mailbox);
98 }
99}
pub fn download_url(&self) -> &[URLPart<URLParameter>]
pub fn upload_url(&self) -> &[URLPart<URLParameter>]
pub fn event_source_url(&self) -> &[URLPart<URLParameter>]
pub async fn handle_error(response: Response) -> Result<Response>
Source§impl Client
impl Client
Sourcepub async fn email_import<T, U, V, W>(
&self,
raw_message: Vec<u8>,
mailbox_ids: T,
keywords: Option<V>,
received_at: Option<i64>,
) -> Result<Email>
pub async fn email_import<T, U, V, W>( &self, raw_message: Vec<u8>, mailbox_ids: T, keywords: Option<V>, received_at: Option<i64>, ) -> Result<Email>
Examples found in repository?
examples/messages.rs (line 65)
33async fn messages() {
34 // Connect to the JMAP server using Basic authentication
35 let client = Client::new()
36 .credentials(("john@example.org", "secret"))
37 .connect("https://jmap.example.org")
38 .await
39 .unwrap();
40
41 // Query mailboxes to obtain Inbox and Trash folder id
42 let inbox_id = client
43 .mailbox_query(
44 mailbox::query::Filter::role(Role::Inbox).into(),
45 None::<Vec<_>>,
46 )
47 .await
48 .unwrap()
49 .take_ids()
50 .pop()
51 .unwrap();
52 let trash_id = client
53 .mailbox_query(
54 mailbox::query::Filter::role(Role::Trash).into(),
55 None::<Vec<_>>,
56 )
57 .await
58 .unwrap()
59 .take_ids()
60 .pop()
61 .unwrap();
62
63 // Import message into inbox
64 client
65 .email_import(TEST_MESSAGE.to_vec(), [&inbox_id], ["$draft"].into(), None)
66 .await
67 .unwrap();
68
69 // Query mailbox
70 let email_id = client
71 .email_query(
72 Filter::and([
73 email::query::Filter::subject("test"),
74 email::query::Filter::in_mailbox(&inbox_id),
75 email::query::Filter::has_keyword("$draft"),
76 ])
77 .into(),
78 [email::query::Comparator::from()].into(),
79 )
80 .await
81 .unwrap()
82 .take_ids()
83 .pop()
84 .unwrap();
85
86 // Fetch message
87 let email = client
88 .email_get(
89 &email_id,
90 [Property::Subject, Property::Preview, Property::Keywords].into(),
91 )
92 .await
93 .unwrap()
94 .unwrap();
95 assert_eq!(email.preview().unwrap(), "This is a test.");
96 assert_eq!(email.subject().unwrap(), "Testing JMAP client");
97 assert_eq!(email.keywords(), ["$draft"]);
98
99 // Remove the $draft keyword
100 client
101 .email_set_keyword(&email_id, "$draft", false)
102 .await
103 .unwrap();
104
105 // Replace all keywords
106 client
107 .email_set_keywords(&email_id, ["$seen", "$important"])
108 .await
109 .unwrap();
110
111 // Move the message to the Trash folder
112 client
113 .email_set_mailboxes(&email_id, [&trash_id])
114 .await
115 .unwrap();
116
117 // Destroy the e-mail
118 client.email_destroy(&email_id).await.unwrap();
119}
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>, ) -> Result<Email>
pub async fn email_set_mailbox( &self, id: &str, mailbox_id: &str, set: bool, ) -> Result<Option<Email>>
Sourcepub async fn email_set_mailboxes<T, U>(
&self,
id: &str,
mailbox_ids: T,
) -> Result<Option<Email>>
pub async fn email_set_mailboxes<T, U>( &self, id: &str, mailbox_ids: T, ) -> Result<Option<Email>>
Examples found in repository?
examples/messages.rs (line 113)
33async fn messages() {
34 // Connect to the JMAP server using Basic authentication
35 let client = Client::new()
36 .credentials(("john@example.org", "secret"))
37 .connect("https://jmap.example.org")
38 .await
39 .unwrap();
40
41 // Query mailboxes to obtain Inbox and Trash folder id
42 let inbox_id = client
43 .mailbox_query(
44 mailbox::query::Filter::role(Role::Inbox).into(),
45 None::<Vec<_>>,
46 )
47 .await
48 .unwrap()
49 .take_ids()
50 .pop()
51 .unwrap();
52 let trash_id = client
53 .mailbox_query(
54 mailbox::query::Filter::role(Role::Trash).into(),
55 None::<Vec<_>>,
56 )
57 .await
58 .unwrap()
59 .take_ids()
60 .pop()
61 .unwrap();
62
63 // Import message into inbox
64 client
65 .email_import(TEST_MESSAGE.to_vec(), [&inbox_id], ["$draft"].into(), None)
66 .await
67 .unwrap();
68
69 // Query mailbox
70 let email_id = client
71 .email_query(
72 Filter::and([
73 email::query::Filter::subject("test"),
74 email::query::Filter::in_mailbox(&inbox_id),
75 email::query::Filter::has_keyword("$draft"),
76 ])
77 .into(),
78 [email::query::Comparator::from()].into(),
79 )
80 .await
81 .unwrap()
82 .take_ids()
83 .pop()
84 .unwrap();
85
86 // Fetch message
87 let email = client
88 .email_get(
89 &email_id,
90 [Property::Subject, Property::Preview, Property::Keywords].into(),
91 )
92 .await
93 .unwrap()
94 .unwrap();
95 assert_eq!(email.preview().unwrap(), "This is a test.");
96 assert_eq!(email.subject().unwrap(), "Testing JMAP client");
97 assert_eq!(email.keywords(), ["$draft"]);
98
99 // Remove the $draft keyword
100 client
101 .email_set_keyword(&email_id, "$draft", false)
102 .await
103 .unwrap();
104
105 // Replace all keywords
106 client
107 .email_set_keywords(&email_id, ["$seen", "$important"])
108 .await
109 .unwrap();
110
111 // Move the message to the Trash folder
112 client
113 .email_set_mailboxes(&email_id, [&trash_id])
114 .await
115 .unwrap();
116
117 // Destroy the e-mail
118 client.email_destroy(&email_id).await.unwrap();
119}
Sourcepub async fn email_set_keyword(
&self,
id: &str,
keyword: &str,
set: bool,
) -> Result<Option<Email>>
pub async fn email_set_keyword( &self, id: &str, keyword: &str, set: bool, ) -> Result<Option<Email>>
Examples found in repository?
examples/messages.rs (line 101)
33async fn messages() {
34 // Connect to the JMAP server using Basic authentication
35 let client = Client::new()
36 .credentials(("john@example.org", "secret"))
37 .connect("https://jmap.example.org")
38 .await
39 .unwrap();
40
41 // Query mailboxes to obtain Inbox and Trash folder id
42 let inbox_id = client
43 .mailbox_query(
44 mailbox::query::Filter::role(Role::Inbox).into(),
45 None::<Vec<_>>,
46 )
47 .await
48 .unwrap()
49 .take_ids()
50 .pop()
51 .unwrap();
52 let trash_id = client
53 .mailbox_query(
54 mailbox::query::Filter::role(Role::Trash).into(),
55 None::<Vec<_>>,
56 )
57 .await
58 .unwrap()
59 .take_ids()
60 .pop()
61 .unwrap();
62
63 // Import message into inbox
64 client
65 .email_import(TEST_MESSAGE.to_vec(), [&inbox_id], ["$draft"].into(), None)
66 .await
67 .unwrap();
68
69 // Query mailbox
70 let email_id = client
71 .email_query(
72 Filter::and([
73 email::query::Filter::subject("test"),
74 email::query::Filter::in_mailbox(&inbox_id),
75 email::query::Filter::has_keyword("$draft"),
76 ])
77 .into(),
78 [email::query::Comparator::from()].into(),
79 )
80 .await
81 .unwrap()
82 .take_ids()
83 .pop()
84 .unwrap();
85
86 // Fetch message
87 let email = client
88 .email_get(
89 &email_id,
90 [Property::Subject, Property::Preview, Property::Keywords].into(),
91 )
92 .await
93 .unwrap()
94 .unwrap();
95 assert_eq!(email.preview().unwrap(), "This is a test.");
96 assert_eq!(email.subject().unwrap(), "Testing JMAP client");
97 assert_eq!(email.keywords(), ["$draft"]);
98
99 // Remove the $draft keyword
100 client
101 .email_set_keyword(&email_id, "$draft", false)
102 .await
103 .unwrap();
104
105 // Replace all keywords
106 client
107 .email_set_keywords(&email_id, ["$seen", "$important"])
108 .await
109 .unwrap();
110
111 // Move the message to the Trash folder
112 client
113 .email_set_mailboxes(&email_id, [&trash_id])
114 .await
115 .unwrap();
116
117 // Destroy the e-mail
118 client.email_destroy(&email_id).await.unwrap();
119}
Sourcepub async fn email_set_keywords<T, U>(
&self,
id: &str,
keywords: T,
) -> Result<Option<Email>>
pub async fn email_set_keywords<T, U>( &self, id: &str, keywords: T, ) -> Result<Option<Email>>
Examples found in repository?
examples/messages.rs (line 107)
33async fn messages() {
34 // Connect to the JMAP server using Basic authentication
35 let client = Client::new()
36 .credentials(("john@example.org", "secret"))
37 .connect("https://jmap.example.org")
38 .await
39 .unwrap();
40
41 // Query mailboxes to obtain Inbox and Trash folder id
42 let inbox_id = client
43 .mailbox_query(
44 mailbox::query::Filter::role(Role::Inbox).into(),
45 None::<Vec<_>>,
46 )
47 .await
48 .unwrap()
49 .take_ids()
50 .pop()
51 .unwrap();
52 let trash_id = client
53 .mailbox_query(
54 mailbox::query::Filter::role(Role::Trash).into(),
55 None::<Vec<_>>,
56 )
57 .await
58 .unwrap()
59 .take_ids()
60 .pop()
61 .unwrap();
62
63 // Import message into inbox
64 client
65 .email_import(TEST_MESSAGE.to_vec(), [&inbox_id], ["$draft"].into(), None)
66 .await
67 .unwrap();
68
69 // Query mailbox
70 let email_id = client
71 .email_query(
72 Filter::and([
73 email::query::Filter::subject("test"),
74 email::query::Filter::in_mailbox(&inbox_id),
75 email::query::Filter::has_keyword("$draft"),
76 ])
77 .into(),
78 [email::query::Comparator::from()].into(),
79 )
80 .await
81 .unwrap()
82 .take_ids()
83 .pop()
84 .unwrap();
85
86 // Fetch message
87 let email = client
88 .email_get(
89 &email_id,
90 [Property::Subject, Property::Preview, Property::Keywords].into(),
91 )
92 .await
93 .unwrap()
94 .unwrap();
95 assert_eq!(email.preview().unwrap(), "This is a test.");
96 assert_eq!(email.subject().unwrap(), "Testing JMAP client");
97 assert_eq!(email.keywords(), ["$draft"]);
98
99 // Remove the $draft keyword
100 client
101 .email_set_keyword(&email_id, "$draft", false)
102 .await
103 .unwrap();
104
105 // Replace all keywords
106 client
107 .email_set_keywords(&email_id, ["$seen", "$important"])
108 .await
109 .unwrap();
110
111 // Move the message to the Trash folder
112 client
113 .email_set_mailboxes(&email_id, [&trash_id])
114 .await
115 .unwrap();
116
117 // Destroy the e-mail
118 client.email_destroy(&email_id).await.unwrap();
119}
Sourcepub async fn email_destroy(&self, id: &str) -> Result<()>
pub async fn email_destroy(&self, id: &str) -> Result<()>
Examples found in repository?
examples/messages.rs (line 118)
33async fn messages() {
34 // Connect to the JMAP server using Basic authentication
35 let client = Client::new()
36 .credentials(("john@example.org", "secret"))
37 .connect("https://jmap.example.org")
38 .await
39 .unwrap();
40
41 // Query mailboxes to obtain Inbox and Trash folder id
42 let inbox_id = client
43 .mailbox_query(
44 mailbox::query::Filter::role(Role::Inbox).into(),
45 None::<Vec<_>>,
46 )
47 .await
48 .unwrap()
49 .take_ids()
50 .pop()
51 .unwrap();
52 let trash_id = client
53 .mailbox_query(
54 mailbox::query::Filter::role(Role::Trash).into(),
55 None::<Vec<_>>,
56 )
57 .await
58 .unwrap()
59 .take_ids()
60 .pop()
61 .unwrap();
62
63 // Import message into inbox
64 client
65 .email_import(TEST_MESSAGE.to_vec(), [&inbox_id], ["$draft"].into(), None)
66 .await
67 .unwrap();
68
69 // Query mailbox
70 let email_id = client
71 .email_query(
72 Filter::and([
73 email::query::Filter::subject("test"),
74 email::query::Filter::in_mailbox(&inbox_id),
75 email::query::Filter::has_keyword("$draft"),
76 ])
77 .into(),
78 [email::query::Comparator::from()].into(),
79 )
80 .await
81 .unwrap()
82 .take_ids()
83 .pop()
84 .unwrap();
85
86 // Fetch message
87 let email = client
88 .email_get(
89 &email_id,
90 [Property::Subject, Property::Preview, Property::Keywords].into(),
91 )
92 .await
93 .unwrap()
94 .unwrap();
95 assert_eq!(email.preview().unwrap(), "This is a test.");
96 assert_eq!(email.subject().unwrap(), "Testing JMAP client");
97 assert_eq!(email.keywords(), ["$draft"]);
98
99 // Remove the $draft keyword
100 client
101 .email_set_keyword(&email_id, "$draft", false)
102 .await
103 .unwrap();
104
105 // Replace all keywords
106 client
107 .email_set_keywords(&email_id, ["$seen", "$important"])
108 .await
109 .unwrap();
110
111 // Move the message to the Trash folder
112 client
113 .email_set_mailboxes(&email_id, [&trash_id])
114 .await
115 .unwrap();
116
117 // Destroy the e-mail
118 client.email_destroy(&email_id).await.unwrap();
119}
Sourcepub async fn email_get(
&self,
id: &str,
properties: Option<impl IntoIterator<Item = Property>>,
) -> Result<Option<Email<Get>>>
pub async fn email_get( &self, id: &str, properties: Option<impl IntoIterator<Item = Property>>, ) -> Result<Option<Email<Get>>>
Examples found in repository?
examples/messages.rs (lines 88-91)
33async fn messages() {
34 // Connect to the JMAP server using Basic authentication
35 let client = Client::new()
36 .credentials(("john@example.org", "secret"))
37 .connect("https://jmap.example.org")
38 .await
39 .unwrap();
40
41 // Query mailboxes to obtain Inbox and Trash folder id
42 let inbox_id = client
43 .mailbox_query(
44 mailbox::query::Filter::role(Role::Inbox).into(),
45 None::<Vec<_>>,
46 )
47 .await
48 .unwrap()
49 .take_ids()
50 .pop()
51 .unwrap();
52 let trash_id = client
53 .mailbox_query(
54 mailbox::query::Filter::role(Role::Trash).into(),
55 None::<Vec<_>>,
56 )
57 .await
58 .unwrap()
59 .take_ids()
60 .pop()
61 .unwrap();
62
63 // Import message into inbox
64 client
65 .email_import(TEST_MESSAGE.to_vec(), [&inbox_id], ["$draft"].into(), None)
66 .await
67 .unwrap();
68
69 // Query mailbox
70 let email_id = client
71 .email_query(
72 Filter::and([
73 email::query::Filter::subject("test"),
74 email::query::Filter::in_mailbox(&inbox_id),
75 email::query::Filter::has_keyword("$draft"),
76 ])
77 .into(),
78 [email::query::Comparator::from()].into(),
79 )
80 .await
81 .unwrap()
82 .take_ids()
83 .pop()
84 .unwrap();
85
86 // Fetch message
87 let email = client
88 .email_get(
89 &email_id,
90 [Property::Subject, Property::Preview, Property::Keywords].into(),
91 )
92 .await
93 .unwrap()
94 .unwrap();
95 assert_eq!(email.preview().unwrap(), "This is a test.");
96 assert_eq!(email.subject().unwrap(), "Testing JMAP client");
97 assert_eq!(email.keywords(), ["$draft"]);
98
99 // Remove the $draft keyword
100 client
101 .email_set_keyword(&email_id, "$draft", false)
102 .await
103 .unwrap();
104
105 // Replace all keywords
106 client
107 .email_set_keywords(&email_id, ["$seen", "$important"])
108 .await
109 .unwrap();
110
111 // Move the message to the Trash folder
112 client
113 .email_set_mailboxes(&email_id, [&trash_id])
114 .await
115 .unwrap();
116
117 // Destroy the e-mail
118 client.email_destroy(&email_id).await.unwrap();
119}
pub async fn email_changes( &self, since_state: impl Into<String>, max_changes: Option<usize>, ) -> Result<ChangesResponse<Email<Get>>>
Sourcepub async fn email_query(
&self,
filter: Option<impl Into<Filter<Filter>>>,
sort: Option<impl IntoIterator<Item = Comparator<Comparator>>>,
) -> Result<QueryResponse>
pub async fn email_query( &self, filter: Option<impl Into<Filter<Filter>>>, sort: Option<impl IntoIterator<Item = Comparator<Comparator>>>, ) -> Result<QueryResponse>
Examples found in repository?
examples/messages.rs (lines 71-79)
33async fn messages() {
34 // Connect to the JMAP server using Basic authentication
35 let client = Client::new()
36 .credentials(("john@example.org", "secret"))
37 .connect("https://jmap.example.org")
38 .await
39 .unwrap();
40
41 // Query mailboxes to obtain Inbox and Trash folder id
42 let inbox_id = client
43 .mailbox_query(
44 mailbox::query::Filter::role(Role::Inbox).into(),
45 None::<Vec<_>>,
46 )
47 .await
48 .unwrap()
49 .take_ids()
50 .pop()
51 .unwrap();
52 let trash_id = client
53 .mailbox_query(
54 mailbox::query::Filter::role(Role::Trash).into(),
55 None::<Vec<_>>,
56 )
57 .await
58 .unwrap()
59 .take_ids()
60 .pop()
61 .unwrap();
62
63 // Import message into inbox
64 client
65 .email_import(TEST_MESSAGE.to_vec(), [&inbox_id], ["$draft"].into(), None)
66 .await
67 .unwrap();
68
69 // Query mailbox
70 let email_id = client
71 .email_query(
72 Filter::and([
73 email::query::Filter::subject("test"),
74 email::query::Filter::in_mailbox(&inbox_id),
75 email::query::Filter::has_keyword("$draft"),
76 ])
77 .into(),
78 [email::query::Comparator::from()].into(),
79 )
80 .await
81 .unwrap()
82 .take_ids()
83 .pop()
84 .unwrap();
85
86 // Fetch message
87 let email = client
88 .email_get(
89 &email_id,
90 [Property::Subject, Property::Preview, Property::Keywords].into(),
91 )
92 .await
93 .unwrap()
94 .unwrap();
95 assert_eq!(email.preview().unwrap(), "This is a test.");
96 assert_eq!(email.subject().unwrap(), "Testing JMAP client");
97 assert_eq!(email.keywords(), ["$draft"]);
98
99 // Remove the $draft keyword
100 client
101 .email_set_keyword(&email_id, "$draft", false)
102 .await
103 .unwrap();
104
105 // Replace all keywords
106 client
107 .email_set_keywords(&email_id, ["$seen", "$important"])
108 .await
109 .unwrap();
110
111 // Move the message to the Trash folder
112 client
113 .email_set_mailboxes(&email_id, [&trash_id])
114 .await
115 .unwrap();
116
117 // Destroy the e-mail
118 client.email_destroy(&email_id).await.unwrap();
119}
pub async fn email_query_changes( &self, since_query_state: impl Into<String>, filter: Option<impl Into<Filter<Filter>>>, ) -> Result<QueryChangesResponse>
pub async fn email_parse( &self, blob_id: &str, properties: Option<impl IntoIterator<Item = Property>>, body_properties: Option<impl IntoIterator<Item = BodyProperty>>, max_body_value_bytes: Option<usize>, ) -> Result<Email>
pub async fn email_copy<T, U, V, W>( &self, from_account_id: impl Into<String>, id: impl Into<String>, mailbox_ids: T, keywords: Option<V>, received_at: Option<i64>, ) -> Result<Email>
pub async fn search_snippet_get( &self, filter: Option<impl Into<Filter<Filter>>>, email_ids: impl IntoIterator<Item = impl Into<String>>, ) -> Result<SearchSnippetGetResponse>
Source§impl Client
impl Client
pub async fn email_submission_create( &self, email_id: impl Into<String>, identity_id: impl Into<String>, ) -> Result<EmailSubmission<Get>>
pub async fn email_submission_create_envelope<S, T, U>( &self, email_id: impl Into<String>, identity_id: impl Into<String>, mail_from: S, rcpt_to: T, ) -> Result<EmailSubmission<Get>>
pub async fn email_submission_change_status( &self, id: &str, undo_status: UndoStatus, ) -> Result<Option<EmailSubmission>>
pub async fn email_submission_destroy(&self, id: &str) -> Result<()>
pub async fn email_submission_get( &self, id: &str, properties: Option<Vec<Property>>, ) -> Result<Option<EmailSubmission>>
pub async fn email_submission_query( &self, filter: Option<impl Into<Filter<Filter>>>, sort: Option<impl IntoIterator<Item = Comparator<Comparator>>>, ) -> Result<QueryResponse>
pub async fn email_submission_changes( &self, since_state: impl Into<String>, max_changes: usize, ) -> Result<ChangesResponse<EmailSubmission<Get>>>
Source§impl Client
impl Client
Sourcepub async fn event_source(
&self,
types: Option<impl IntoIterator<Item = TypeState>>,
close_after_state: bool,
ping: Option<u32>,
last_event_id: Option<&str>,
) -> Result<impl Stream<Item = Result<Changes>> + Unpin>
pub async fn event_source( &self, types: Option<impl IntoIterator<Item = TypeState>>, close_after_state: bool, ping: Option<u32>, last_event_id: Option<&str>, ) -> Result<impl Stream<Item = Result<Changes>> + Unpin>
Examples found in repository?
examples/eventsource.rs (lines 32-44)
22async fn event_source() {
23 // Connect to the JMAP server using Basic authentication
24 let client = Client::new()
25 .credentials(("john@example.org", "secret"))
26 .connect("https://jmap.example.org")
27 .await
28 .unwrap();
29
30 // Open EventSource connection
31 let mut stream = client
32 .event_source(
33 [
34 TypeState::Email,
35 TypeState::EmailDelivery,
36 TypeState::Mailbox,
37 TypeState::EmailSubmission,
38 TypeState::Identity,
39 ]
40 .into(),
41 false,
42 60.into(),
43 None,
44 )
45 .await
46 .unwrap();
47
48 // Consume events
49 while let Some(event) = stream.next().await {
50 let changes = event.unwrap();
51 println!("-> Change id: {:?}", changes.id());
52 for account_id in changes.changed_accounts() {
53 println!(" Account {} has changes:", account_id);
54 if let Some(account_changes) = changes.changes(account_id) {
55 for (type_state, state_id) in account_changes {
56 println!(" Type {:?} has a new state {}.", type_state, state_id);
57 }
58 }
59 }
60 }
61}
Source§impl Client
impl Client
pub async fn identity_create( &self, name: impl Into<String>, email: impl Into<String>, ) -> Result<Identity>
pub async fn identity_destroy(&self, id: &str) -> Result<()>
pub async fn identity_get( &self, id: &str, properties: Option<Vec<Property>>, ) -> Result<Option<Identity>>
pub async fn identity_changes( &self, since_state: impl Into<String>, max_changes: usize, ) -> Result<ChangesResponse<Identity<Get>>>
Source§impl Client
impl Client
Sourcepub async fn mailbox_create(
&self,
name: impl Into<String>,
parent_id: Option<impl Into<String>>,
role: Role,
) -> Result<Mailbox>
pub async fn mailbox_create( &self, name: impl Into<String>, parent_id: Option<impl Into<String>>, role: Role, ) -> Result<Mailbox>
Examples found in repository?
examples/mailboxes.rs (line 33)
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}
Sourcepub async fn mailbox_rename(
&self,
id: &str,
name: impl Into<String>,
) -> Result<Option<Mailbox>>
pub async fn mailbox_rename( &self, id: &str, name: impl Into<String>, ) -> Result<Option<Mailbox>>
Examples found in repository?
examples/mailboxes.rs (line 40)
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}
Sourcepub async fn mailbox_move(
&self,
id: &str,
parent_id: Option<impl Into<String>>,
) -> Result<Option<Mailbox>>
pub async fn mailbox_move( &self, id: &str, parent_id: Option<impl Into<String>>, ) -> Result<Option<Mailbox>>
Examples found in repository?
examples/mailboxes.rs (line 61)
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}
pub async fn mailbox_update_role( &self, id: &str, role: Role, ) -> Result<Option<Mailbox>>
pub async fn mailbox_update_acl( &self, id: &str, account_id: &str, acl: impl IntoIterator<Item = ACL>, ) -> Result<Option<Mailbox>>
Sourcepub async fn mailbox_update_sort_order(
&self,
id: &str,
sort_order: u32,
) -> Result<Option<Mailbox>>
pub async fn mailbox_update_sort_order( &self, id: &str, sort_order: u32, ) -> Result<Option<Mailbox>>
Examples found in repository?
examples/websocket.rs (line 78)
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 async fn mailbox_subscribe( &self, id: &str, is_subscribed: bool, ) -> Result<Option<Mailbox>>
Sourcepub async fn mailbox_destroy(&self, id: &str, delete_emails: bool) -> Result<()>
pub async fn mailbox_destroy(&self, id: &str, delete_emails: bool) -> Result<()>
Examples found in repository?
examples/mailboxes.rs (line 66)
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}
Sourcepub async fn mailbox_get(
&self,
id: &str,
properties: Option<impl IntoIterator<Item = Property>>,
) -> Result<Option<Mailbox>>
pub async fn mailbox_get( &self, id: &str, properties: Option<impl IntoIterator<Item = Property>>, ) -> Result<Option<Mailbox>>
Examples found in repository?
examples/mailboxes.rs (line 56)
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}
Sourcepub async fn mailbox_query(
&self,
filter: Option<impl Into<Filter<Filter>>>,
sort: Option<impl IntoIterator<Item = Comparator<Comparator>>>,
) -> Result<QueryResponse>
pub async fn mailbox_query( &self, filter: Option<impl Into<Filter<Filter>>>, sort: Option<impl IntoIterator<Item = Comparator<Comparator>>>, ) -> Result<QueryResponse>
Examples found in repository?
examples/mailboxes.rs (line 46)
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/messages.rs (lines 43-46)
33async fn messages() {
34 // Connect to the JMAP server using Basic authentication
35 let client = Client::new()
36 .credentials(("john@example.org", "secret"))
37 .connect("https://jmap.example.org")
38 .await
39 .unwrap();
40
41 // Query mailboxes to obtain Inbox and Trash folder id
42 let inbox_id = client
43 .mailbox_query(
44 mailbox::query::Filter::role(Role::Inbox).into(),
45 None::<Vec<_>>,
46 )
47 .await
48 .unwrap()
49 .take_ids()
50 .pop()
51 .unwrap();
52 let trash_id = client
53 .mailbox_query(
54 mailbox::query::Filter::role(Role::Trash).into(),
55 None::<Vec<_>>,
56 )
57 .await
58 .unwrap()
59 .take_ids()
60 .pop()
61 .unwrap();
62
63 // Import message into inbox
64 client
65 .email_import(TEST_MESSAGE.to_vec(), [&inbox_id], ["$draft"].into(), None)
66 .await
67 .unwrap();
68
69 // Query mailbox
70 let email_id = client
71 .email_query(
72 Filter::and([
73 email::query::Filter::subject("test"),
74 email::query::Filter::in_mailbox(&inbox_id),
75 email::query::Filter::has_keyword("$draft"),
76 ])
77 .into(),
78 [email::query::Comparator::from()].into(),
79 )
80 .await
81 .unwrap()
82 .take_ids()
83 .pop()
84 .unwrap();
85
86 // Fetch message
87 let email = client
88 .email_get(
89 &email_id,
90 [Property::Subject, Property::Preview, Property::Keywords].into(),
91 )
92 .await
93 .unwrap()
94 .unwrap();
95 assert_eq!(email.preview().unwrap(), "This is a test.");
96 assert_eq!(email.subject().unwrap(), "Testing JMAP client");
97 assert_eq!(email.keywords(), ["$draft"]);
98
99 // Remove the $draft keyword
100 client
101 .email_set_keyword(&email_id, "$draft", false)
102 .await
103 .unwrap();
104
105 // Replace all keywords
106 client
107 .email_set_keywords(&email_id, ["$seen", "$important"])
108 .await
109 .unwrap();
110
111 // Move the message to the Trash folder
112 client
113 .email_set_mailboxes(&email_id, [&trash_id])
114 .await
115 .unwrap();
116
117 // Destroy the e-mail
118 client.email_destroy(&email_id).await.unwrap();
119}
pub async fn mailbox_changes( &self, since_state: impl Into<String>, max_changes: usize, ) -> Result<ChangesResponse<Mailbox<Get>>>
Source§impl Client
impl Client
pub async fn individual_create( &self, email: impl Into<String>, secret: impl Into<String>, name: impl Into<String>, ) -> Result<Principal>
pub async fn domain_create(&self, name: impl Into<String>) -> Result<Principal>
pub async fn domain_enable_dkim( &self, id: &str, key: impl Into<String>, selector: impl Into<String>, expiration: Option<i64>, ) -> Result<Option<Principal>>
pub async fn list_create( &self, email: impl Into<String>, name: impl Into<String>, members: impl IntoIterator<Item = impl Into<String>>, ) -> Result<Principal>
pub async fn group_create( &self, email: impl Into<String>, name: impl Into<String>, members: impl IntoIterator<Item = impl Into<String>>, ) -> Result<Principal>
pub async fn principal_set_name( &self, id: &str, name: impl Into<String>, ) -> Result<Option<Principal>>
pub async fn principal_set_secret( &self, id: &str, secret: impl Into<String>, ) -> Result<Option<Principal>>
pub async fn principal_set_email( &self, id: &str, email: impl Into<String>, ) -> Result<Option<Principal>>
pub async fn principal_set_timezone( &self, id: &str, timezone: Option<impl Into<String>>, ) -> Result<Option<Principal>>
pub async fn principal_set_members( &self, id: &str, members: Option<impl IntoIterator<Item = impl Into<String>>>, ) -> Result<Option<Principal>>
pub async fn principal_set_aliases( &self, id: &str, aliases: Option<impl IntoIterator<Item = impl Into<String>>>, ) -> Result<Option<Principal>>
pub async fn principal_set_capabilities( &self, id: &str, capabilities: Option<impl IntoIterator<Item = impl Into<String>>>, ) -> Result<Option<Principal>>
pub async fn principal_destroy(&self, id: &str) -> Result<()>
pub async fn principal_get( &self, id: &str, properties: Option<impl IntoIterator<Item = Property>>, ) -> Result<Option<Principal>>
pub async fn principal_query( &self, filter: Option<impl Into<Filter<Filter>>>, sort: Option<impl IntoIterator<Item = Comparator<Comparator>>>, ) -> Result<QueryResponse>
pub async fn principal_changes( &self, since_state: impl Into<String>, max_changes: usize, ) -> Result<ChangesResponse<Principal<Get>>>
Source§impl Client
impl Client
pub async fn push_subscription_create( &self, device_client_id: impl Into<String>, url: impl Into<String>, keys: Option<Keys>, ) -> Result<PushSubscription>
pub async fn push_subscription_verify( &self, id: &str, verification_code: impl Into<String>, ) -> Result<Option<PushSubscription>>
pub async fn push_subscription_update_types( &self, id: &str, types: Option<impl IntoIterator<Item = TypeState>>, ) -> Result<Option<PushSubscription>>
pub async fn push_subscription_destroy(&self, id: &str) -> Result<()>
Source§impl Client
impl Client
pub async fn sieve_script_create( &self, name: impl Into<String>, script: impl Into<Vec<u8>>, activate: bool, ) -> Result<SieveScript>
pub async fn sieve_script_replace( &self, id: &str, script: impl Into<Vec<u8>>, activate: bool, ) -> Result<Option<SieveScript>>
pub async fn sieve_script_rename( &self, id: &str, name: impl Into<String>, activate: bool, ) -> Result<Option<SieveScript>>
pub async fn sieve_script_activate(&self, id: &str) -> Result<()>
pub async fn sieve_script_deactivate(&self) -> Result<()>
pub async fn sieve_script_destroy(&self, id: &str) -> Result<()>
pub async fn sieve_script_get( &self, id: &str, properties: Option<impl IntoIterator<Item = Property>>, ) -> Result<Option<SieveScript>>
pub async fn sieve_script_query( &self, filter: Option<impl Into<Filter<Filter>>>, sort: Option<impl IntoIterator<Item = Comparator<Comparator>>>, ) -> Result<QueryResponse>
pub async fn sieve_script_validate( &self, script: impl Into<Vec<u8>>, ) -> Result<()>
Source§impl Client
impl Client
pub async fn vacation_response_create( &self, subject: impl Into<String>, text_body: Option<impl Into<String>>, html_body: Option<impl Into<String>>, ) -> Result<VacationResponse>
pub async fn vacation_response_enable( &self, subject: impl Into<String>, text_body: Option<impl Into<String>>, html_body: Option<impl Into<String>>, ) -> Result<Option<VacationResponse>>
pub async fn vacation_response_disable( &self, ) -> Result<Option<VacationResponse>>
pub async fn vacation_response_set_dates( &self, from_date: Option<i64>, to_date: Option<i64>, ) -> Result<Option<VacationResponse>>
pub async fn vacation_response_get( &self, properties: Option<impl IntoIterator<Item = Property>>, ) -> Result<Option<VacationResponse>>
pub async fn vacation_response_destroy(&self) -> Result<()>
Source§impl Client
impl Client
Sourcepub async fn connect_ws(
&self,
) -> Result<Pin<Box<impl Stream<Item = Result<WebSocketMessage>>>>>
pub async fn connect_ws( &self, ) -> Result<Pin<Box<impl Stream<Item = Result<WebSocketMessage>>>>>
Examples found in repository?
examples/websocket.rs (line 34)
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 async fn send_ws(&self, request: Request<'_>) -> Result<String>
Sourcepub async fn enable_push_ws(
&self,
data_types: Option<impl IntoIterator<Item = StateChangeType>>,
push_state: Option<impl Into<String>>,
) -> Result<()>
pub async fn enable_push_ws( &self, data_types: Option<impl IntoIterator<Item = StateChangeType>>, push_state: Option<impl Into<String>>, ) -> Result<()>
Examples found in repository?
examples/websocket.rs (line 72)
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 async fn disable_push_ws(&self) -> Result<()>
pub async fn ws_ping(&self) -> Result<()>
Auto Trait Implementations§
impl !Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
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