aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2022-06-01 18:00:56 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2022-06-01 18:00:56 +0200
commit109337b904ce1ca03f2f6e6216edc8c1af359870 (patch)
tree3d7c8699e608652b8a323111365d973c9a3d2714 /src
parent6682edfc5e13e4b968c95268ee903a0dab538274 (diff)
downloadaerogramme-109337b904ce1ca03f2f6e6216edc8c1af359870.tar.gz
aerogramme-109337b904ce1ca03f2f6e6216edc8c1af359870.zip
Start bal in mailrage
Diffstat (limited to 'src')
-rw-r--r--src/config.rs2
-rw-r--r--src/server.rs28
-rw-r--r--src/test.rs47
3 files changed, 51 insertions, 26 deletions
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<dyn LoginProvider>,
}
+async fn handle_req(req: Request) -> Result<Response> {
+ tracing::debug!("Got request: {:#?}", req);
+ Ok(Response::ok("Done")?)
+}
+
impl Server {
pub fn new(config: Config) -> Result<Arc<Self>> {
let s3_region = Region::Custom {
@@ -32,11 +42,25 @@ impl Server {
}
pub async fn run(self: &Arc<Self>) -> 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);
}