Skip to main content

ecr_store/
store.rs

1use crate::error::Result;
2use ecr_core::account::{Account, AccountId};
3use ecr_core::doctor::Doctor;
4use ecr_core::message::{
5    Body, BodyFormat, Message, MessageId, Part, PartId, Query, SyncReport, TagOp, Thread, ThreadId,
6    ThreadSummary,
7};
8use ecr_core::revision::Revision;
9use std::future::Future;
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub struct BodyOptions {
13    pub format: BodyFormat,
14    pub allow_remote_resources: bool,
15}
16
17impl Default for BodyOptions {
18    fn default() -> Self {
19        Self {
20            format: BodyFormat::Html,
21            allow_remote_resources: false,
22        }
23    }
24}
25
26pub trait ProgressSink: Send + Sync {
27    fn line(&self, text: &str);
28}
29
30impl ProgressSink for () {
31    fn line(&self, _text: &str) {}
32}
33
34pub trait MailStore: Send + Sync {
35    fn revision(&self) -> impl Future<Output = Result<Revision>> + Send;
36
37    fn accounts(&self) -> impl Future<Output = Result<Vec<Account>>> + Send;
38
39    fn search_threads(
40        &self,
41        query: &Query,
42    ) -> impl Future<Output = Result<Vec<ThreadSummary>>> + Send;
43
44    fn count(&self, query: &Query) -> impl Future<Output = Result<usize>> + Send;
45
46    /// One count per query, in the order asked. The sidebar wants a number for
47    /// every row at once, and one process answers all of them.
48    fn count_batch(&self, queries: &[String]) -> impl Future<Output = Result<Vec<u64>>> + Send;
49
50    fn thread(&self, id: &ThreadId) -> impl Future<Output = Result<Thread>> + Send;
51
52    fn message(&self, id: &MessageId) -> impl Future<Output = Result<Message>> + Send;
53
54    fn body(
55        &self,
56        id: &MessageId,
57        options: BodyOptions,
58    ) -> impl Future<Output = Result<Body>> + Send;
59
60    fn part(&self, id: &MessageId, part: &PartId) -> impl Future<Output = Result<Part>> + Send;
61
62    fn tag(&self, ops: &[TagOp]) -> impl Future<Output = Result<Revision>> + Send;
63
64    fn sync(
65        &self,
66        accounts: &[AccountId],
67        progress: &dyn ProgressSink,
68    ) -> impl Future<Output = Result<SyncReport>> + Send;
69
70    fn send(&self, account: &AccountId, raw: &[u8]) -> impl Future<Output = Result<()>> + Send;
71
72    fn doctor(&self) -> impl Future<Output = Doctor> + Send;
73}