Expand description
JMAP protocol implementation for RusMES
This crate implements the JSON Meta Application Protocol (JMAP) for the RusMES mail server, providing an HTTP/JSON API for email access as defined in:
- RFC 8620 — The JSON Meta Application Protocol (core protocol)
- RFC 8621 — Using JMAP for Email (Email, Mailbox, Thread, EmailSubmission, VacationResponse, SearchSnippet, Identity)
§Module Overview
| Module | Contents |
|---|---|
api | Axum-based HTTP server (JmapServer), request dispatch, auth middleware |
blob | Blob upload (POST /upload/:account) and download (GET /download/…) endpoints |
eventsource | Server-Sent Events push channel (GET /eventsource) for state-change notifications |
session | JMAP Session resource (GET /.well-known/jmap), capability advertisement |
types | Shared JSON types: Email, JmapRequest, JmapResponse, JmapError, etc. |
methods | Method handlers for all JMAP objects (see sub-modules below) |
§Method Handlers
| Sub-module | RFC | Methods |
|---|---|---|
methods::mailbox | RFC 8621 §2 | Mailbox/get, Mailbox/set, Mailbox/query, Mailbox/changes, Mailbox/queryChanges |
methods::email | RFC 8621 §4 | Email/get, Email/set, Email/query |
methods::email_advanced | RFC 8621 §4 | Email/changes, Email/queryChanges, Email/copy, Email/import, Email/parse |
methods::thread | RFC 8621 §3 | Thread/get, Thread/changes |
methods::submission | RFC 8621 §7 | EmailSubmission/get, EmailSubmission/set, EmailSubmission/query, EmailSubmission/changes |
methods::identity | RFC 8621 §5 | Identity/get, Identity/set, Identity/changes |
methods::vacation | RFC 8621 §8 | VacationResponse/get, VacationResponse/set |
methods::search_snippet | RFC 8621 §9 | SearchSnippet/get |
§Example — Starting the JMAP server
use rusmes_jmap::JmapServer;
use axum::Router;
// Obtain the JMAP routes and nest them inside an Axum application.
let app: Router = JmapServer::routes();
// e.g. axum::serve(listener, app).await.unwrap();§EventSource Push
The eventsource::EventSourceManager can be used to broadcast state-change
notifications to JMAP clients that maintain a long-lived SSE connection:
use rusmes_jmap::EventSourceManager;
let manager = EventSourceManager::new();
// Notify all connected clients that the Email state has changed:
manager.notify_change("Email".to_string(), "new-state-token".to_string());§Blob Handling
BlobStorage supports two persistence backends:
- Memory (default, via
BlobStorage::new): blobs live in-memory and are lost on restart. Existing callers are unaffected. - Filesystem (via
BlobStorage::new_filesystem): blobs are written to<root>/blobs/<id>with a JSON sidecar and survive server restarts. The in-memory index is rebuilt by scanning.meta.jsonsidecars on open.
Both backends enforce a configurable max_blob_size (default 50 MiB) and
return UploadError::TooLarge before writing any bytes when the limit is
exceeded. Uploaded blobs are referenced by blobId strings throughout JMAP
Email import/parse operations.
Re-exports§
pub use api::JmapServer;pub use auth::authenticate;pub use auth::extract_credentials;pub use auth::require_auth;pub use auth::AuthError;pub use auth::Credentials;pub use blob::BlobMeta;pub use blob::BlobStorage;pub use blob::UploadError;pub use blob::UploadErrorBody;pub use blob::UploadResponse;pub use eventsource::EventSourceManager;pub use eventsource::EventSourcePushHint;pub use eventsource::StateChange;pub use session::Account;pub use session::AccountCapability;pub use session::Capability;pub use session::Session;pub use types::derive_account_id;pub use types::Email;pub use types::EmailAddress;pub use types::EmailGetRequest;pub use types::EmailGetResponse;pub use types::EmailQueryRequest;pub use types::EmailQueryResponse;pub use types::EmailSetRequest;pub use types::EmailSetResponse;pub use types::JmapError;pub use types::JmapErrorType;pub use types::JmapMethod;pub use types::JmapRequest;pub use types::JmapResponse;pub use types::Principal;pub use types::PushSubscription;
Modules§
- api
- JMAP API server
- auth
- JMAP authentication middleware.
- back_
reference - RFC 8620 §3.7 back-reference resolution for JMAP method call batches.
- blob
- Blob upload/download endpoints for JMAP
- eventsource
- EventSource (Server-Sent Events) endpoint for JMAP
- methods
- JMAP method handlers
- session
- JMAP Session Object (RFC 8620 Section 2)
- types
- JMAP type definitions
- web_
push - WebPush client for RFC 8030 push + RFC 8444 VAPID.