main
Mauro D 2022-09-09 09:54:09 +00:00
parent 756085ec4d
commit 88eeb32198
1 changed files with 103 additions and 103 deletions

View File

@ -22,23 +22,23 @@ Features:
## Usage Example ## Usage Example
```rust ```rust
// Connect to the JMAP server using Basic authentication. // Connect to the JMAP server using Basic authentication.
// (just for demonstration purposes, Bearer tokens should be used instead) // (just for demonstration purposes, Bearer tokens should be used instead)
let client = Client::new() let client = Client::new()
.credentials(("john@example.org", "secret")) .credentials(("john@example.org", "secret"))
.connect("https://jmap.example.org") .connect("https://jmap.example.org")
.await .await
.unwrap(); .unwrap();
// Create a mailbox. // Create a mailbox.
let mailbox_id = client let mailbox_id = client
.mailbox_create("My Mailbox", None::<String>, Role::None) .mailbox_create("My Mailbox", None::<String>, Role::None)
.await .await
.unwrap() .unwrap()
.take_id(); .take_id();
// Import a message into the mailbox. // Import a message into the mailbox.
client client
.email_import( .email_import(
b"From: john@example.org\nSubject: test\n\n test".to_vec(), b"From: john@example.org\nSubject: test\n\n test".to_vec(),
[&mailbox_id], [&mailbox_id],
@ -48,8 +48,8 @@ Features:
.await .await
.unwrap(); .unwrap();
// Obtain all e-mail ids matching a filter. // Obtain all e-mail ids matching a filter.
let email_id = client let email_id = client
.email_query( .email_query(
Filter::and([ Filter::and([
email::query::Filter::subject("test"), email::query::Filter::subject("test"),
@ -65,8 +65,8 @@ Features:
.pop() .pop()
.unwrap(); .unwrap();
// Fetch an e-mail message. // Fetch an e-mail message.
let email = client let email = client
.email_get( .email_get(
&email_id, &email_id,
[Property::Subject, Property::Preview, Property::Keywords].into(), [Property::Subject, Property::Preview, Property::Keywords].into(),
@ -74,21 +74,21 @@ Features:
.await .await
.unwrap() .unwrap()
.unwrap(); .unwrap();
assert_eq!(email.preview().unwrap(), "test"); assert_eq!(email.preview().unwrap(), "test");
assert_eq!(email.subject().unwrap(), "test"); assert_eq!(email.subject().unwrap(), "test");
assert_eq!(email.keywords(), ["$draft"]); assert_eq!(email.keywords(), ["$draft"]);
// Fetch only the updated properties of all mailboxes that changed // Fetch only the updated properties of all mailboxes that changed
// since a state. // since a state.
let mut request = client.build(); let mut request = client.build();
let changes_request = request.changes_mailbox("n").max_changes(0); let changes_request = request.changes_mailbox("n").max_changes(0);
let properties_ref = changes_request.updated_properties_reference(); let properties_ref = changes_request.updated_properties_reference();
let updated_ref = changes_request.updated_reference(); let updated_ref = changes_request.updated_reference();
request request
.get_mailbox() .get_mailbox()
.ids_ref(updated_ref) .ids_ref(updated_ref)
.properties_ref(properties_ref); .properties_ref(properties_ref);
for mailbox in request for mailbox in request
.send() .send()
.await .await
.unwrap() .unwrap()
@ -98,15 +98,15 @@ Features:
.unwrap_get_mailbox() .unwrap_get_mailbox()
.unwrap() .unwrap()
.take_list() .take_list()
{ {
println!("Changed mailbox: {:#?}", mailbox); println!("Changed mailbox: {:#?}", mailbox);
} }
// Delete the mailbox including any messages // Delete the mailbox including any messages
client.mailbox_destroy(&mailbox_id, true).await.unwrap(); client.mailbox_destroy(&mailbox_id, true).await.unwrap();
// Open an EventSource connection with the JMAP server. // Open an EventSource connection with the JMAP server.
let mut stream = client let mut stream = client
.event_source( .event_source(
[ [
TypeState::Email, TypeState::Email,
@ -123,8 +123,8 @@ Features:
.await .await
.unwrap(); .unwrap();
// Consume events received over EventSource. // Consume events received over EventSource.
while let Some(event) = stream.next().await { while let Some(event) = stream.next().await {
let changes = event.unwrap(); let changes = event.unwrap();
println!("-> Change id: {:?}", changes.id()); println!("-> Change id: {:?}", changes.id());
for account_id in changes.changed_accounts() { for account_id in changes.changed_accounts() {
@ -135,7 +135,7 @@ Features:
} }
} }
} }
} }
``` ```
More examples available under the [examples](examples) directory. More examples available under the [examples](examples) directory.