Skip to main content

Crate rusmes_storage

Crate rusmes_storage 

Source
Expand description

Storage abstraction layer for RusMES

This crate provides a unified storage interface for the RusMES mail server, covering mailbox management, message delivery, metadata tracking, and quota enforcement.

§Architecture

The storage layer is composed of three orthogonal trait abstractions:

  • MailboxStore — Create, rename, delete, subscribe, and list mailboxes per user.
  • MessageStore — Append, retrieve, copy, flag, search, and delete messages.
  • MetadataStore — Manage per-user quotas and per-mailbox counters (exists/recent/unseen).

These three stores are obtained from a single StorageBackend factory, which bundles them together and can be shared across protocol handlers (IMAP, JMAP, POP3, SMTP).

§Backends

BackendModuleNotes
Filesystem / Maildirbackends::filesystemAtomic delivery via tmp/new/ rename; flag encoding in filenames
AmateRS distributed KVbackends::amatersMock implementation with circuit-breaker and exponential-backoff retry logic
PostgreSQLbackends::postgresFull connection pool via sqlx, full-text search, migrations

§Example — Filesystem backend

use rusmes_storage::{StorageBackend, MailboxStore, MailboxPath};
use rusmes_storage::backends::filesystem::FilesystemBackend;

let backend = FilesystemBackend::new("/var/mail/rusmes");
let mb_store = backend.mailbox_store();

let user: rusmes_proto::Username = "alice@example.com".parse()?;
let path = MailboxPath::new(user, vec!["INBOX".to_string()]);
let id = mb_store.create_mailbox(&path).await?;

let mailbox = mb_store.get_mailbox(&id).await?;
println!("Created: {:?}", mailbox);

§ModSeq (Modification Sequence Numbers)

ModSeqGenerator produces monotonically increasing sequence numbers suitable for IMAP CONDSTORE / QRESYNC extensions. Both mailbox-level and message-level ModSeq values are tracked via MailboxModSeq and MessageModSeq wrappers.

§Metrics

StorageMetrics records per-operation histograms for timing storage calls from higher-level protocol handlers, enabling Prometheus-compatible export.

Re-exports§

pub use backup::backup;
pub use backup::restore;
pub use metrics::Histogram;
pub use metrics::MetricsSummary;
pub use metrics::StorageMetrics;
pub use metrics::StorageTimer;
pub use modseq::MailboxModSeq;
pub use modseq::MessageModSeq;
pub use modseq::ModSeq;
pub use modseq::ModSeqGenerator;

Modules§

backends
Storage backend implementations
backup
Backup and restore library API for rusmes storage backends.
metrics
Storage metrics collection and tracking
modseq
MODSEQ (Modification Sequence) tracking for IMAP CONDSTORE

Structs§

Mailbox
Mailbox metadata
MailboxCounters
Mailbox counters
MailboxId
Unique identifier for a mailbox
MailboxPath
Mailbox path (hierarchical)
MessageFlags
Message flags (IMAP standard flags)
MessageMetadata
Message metadata in a mailbox
Quota
User quota information
SpecialUseAttributes
Special-use mailbox attributes (RFC 6154)

Enums§

BackendKind
Configuration for which storage backend to build.
SearchCriteria
Search criteria for messages
StorageEvent
Events emitted by storage backends after write operations.

Traits§

MailboxStore
Mailbox storage operations
MessageStore
Message storage operations
MetadataStore
Metadata storage operations
StorageBackend
Combined storage backend

Functions§

build_storage
Construct a storage backend from configuration.
compact_expunged
Perform compaction: remove expunged messages older than older_than.