pub mod backends;
pub mod backup;
pub mod metrics;
pub mod modseq;
mod traits;
mod types;
pub use backup::{backup, restore};
pub use metrics::{Histogram, MetricsSummary, StorageMetrics, StorageTimer};
pub use modseq::{MailboxModSeq, MessageModSeq, ModSeq, ModSeqGenerator};
pub use traits::{MailboxStore, MessageStore, MetadataStore, StorageBackend};
pub use types::{
Mailbox, MailboxCounters, MailboxId, MailboxPath, MessageFlags, MessageMetadata, Quota,
SearchCriteria, SpecialUseAttributes,
};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use std::time::Duration;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum StorageEvent {
MessageStored {
account: String,
mailbox: String,
uid: u32,
},
MessageExpunged {
account: String,
mailbox: String,
uid: u32,
},
}
#[derive(Debug, Clone)]
pub enum BackendKind {
Filesystem { path: String },
Sqlite { connection_string: String },
Postgres { connection_string: String },
Amaters {
endpoints: Vec<String>,
replication_factor: usize,
},
}
pub async fn build_storage(kind: &BackendKind) -> anyhow::Result<Arc<dyn StorageBackend>> {
match kind {
BackendKind::Filesystem { path } => {
use backends::filesystem::FilesystemBackend;
let backend = FilesystemBackend::new(path);
Ok(Arc::new(backend))
}
BackendKind::Sqlite { connection_string } => {
use backends::sqlite::SqliteBackend;
let backend = SqliteBackend::new(connection_string).await?;
Ok(Arc::new(backend))
}
BackendKind::Postgres { connection_string } => {
use backends::postgres::PostgresBackend;
let backend = PostgresBackend::new(connection_string).await?;
backend.init_schema().await?;
Ok(Arc::new(backend))
}
BackendKind::Amaters {
endpoints,
replication_factor,
} => {
use backends::amaters::{AmatersBackend, AmatersConfig};
let config = AmatersConfig {
cluster_endpoints: endpoints.clone(),
replication_factor: *replication_factor,
..Default::default()
};
let backend = AmatersBackend::new(config).await?;
Ok(Arc::new(backend))
}
}
}
pub async fn compact_expunged(
backend: &dyn StorageBackend,
older_than: Duration,
) -> anyhow::Result<usize> {
backend.compact_expunged(older_than).await
}