aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2022-06-03 17:37:39 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2022-06-03 17:37:39 +0200
commite950931c5f145c05353aa377f99fb2daac37d044 (patch)
tree2c7fd58299432853ec905cd5f7a2ab7376de5fba /src
parent3589b0fa4b290ebbe416d793b9f82673754ab6f9 (diff)
downloadaerogramme-e950931c5f145c05353aa377f99fb2daac37d044.tar.gz
aerogramme-e950931c5f145c05353aa377f99fb2daac37d044.zip
Run cargo fmt
Diffstat (limited to 'src')
-rw-r--r--src/connection.rs23
-rw-r--r--src/instance.rs14
-rw-r--r--src/mailstore.rs19
-rw-r--r--src/server.rs15
4 files changed, 33 insertions, 38 deletions
diff --git a/src/connection.rs b/src/connection.rs
index aed11fa..fecb4f4 100644
--- a/src/connection.rs
+++ b/src/connection.rs
@@ -2,7 +2,7 @@ use std::sync::Arc;
use std::task::{Context, Poll};
use boitalettres::errors::Error as BalError;
-use boitalettres::proto::{Request,Response};
+use boitalettres::proto::{Request, Response};
use futures::future::BoxFuture;
use tower::Service;
@@ -12,9 +12,9 @@ pub struct Connection {
pub mailstore: Arc<Mailstore>,
}
impl Connection {
- pub fn new(mailstore: Arc<Mailstore>) -> Self {
- Self { mailstore }
- }
+ pub fn new(mailstore: Arc<Mailstore>) -> Self {
+ Self { mailstore }
+ }
}
impl Service<Request> for Connection {
type Response = Response;
@@ -43,18 +43,17 @@ impl Service<Request> for Connection {
)?
.with_body(body)
}
- CommandBody::Login {
- username,
- password,
- } => {
+ CommandBody::Login { username, password } => {
let (u, p) = match (String::try_from(username), String::try_from(password)) {
- (Ok(u), Ok(p)) => (u, p),
- _ => { return Response::bad("Invalid characters") }
+ (Ok(u), Ok(p)) => (u, p),
+ _ => return Response::bad("Invalid characters"),
};
tracing::debug!(user = %u, "command.login");
let creds = match mailstore.login_provider.login(&u, &p).await {
- Err(_) => { return Response::no("[AUTHENTICATIONFAILED] Authentication failed.") }
+ Err(_) => {
+ return Response::no("[AUTHENTICATIONFAILED] Authentication failed.")
+ }
Ok(c) => c,
};
@@ -67,5 +66,3 @@ impl Service<Request> for Connection {
})
}
}
-
-
diff --git a/src/instance.rs b/src/instance.rs
index cb0468f..6e11be5 100644
--- a/src/instance.rs
+++ b/src/instance.rs
@@ -10,12 +10,12 @@ use crate::connection::Connection;
use crate::mailstore::Mailstore;
pub struct Instance {
- pub mailstore: Arc<Mailstore>
+ pub mailstore: Arc<Mailstore>,
}
impl Instance {
- pub fn new(mailstore: Arc<Mailstore>) -> Self {
- Self { mailstore }
- }
+ pub fn new(mailstore: Arc<Mailstore>) -> Self {
+ Self { mailstore }
+ }
}
impl<'a> Service<&'a AddrStream> for Instance {
type Response = Connection;
@@ -29,10 +29,6 @@ impl<'a> Service<&'a AddrStream> for Instance {
fn call(&mut self, addr: &'a AddrStream) -> Self::Future {
tracing::info!(remote_addr = %addr.remote_addr, local_addr = %addr.local_addr, "accept");
let ms = self.mailstore.clone();
- Box::pin(async {
- Ok(Connection::new(ms))
- })
+ Box::pin(async { Ok(Connection::new(ms)) })
}
}
-
-
diff --git a/src/mailstore.rs b/src/mailstore.rs
index e4387cb..2bcc592 100644
--- a/src/mailstore.rs
+++ b/src/mailstore.rs
@@ -19,16 +19,15 @@ impl Mailstore {
name: config.aws_region,
endpoint: config.k2v_endpoint,
};
- let login_provider: Box<dyn LoginProvider + Send + Sync> = match (config.login_static, config.login_ldap)
- {
- (Some(st), None) => Box::new(StaticLoginProvider::new(st, k2v_region, s3_region)?),
- (None, Some(ld)) => Box::new(LdapLoginProvider::new(ld, k2v_region, s3_region)?),
- (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"),
- };
+ let login_provider: Box<dyn LoginProvider + Send + Sync> =
+ match (config.login_static, config.login_ldap) {
+ (Some(st), None) => Box::new(StaticLoginProvider::new(st, k2v_region, s3_region)?),
+ (None, Some(ld)) => Box::new(LdapLoginProvider::new(ld, k2v_region, s3_region)?),
+ (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 { login_provider }))
}
}
-
-
-
diff --git a/src/server.rs b/src/server.rs
index 4fe5f12..8a9b7a3 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -2,8 +2,8 @@ use anyhow::Result;
use std::sync::Arc;
use crate::config::*;
-use crate::mailstore;
use crate::instance;
+use crate::mailstore;
use boitalettres::server::accept::addr::AddrIncoming;
use boitalettres::server::Server as ImapServer;
@@ -14,7 +14,7 @@ pub struct Server {
}
impl Server {
pub async fn new(config: Config) -> Result<Self> {
- Ok(Self {
+ Ok(Self {
incoming: AddrIncoming::new("127.0.0.1:4567").await?,
mailstore: mailstore::Mailstore::new(config)?,
})
@@ -23,15 +23,18 @@ impl Server {
pub async fn run(self: Self) -> Result<()> {
tracing::info!("Starting server on {:#}", self.incoming.local_addr);
-
- let creds = self.mailstore.login_provider.login("quentin", "poupou").await?;
+ let creds = self
+ .mailstore
+ .login_provider
+ .login("quentin", "poupou")
+ .await?;
//let mut mailbox = Mailbox::new(&creds, "TestMailbox".to_string()).await?;
//mailbox.test().await?;
- let server = ImapServer::new(self.incoming).serve(instance::Instance::new(self.mailstore.clone()));
+ let server =
+ ImapServer::new(self.incoming).serve(instance::Instance::new(self.mailstore.clone()));
let _ = server.await?;
-
Ok(())
}
}