sync
This commit is contained in:
parent
dfdb71dea2
commit
ff98685afb
3 changed files with 51 additions and 7 deletions
|
@ -2,7 +2,10 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Clap;
|
use clap::Clap;
|
||||||
use mbsync::{config, store};
|
use mbsync::{
|
||||||
|
config::{self, ChannelSyncOps},
|
||||||
|
store,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clap)]
|
#[derive(Debug, Clap)]
|
||||||
struct Opt {
|
struct Opt {
|
||||||
|
@ -30,6 +33,10 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
let far = store::open(&config, &channel.far).await?;
|
let far = store::open(&config, &channel.far).await?;
|
||||||
let near = store::open(&config, &channel.near).await?;
|
let near = store::open(&config, &channel.near).await?;
|
||||||
|
|
||||||
|
if channel.sync.contains(ChannelSyncOps::PULL) {
|
||||||
|
store::sync(&far, &near, channel.sync).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use panorama_imap::client::{auth::Login, ClientAuthenticated, ConfigBuilder};
|
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> {
|
pub async fn open(config: &Config, store_name: impl AsRef<str>) -> Result<OpenedStore> {
|
||||||
let store = config
|
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?;
|
let client = client.auth(login).await?;
|
||||||
|
|
||||||
println!("authenticated");
|
println!("authenticated");
|
||||||
Ok(OpenedStore::Imap(ImapStore { client }))
|
Ok(OpenedStore::Imap(ImapStore {
|
||||||
|
name: account.name.clone(),
|
||||||
|
client,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Store::Maildir(store) => {
|
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),
|
Maildir(MaildirStore),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OpenedStore {
|
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 {
|
pub struct ImapStore {
|
||||||
|
name: String,
|
||||||
client: ClientAuthenticated,
|
client: ClientAuthenticated,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MaildirStore {}
|
pub struct MaildirStore {
|
||||||
|
name: String,
|
||||||
|
path: PathBuf,
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue