2022-05-18 10:24:37 +00:00
|
|
|
mod bayou;
|
2022-05-19 10:10:48 +00:00
|
|
|
mod config;
|
2022-05-18 10:24:37 +00:00
|
|
|
mod cryptoblob;
|
2022-05-19 10:10:48 +00:00
|
|
|
mod login;
|
2022-05-19 10:14:06 +00:00
|
|
|
mod mailbox;
|
2022-05-18 10:24:37 +00:00
|
|
|
mod time;
|
|
|
|
mod uidindex;
|
|
|
|
|
2022-05-19 10:10:48 +00:00
|
|
|
use anyhow::{bail, Result};
|
|
|
|
use std::sync::Arc;
|
2022-05-18 12:54:48 +00:00
|
|
|
|
|
|
|
use rusoto_signature::Region;
|
|
|
|
|
2022-05-19 10:10:48 +00:00
|
|
|
use config::*;
|
|
|
|
use login::{ldap_provider::*, static_provider::*, *};
|
|
|
|
use mailbox::Mailbox;
|
2022-05-18 10:24:37 +00:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2022-05-19 10:10:48 +00:00
|
|
|
if let Err(e) = main2().await {
|
|
|
|
eprintln!("Error: {}", e);
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
2022-05-18 10:24:37 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 10:10:48 +00:00
|
|
|
async fn main2() -> Result<()> {
|
|
|
|
let config = read_config("mailrage.toml".into())?;
|
2022-05-18 12:54:48 +00:00
|
|
|
|
2022-05-19 10:10:48 +00:00
|
|
|
let main = Main::new(config)?;
|
|
|
|
main.run().await
|
|
|
|
}
|
2022-05-18 10:24:37 +00:00
|
|
|
|
2022-05-19 10:10:48 +00:00
|
|
|
struct Main {
|
|
|
|
pub s3_region: Region,
|
|
|
|
pub k2v_region: Region,
|
|
|
|
pub login_provider: Box<dyn LoginProvider>,
|
|
|
|
}
|
2022-05-18 12:54:48 +00:00
|
|
|
|
2022-05-19 10:10:48 +00:00
|
|
|
impl Main {
|
|
|
|
fn new(config: Config) -> Result<Arc<Self>> {
|
|
|
|
let s3_region = Region::Custom {
|
|
|
|
name: config.s3_region,
|
|
|
|
endpoint: config.s3_endpoint,
|
|
|
|
};
|
|
|
|
let k2v_region = Region::Custom {
|
|
|
|
name: config.k2v_region,
|
|
|
|
endpoint: config.k2v_endpoint,
|
|
|
|
};
|
|
|
|
let login_provider: Box<dyn LoginProvider> = match (config.login_static, config.login_ldap)
|
|
|
|
{
|
|
|
|
(Some(st), None) => Box::new(StaticLoginProvider::new(st, k2v_region.clone())?),
|
|
|
|
(None, Some(ld)) => Box::new(LdapLoginProvider::new(ld)?),
|
|
|
|
(Some(_), Some(_)) => bail!("A single login provider must be set up in config file"),
|
|
|
|
(None, None) => bail!("No login provider is set up in config file"),
|
|
|
|
};
|
|
|
|
Ok(Arc::new(Self {
|
|
|
|
s3_region,
|
|
|
|
k2v_region,
|
|
|
|
login_provider,
|
|
|
|
}))
|
|
|
|
}
|
2022-05-18 10:42:25 +00:00
|
|
|
|
2022-05-19 10:10:48 +00:00
|
|
|
async fn run(self: &Arc<Self>) -> Result<()> {
|
|
|
|
let creds = self.login_provider.login("lx", "plop").await?;
|
2022-05-18 14:03:27 +00:00
|
|
|
|
2022-05-19 10:14:06 +00:00
|
|
|
let mut mailbox = Mailbox::new(
|
2022-05-19 11:54:38 +00:00
|
|
|
&self.k2v_region,
|
|
|
|
&self.s3_region,
|
|
|
|
&creds,
|
2022-05-19 10:14:06 +00:00
|
|
|
"TestMailbox".to_string(),
|
|
|
|
)
|
|
|
|
.await?;
|
2022-05-18 14:03:27 +00:00
|
|
|
|
2022-05-19 10:10:48 +00:00
|
|
|
mailbox.test().await?;
|
2022-05-18 12:54:48 +00:00
|
|
|
|
2022-05-19 10:10:48 +00:00
|
|
|
Ok(())
|
2022-05-18 12:54:48 +00:00
|
|
|
}
|
|
|
|
}
|