From ff98685afb4edff39f20334a498d87fe211f93fb Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sun, 22 Aug 2021 19:34:25 -0500 Subject: [PATCH] sync --- mbsync/src/lib.rs | 2 +- mbsync/src/main.rs | 9 ++++++++- mbsync/src/store.rs | 47 ++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/mbsync/src/lib.rs b/mbsync/src/lib.rs index 92802af..6230463 100644 --- a/mbsync/src/lib.rs +++ b/mbsync/src/lib.rs @@ -8,4 +8,4 @@ extern crate derivative; extern crate derive_builder; pub mod config; -pub mod store; \ No newline at end of file +pub mod store; diff --git a/mbsync/src/main.rs b/mbsync/src/main.rs index 2aa17d6..5abd1fc 100644 --- a/mbsync/src/main.rs +++ b/mbsync/src/main.rs @@ -2,7 +2,10 @@ use std::path::PathBuf; use anyhow::Result; use clap::Clap; -use mbsync::{config, store}; +use mbsync::{ + config::{self, ChannelSyncOps}, + store, +}; #[derive(Debug, Clap)] struct Opt { @@ -30,6 +33,10 @@ async fn main() -> Result<()> { let far = store::open(&config, &channel.far).await?; let near = store::open(&config, &channel.near).await?; + + if channel.sync.contains(ChannelSyncOps::PULL) { + store::sync(&far, &near, channel.sync).await?; + } } Ok(()) diff --git a/mbsync/src/store.rs b/mbsync/src/store.rs index 9a25989..3482d75 100644 --- a/mbsync/src/store.rs +++ b/mbsync/src/store.rs @@ -1,7 +1,9 @@ +use std::path::PathBuf; + use anyhow::Result; use panorama_imap::client::{auth::Login, ClientAuthenticated, ConfigBuilder}; -use crate::config::{Account, Config, SslType, Store}; +use crate::config::{Account, ChannelSyncOps, Config, SslType, Store}; pub async fn open(config: &Config, store_name: impl AsRef) -> Result { let store = config @@ -45,12 +47,19 @@ pub async fn open(config: &Config, store_name: impl AsRef) -> Result { - todo!() + let path = store.path.clone(); + Ok(OpenedStore::Maildir(MaildirStore { + name: store.name.clone(), + path, + })) } } } @@ -60,12 +69,40 @@ pub enum OpenedStore { Maildir(MaildirStore), } +pub async fn sync(from: &OpenedStore, to: &OpenedStore, flags: ChannelSyncOps) -> Result<()> { + println!("{} -> {}", from.name(), to.name()); + let from_uid = from.uid(); + let to_uid = to.uid(); + + Ok(()) +} + impl OpenedStore { - + fn name(&self) -> &str { + match self { + OpenedStore::Imap(store) => &store.name, + OpenedStore::Maildir(store) => &store.name, + } + } + + async fn uid(&self) -> Result { + match self { + OpenedStore::Imap(store) => { + todo!() + } + OpenedStore::Maildir(store) => { + todo!() + } + } + } } pub struct ImapStore { + name: String, client: ClientAuthenticated, } -pub struct MaildirStore {} +pub struct MaildirStore { + name: String, + path: PathBuf, +}