rusmes_jmap/lib.rs
1//! JMAP protocol implementation for RusMES
2//!
3//! This crate implements the JSON Meta Application Protocol (JMAP) for the RusMES mail
4//! server, providing an HTTP/JSON API for email access as defined in:
5//!
6//! - **RFC 8620** — The JSON Meta Application Protocol (core protocol)
7//! - **RFC 8621** — Using JMAP for Email (Email, Mailbox, Thread, EmailSubmission,
8//! VacationResponse, SearchSnippet, Identity)
9//!
10//! # Module Overview
11//!
12//! | Module | Contents |
13//! |--------|----------|
14//! [`api`] | Axum-based HTTP server (`JmapServer`), request dispatch, auth middleware |
15//! [`blob`] | Blob upload (`POST /upload/:account`) and download (`GET /download/…`) endpoints |
16//! [`eventsource`] | Server-Sent Events push channel (`GET /eventsource`) for state-change notifications |
17//! [`session`] | JMAP Session resource (`GET /.well-known/jmap`), capability advertisement |
18//! [`types`] | Shared JSON types: `Email`, `JmapRequest`, `JmapResponse`, `JmapError`, etc. |
19//! [`methods`] | Method handlers for all JMAP objects (see sub-modules below) |
20//!
21//! ## Method Handlers
22//!
23//! | Sub-module | RFC | Methods |
24//! |-----------|-----|---------|
25//! `methods::mailbox` | RFC 8621 §2 | `Mailbox/get`, `Mailbox/set`, `Mailbox/query`, `Mailbox/changes`, `Mailbox/queryChanges` |
26//! `methods::email` | RFC 8621 §4 | `Email/get`, `Email/set`, `Email/query` |
27//! `methods::email_advanced` | RFC 8621 §4 | `Email/changes`, `Email/queryChanges`, `Email/copy`, `Email/import`, `Email/parse` |
28//! `methods::thread` | RFC 8621 §3 | `Thread/get`, `Thread/changes` |
29//! `methods::submission` | RFC 8621 §7 | `EmailSubmission/get`, `EmailSubmission/set`, `EmailSubmission/query`, `EmailSubmission/changes` |
30//! `methods::identity` | RFC 8621 §5 | `Identity/get`, `Identity/set`, `Identity/changes` |
31//! `methods::vacation` | RFC 8621 §8 | `VacationResponse/get`, `VacationResponse/set` |
32//! `methods::search_snippet` | RFC 8621 §9 | `SearchSnippet/get` |
33//!
34//! # Example — Starting the JMAP server
35//!
36//! ```rust,no_run
37//! use rusmes_jmap::JmapServer;
38//! use axum::Router;
39//!
40//! // Obtain the JMAP routes and nest them inside an Axum application.
41//! let app: Router = JmapServer::routes();
42//! // e.g. axum::serve(listener, app).await.unwrap();
43//! ```
44//!
45//! # EventSource Push
46//!
47//! The [`eventsource::EventSourceManager`] can be used to broadcast state-change
48//! notifications to JMAP clients that maintain a long-lived SSE connection:
49//!
50//! ```rust,no_run
51//! use rusmes_jmap::EventSourceManager;
52//!
53//! let manager = EventSourceManager::new();
54//! // Notify all connected clients that the Email state has changed:
55//! manager.notify_change("Email".to_string(), "new-state-token".to_string());
56//! ```
57//!
58//! # Blob Handling
59//!
60//! [`BlobStorage`] provides a content-addressed in-memory blob store keyed by
61//! SHA-256 hash. Uploaded blobs are referenced by `blobId` strings throughout
62//! JMAP Email import/parse operations.
63
64pub mod api;
65pub mod blob;
66pub mod eventsource;
67pub mod methods;
68pub mod session;
69pub mod types;
70
71pub use api::JmapServer;
72pub use blob::{BlobStorage, UploadError, UploadResponse};
73pub use eventsource::{EventSourceManager, PushSubscription, StateChange};
74pub use session::{Account, AccountCapability, Capability, Session};
75pub use types::{
76 Email, EmailAddress, EmailGetRequest, EmailGetResponse, EmailQueryRequest, EmailQueryResponse,
77 EmailSetRequest, EmailSetResponse, JmapError, JmapErrorType, JmapMethod, JmapRequest,
78 JmapResponse,
79};