email/account/sync/
mod.rs

1//! # Account synchronization
2//!
3//! Module dedicated to synchronization of folders and emails
4//! belonging to an account. The main structure of this module is
5//! [`AccountSyncBuilder`], which allows you to synchronize a given
6//! backend with a local Maildir one, and therefore enables offline
7//! support for this backend.
8
9pub mod config;
10
11#[doc(inline)]
12pub use super::{Error, Result};
13use crate::{
14    backend::{context::BackendContextBuilder, BackendBuilder},
15    maildir::MaildirContextBuilder,
16    sync::{hash::SyncHash, SyncBuilder},
17};
18
19/// The account synchronization builder.
20///
21/// This builder is just a wrapper around [`SyncBuilder`], where the
22/// left backend builder is a pre-defined Maildir one. The aim of this
23/// builder is to provide offline support for any given backend.
24pub struct AccountSyncBuilder;
25
26impl AccountSyncBuilder {
27    /// Try to create a new account synchronization builder.
28    pub fn try_new<R: BackendContextBuilder + SyncHash + 'static>(
29        right_builder: BackendBuilder<R>,
30    ) -> Result<SyncBuilder<MaildirContextBuilder, R>> {
31        let left_ctx_builder = right_builder
32            .ctx_builder
33            .try_to_sync_cache_builder(&right_builder.account_config)?;
34        let left_builder =
35            BackendBuilder::new(right_builder.account_config.clone(), left_ctx_builder);
36        let sync_builder = SyncBuilder::new(left_builder, right_builder);
37
38        Ok(sync_builder)
39    }
40}