jmap-client
jmap-client is a JSON Meta Application Protocol (JMAP) library written in Rust. The library is a full implementation of the JMAP RFCs including:
- JMAP Core (RFC 8620)
- JMAP for Mail (RFC 8621)
- JMAP over WebSocket (RFC 8887).
- JMAP for Sieve Scripts (DRAFT-SIEVE-14).
Features:
- Async and blocking support (use the cargo feature
blocking
to enable blocking). - WebSocket async streams (use the cargo feature
websockets
to enable JMAP over WebSocket). - EventSource async streams.
- Helper functions to reduce boilerplate code and quickly build JMAP requests.
- Fast parsing and encoding of JMAP requests.
Usage Example
// Connect to the JMAP server using Basic authentication.
// (just for demonstration purposes, Bearer tokens should be used instead)
let client = new
.credentials
.connect
.await
.unwrap;
// Create a mailbox.
let mailbox_id = client
.mailbox_create
.await
.unwrap
.take_id;
// Import a message into the mailbox.
client
.email_import
.await
.unwrap;
// Obtain all e-mail ids matching a filter.
let email_id = client
.email_query
.await
.unwrap
.take_ids
.pop
.unwrap;
// Fetch an e-mail message.
let email = client
.email_get
.await
.unwrap
.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
// Fetch only the updated properties of all mailboxes that changed
// since a state.
let mut request = client.build;
let changes_request = request.changes_mailbox.max_changes;
let properties_ref = changes_request.updated_properties_reference;
let updated_ref = changes_request.updated_reference;
request
.get_mailbox
.ids_ref
.properties_ref;
for mailbox in request
.send
.await
.unwrap
.unwrap_method_responses
.pop
.unwrap
.unwrap_get_mailbox
.unwrap
.take_list
// Delete the mailbox including any messages
client.mailbox_destroy.await.unwrap;
// Open an EventSource connection with the JMAP server.
let mut stream = client
.event_source
.await
.unwrap;
// Consume events received over EventSource.
while let Some = stream.next.await
More examples available under the examples directory.
Testing
To run the testsuite:
Conformed RFCs
- RFC 8620 - The JSON Meta Application Protocol (JMAP)
- RFC 8621 - The JSON Meta Application Protocol (JMAP) for Mail
- RFC 8887 - A JSON Meta Application Protocol (JMAP) Subprotocol for WebSocket
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Copyright
Copyright (C) 2022, Stalwart Labs Ltd.