Skip to main content

Crate rusmes_jmap

Crate rusmes_jmap 

Source
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

ModuleContents
apiAxum-based HTTP server (JmapServer), request dispatch, auth middleware
blobBlob upload (POST /upload/:account) and download (GET /download/…) endpoints
eventsourceServer-Sent Events push channel (GET /eventsource) for state-change notifications
sessionJMAP Session resource (GET /.well-known/jmap), capability advertisement
typesShared JSON types: Email, JmapRequest, JmapResponse, JmapError, etc.
methodsMethod handlers for all JMAP objects (see sub-modules below)

§Method Handlers

Sub-moduleRFCMethods
methods::mailboxRFC 8621 §2Mailbox/get, Mailbox/set, Mailbox/query, Mailbox/changes, Mailbox/queryChanges
methods::emailRFC 8621 §4Email/get, Email/set, Email/query
methods::email_advancedRFC 8621 §4Email/changes, Email/queryChanges, Email/copy, Email/import, Email/parse
methods::threadRFC 8621 §3Thread/get, Thread/changes
methods::submissionRFC 8621 §7EmailSubmission/get, EmailSubmission/set, EmailSubmission/query, EmailSubmission/changes
methods::identityRFC 8621 §5Identity/get, Identity/set, Identity/changes
methods::vacationRFC 8621 §8VacationResponse/get, VacationResponse/set
methods::search_snippetRFC 8621 §9SearchSnippet/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.json sidecars 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 auth::SharedAuth;
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.