Skip to main content

mxr_core/
provider.rs

1use crate::error::MxrError;
2use crate::id::AccountId;
3use crate::types::*;
4use async_trait::async_trait;
5
6pub type Result<T> = std::result::Result<T, MxrError>;
7
8#[async_trait]
9pub trait MailSyncProvider: Send + Sync {
10    fn name(&self) -> &str;
11    fn account_id(&self) -> &AccountId;
12    fn capabilities(&self) -> SyncCapabilities;
13
14    async fn authenticate(&mut self) -> Result<()>;
15    async fn refresh_auth(&mut self) -> Result<()>;
16
17    async fn sync_labels(&self) -> Result<Vec<Label>>;
18    async fn sync_messages(&self, cursor: &SyncCursor) -> Result<SyncBatch>;
19
20    async fn fetch_attachment(
21        &self,
22        provider_message_id: &str,
23        provider_attachment_id: &str,
24    ) -> Result<Vec<u8>>;
25
26    async fn modify_labels(
27        &self,
28        provider_message_id: &str,
29        add: &[String],
30        remove: &[String],
31    ) -> Result<()>;
32
33    async fn create_label(&self, _name: &str, _color: Option<&str>) -> Result<Label> {
34        Err(MxrError::Provider(
35            "Label creation not supported".to_string(),
36        ))
37    }
38
39    async fn rename_label(&self, _provider_label_id: &str, _new_name: &str) -> Result<Label> {
40        Err(MxrError::Provider("Label rename not supported".to_string()))
41    }
42
43    async fn delete_label(&self, _provider_label_id: &str) -> Result<()> {
44        Err(MxrError::Provider(
45            "Label deletion not supported".to_string(),
46        ))
47    }
48
49    async fn trash(&self, provider_message_id: &str) -> Result<()>;
50    async fn set_read(&self, provider_message_id: &str, read: bool) -> Result<()>;
51    async fn set_starred(&self, provider_message_id: &str, starred: bool) -> Result<()>;
52
53    async fn search_remote(&self, _query: &str) -> Result<Vec<String>> {
54        Err(MxrError::Provider(
55            "Server-side search not supported".into(),
56        ))
57    }
58}
59
60#[async_trait]
61pub trait MailSendProvider: Send + Sync {
62    fn name(&self) -> &str;
63    async fn send(&self, draft: &Draft, from: &Address) -> Result<SendReceipt>;
64
65    /// Save a draft to the mail server. Returns the server-side draft ID if supported.
66    /// Default: returns Ok(None) (provider doesn't support server drafts).
67    async fn save_draft(&self, _draft: &Draft, _from: &Address) -> Result<Option<String>> {
68        Ok(None)
69    }
70}