From 109337b904ce1ca03f2f6e6216edc8c1af359870 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 1 Jun 2022 18:00:56 +0200 Subject: Start bal in mailrage --- src/config.rs | 2 +- src/server.rs | 28 ++++++++++++++++++++++++++-- src/test.rs | 47 ++++++++++++++++++++++++----------------------- 3 files changed, 51 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index 6c3801c..3ffc553 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,7 +3,7 @@ use std::io::Read; use std::path::PathBuf; use anyhow::Result; -use serde::{Serialize,Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Config { diff --git a/src/server.rs b/src/server.rs index ed751de..0fca3ec 100644 --- a/src/server.rs +++ b/src/server.rs @@ -7,10 +7,20 @@ use crate::config::*; use crate::login::{ldap_provider::*, static_provider::*, *}; use crate::mailbox::Mailbox; +use boitalettres::proto::{Request, Response}; +use boitalettres::server::accept::addr::{AddrIncoming, AddrStream}; +use boitalettres::server::Server as ImapServer; +use tracing_subscriber; + pub struct Server { pub login_provider: Box, } +async fn handle_req(req: Request) -> Result { + tracing::debug!("Got request: {:#?}", req); + Ok(Response::ok("Done")?) +} + impl Server { pub fn new(config: Config) -> Result> { let s3_region = Region::Custom { @@ -32,11 +42,25 @@ impl Server { } pub async fn run(self: &Arc) -> Result<()> { - let creds = self.login_provider.login("quentin", "poupou").await?; + // tracing_subscriber::fmt::init(); + + let incoming = AddrIncoming::new("127.0.0.1:4567").await?; + + let make_service = tower::service_fn(|addr: &AddrStream| { + tracing::debug!(remote_addr = %addr.remote_addr, local_addr = %addr.local_addr, "accept"); + let service = tower::ServiceBuilder::new().service_fn(handle_req); + futures::future::ok::<_, std::convert::Infallible>(service) + }); + + + let server = ImapServer::new(incoming).serve(make_service); + let _ = server.await?; + + /*let creds = self.login_provider.login("quentin", "poupou").await?; let mut mailbox = Mailbox::new(&creds, "TestMailbox".to_string()).await?; - mailbox.test().await?; + mailbox.test().await?;*/ Ok(()) } diff --git a/src/test.rs b/src/test.rs index 4d32a6f..29db928 100644 --- a/src/test.rs +++ b/src/test.rs @@ -1,31 +1,32 @@ -mod config; +mod config; use serde::Serialize; use std::collections::HashMap; fn main() { - let config = config::Config { - s3_endpoint: "http://127.0.0.1:3900".to_string(), - k2v_endpoint: "http://127.0.0.1:3904".to_string(), - aws_region: "garage".to_string(), - login_static: Some(config::LoginStaticConfig { - default_bucket: Some("mailrage".to_string()), - users: HashMap::from([ - ("quentin".to_string(), config::LoginStaticUser { - password: "toto".to_string(), - aws_access_key_id: "GKxxx".to_string(), - aws_secret_access_key: "ffff".to_string(), - bucket: Some("mailrage-quentin".to_string()), - user_secret: "xxx".to_string(), - alternate_user_secrets: vec![], - master_key: None, - secret_key: None, + let config = config::Config { + s3_endpoint: "http://127.0.0.1:3900".to_string(), + k2v_endpoint: "http://127.0.0.1:3904".to_string(), + aws_region: "garage".to_string(), + login_static: Some(config::LoginStaticConfig { + default_bucket: Some("mailrage".to_string()), + users: HashMap::from([( + "quentin".to_string(), + config::LoginStaticUser { + password: "toto".to_string(), + aws_access_key_id: "GKxxx".to_string(), + aws_secret_access_key: "ffff".to_string(), + bucket: Some("mailrage-quentin".to_string()), + user_secret: "xxx".to_string(), + alternate_user_secrets: vec![], + master_key: None, + secret_key: None, + }, + )]), }), - ]), - }), - login_ldap: None, - }; + login_ldap: None, + }; - let ser = toml::to_string(&config).unwrap(); - println!("{}", ser); + let ser = toml::to_string(&config).unwrap(); + println!("{}", ser); } -- cgit v1.2.3