JMAP Unix Implementation#
This library provides Unix-specific implementation for the core JMAP protocol.
Overview#
Jmap_unix provides the implementation needed to make actual connections to JMAP servers using OCaml's Unix module. It handles:
- HTTP connections to JMAP endpoints
- Authentication
- Session discovery
- Request/response handling
- Blob upload/download
- High-level email operations (Jmap_unix.Email)
Usage#
open Jmap
open Jmap_unix
(* Create a connection to a JMAP server *)
let connect_example env =
let ctx = Jmap_unix.create_client () in
match Jmap_unix.quick_connect env ~host:"jmap.example.com" ~username:"user" ~password:"pass" () with
| Ok (ctx, session) ->
(* Use the connection for JMAP requests *)
let builder = Jmap_unix.build ctx in
let builder = Jmap_unix.using builder [`Core] in
(* ... add method calls ... *)
let response = Jmap_unix.execute env builder in
ignore (Jmap_unix.close ctx)
| Error err ->
Printf.eprintf "Connection failed: %s\n" (Jmap.Error.to_string err)
Email Operations#
The Email module provides high-level operations for working with emails:
open Jmap
open Jmap_unix
(* Get an email *)
let get_email_example env ctx account_id email_id =
match Email.get_email env ctx ~account_id ~email_id () with
| Ok email -> Printf.printf "Got email: %s\n" (Jmap_email.Email.subject email)
| Error err -> Printf.eprintf "Error: %s\n" (Jmap.Error.to_string err)
(* Search for unread emails *)
let search_unread env ctx account_id =
let filter = Jmap.Methods.Filter.(["hasKeyword", `String "$unseen"]) in
match Email.search_emails env ctx ~account_id ~filter () with
| Ok (ids, Some emails) -> Printf.printf "Found %d unread emails\n" (List.length emails)
| Ok (ids, None) -> Printf.printf "Found %d unread email IDs\n" (List.length ids)
| Error err -> Printf.eprintf "Search error: %s\n" (Jmap.Error.to_string err)
(* Mark emails as read *)
let mark_read env ctx account_id email_ids =
match Email.mark_as_seen env ctx ~account_id ~email_ids () with
| Ok () -> Printf.printf "Marked %d emails as read\n" (List.length email_ids)
| Error err -> Printf.eprintf "Mark error: %s\n" (Jmap.Error.to_string err)
Dependencies#
- jmap (core library)
- jmap-email (email types and helpers)
- eio (structured concurrency)
- tls-eio (TLS support)
- cohttp-eio (HTTP client)
- yojson (JSON handling)
- uri (URL parsing)