···
+
A type-safe OCaml interface to the JMAP protocol ([RFC8620](https://datatracker.ietf.org/doc/html/rfc8620)) and JMAP Mail extension ([RFC8621](https://datatracker.ietf.org/doc/html/rfc8621)).
+
**Note:** This library is largely AI-generated and has not been audited carefully. It's a proof-of-concept implementation of the JMAP specification.
+
JMAP (JSON Meta Application Protocol) is a modern protocol for synchronizing email, calendars, and contacts designed as a replacement for legacy protocols like IMAP. This OCaml implementation provides:
+
- Type-safe OCaml interfaces to the JMAP Core and Mail specifications
+
- Authentication with username/password or API tokens (Fastmail support)
+
- Convenient functions for common email and mailbox operations
+
- Support for composing complex multi-part requests with result references
+
- Typed handling of message flags, keywords, and mailbox attributes
+
Add to your project with opam:
+
Or pin the development version:
+
opam pin add jmap.dev git+https://github.com/example/jmap-ocaml.git
+
let token = Sys.getenv "JMAP_API_TOKEN" in
+
let* result = Jmap_mail.login_with_token
+
~uri:"https://api.fastmail.com/jmap/session"
+
Printf.eprintf "Authentication failed\n";
+
(* Get primary account ID *)
+
let mail_capability = Jmap_mail.Capability.to_string Jmap_mail.Capability.Mail in
+
let account_id = List.assoc mail_capability conn.session.primary_accounts in
+
let* mailboxes_result = Jmap_mail.get_mailboxes conn ~account_id in
+
match mailboxes_result with
+
Printf.eprintf "Failed to get mailboxes\n";
+
let inbox = List.find_opt (fun m ->
+
m.Types.role = Some Types.Inbox
+
Printf.eprintf "No inbox found\n";
+
(* Get recent emails *)
+
let* emails_result = Jmap_mail.get_messages_in_mailbox
+
~mailbox_id:inbox.Types.id
+
match emails_result with
+
Printf.eprintf "Failed to get emails\n";
+
List.iter (fun email ->
+
Printf.printf "%s - %s\n"
+
(Option.value ~default:"<unknown>"
+
(Option.map (fun addrs ->
+
| addr::_ -> addr.Types.email
+
(Option.value ~default:"<no subject>" email.Types.subject)
+
- **Core JMAP Protocol**
+
- API request/response management
+
- Type-safe representation of all JMAP structures
+
- Result references for composing multi-step requests
+
- **JMAP Mail Extension**
+
- Mailbox operations (folders/labels)
+
- Email retrieval and manipulation
+
- Message flags and keywords
+
- **Fastmail Integration**
+
- API token authentication
+
- Example tools for listing messages
+
The library includes comprehensive OCamldoc documentation with cross-references to the relevant sections of the JMAP specifications.
+
Build the documentation with:
+
The package includes several example tools:
+
- `fastmail-list`: Lists emails from a Fastmail account (requires JMAP_API_TOKEN)
+
- `jmap-tutorial-examples`: Demonstrates basic JMAP operations as shown in the tutorial
+
- [RFC8620: The JSON Meta Application Protocol (JMAP)](https://datatracker.ietf.org/doc/html/rfc8620)
+
- [RFC8621: The JSON Meta Application Protocol (JMAP) for Mail](https://datatracker.ietf.org/doc/html/rfc8621)
+
- [Message Flag and Mailbox Attribute Extension](https://datatracker.ietf.org/doc/html/draft-ietf-mailmaint-messageflag-mailboxattribute-02)
+
- [Fastmail Developer Documentation](https://www.fastmail.com/dev/)