Working server
This commit is contained in:
parent
deced08513
commit
3cb7c65b70
4 changed files with 49 additions and 31 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -973,6 +973,7 @@ dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"hex",
|
"hex",
|
||||||
"im",
|
"im",
|
||||||
|
"imap-codec",
|
||||||
"itertools",
|
"itertools",
|
||||||
"k2v-client",
|
"k2v-client",
|
||||||
"ldap3",
|
"ldap3",
|
||||||
|
|
|
@ -35,6 +35,7 @@ tracing-subscriber = "0.3"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tower = "0.4"
|
tower = "0.4"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
|
imap-codec = "0.5"
|
||||||
|
|
||||||
|
|
||||||
k2v-client = { git = "https://git.deuxfleurs.fr/Deuxfleurs/garage.git", branch = "main" }
|
k2v-client = { git = "https://git.deuxfleurs.fr/Deuxfleurs/garage.git", branch = "main" }
|
||||||
|
|
|
@ -111,9 +111,10 @@ struct UserSecretsArgs {
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
if std::env::var("RUST_LOG").is_err() {
|
if std::env::var("RUST_LOG").is_err() {
|
||||||
std::env::set_var("RUST_LOG", "mailrage=info,k2v_client=info")
|
std::env::set_var("RUST_LOG", "main=info,mailrage=info,k2v_client=info")
|
||||||
}
|
}
|
||||||
pretty_env_logger::init();
|
|
||||||
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
|
|
|
@ -10,14 +10,10 @@ use crate::mailbox::Mailbox;
|
||||||
use boitalettres::proto::{Request, Response};
|
use boitalettres::proto::{Request, Response};
|
||||||
use boitalettres::server::accept::addr::{AddrIncoming, AddrStream};
|
use boitalettres::server::accept::addr::{AddrIncoming, AddrStream};
|
||||||
use boitalettres::server::Server as ImapServer;
|
use boitalettres::server::Server as ImapServer;
|
||||||
use tracing_subscriber;
|
|
||||||
|
|
||||||
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use tower::Service;
|
use tower::Service;
|
||||||
use std::future::Future;
|
|
||||||
use std::pin::Pin;
|
|
||||||
|
|
||||||
use std::error::Error;
|
|
||||||
|
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
pub login_provider: Box<dyn LoginProvider>,
|
pub login_provider: Box<dyn LoginProvider>,
|
||||||
|
@ -25,38 +21,57 @@ pub struct Server {
|
||||||
|
|
||||||
struct Connection;
|
struct Connection;
|
||||||
impl Service<Request> for Connection {
|
impl Service<Request> for Connection {
|
||||||
type Response = Response;
|
type Response = Response;
|
||||||
type Error = anyhow::Error;
|
type Error = anyhow::Error;
|
||||||
type Future = Pin<Box<dyn futures::Future<Output = Result<Self::Response>> + Send>>;
|
type Future = Pin<Box<dyn futures::Future<Output = Result<Self::Response>> + Send>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
Poll::Ready(Ok(()))
|
Poll::Ready(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, req: Request) -> Self::Future {
|
fn call(&mut self, req: Request) -> Self::Future {
|
||||||
Box::pin(async move {
|
tracing::debug!("Got request: {:#?}", req);
|
||||||
println!("Got request: {:#?}", req);
|
Box::pin(async move {
|
||||||
Ok(Response::ok("Done")?)
|
use imap_codec::types::{
|
||||||
})
|
command::CommandBody,
|
||||||
}
|
response::{Capability, Data},
|
||||||
|
};
|
||||||
|
|
||||||
|
let r = match req.body {
|
||||||
|
CommandBody::Capability => {
|
||||||
|
let capabilities = vec![Capability::Imap4Rev1, Capability::Idle];
|
||||||
|
let body = vec![Data::Capability(capabilities)];
|
||||||
|
Response::ok(
|
||||||
|
"Pre-login capabilities listed, post-login capabilities have more.",
|
||||||
|
)?
|
||||||
|
.with_body(body)
|
||||||
|
}
|
||||||
|
CommandBody::Login {
|
||||||
|
username: _,
|
||||||
|
password: _,
|
||||||
|
} => Response::ok("Logged in")?,
|
||||||
|
_ => Response::bad("Error in IMAP command received by server.")?,
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(r)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Instance;
|
struct Instance;
|
||||||
impl<'a> Service<&'a AddrStream> for Instance {
|
impl<'a> Service<&'a AddrStream> for Instance {
|
||||||
type Response = Connection;
|
type Response = Connection;
|
||||||
type Error = anyhow::Error;
|
type Error = anyhow::Error;
|
||||||
type Future = Pin<Box<dyn futures::Future<Output = Result<Self::Response>> + Send>>;
|
type Future = Pin<Box<dyn futures::Future<Output = Result<Self::Response>> + Send>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
Poll::Ready(Ok(()))
|
Poll::Ready(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, addr: &'a AddrStream) -> Self::Future {
|
fn call(&mut self, addr: &'a AddrStream) -> Self::Future {
|
||||||
println!("{}, {}", addr.remote_addr, addr.local_addr);
|
tracing::info!(remote_addr = %addr.remote_addr, local_addr = %addr.local_addr, "accept");
|
||||||
Box::pin(async {
|
Box::pin(async { Ok(Connection) })
|
||||||
Ok(Connection)
|
}
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
|
|
Loading…
Reference in a new issue