This commit is contained in:
Michael Zhang 2021-08-22 19:34:25 -05:00
parent dfdb71dea2
commit ff98685afb
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
3 changed files with 51 additions and 7 deletions

View file

@ -8,4 +8,4 @@ extern crate derivative;
extern crate derive_builder;
pub mod config;
pub mod store;
pub mod store;

View file

@ -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(())

View file

@ -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<str>) -> Result<OpenedStore> {
let store = config
@ -45,12 +47,19 @@ pub async fn open(config: &Config, store_name: impl AsRef<str>) -> Result<Opened
let client = client.auth(login).await?;
println!("authenticated");
Ok(OpenedStore::Imap(ImapStore { client }))
Ok(OpenedStore::Imap(ImapStore {
name: account.name.clone(),
client,
}))
}
}
}
Store::Maildir(store) => {
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<u32> {
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,
}