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