use miette::{IntoDiagnostic, Result}; use boitalettres::proto::{Request, Response}; use boitalettres::server::accept::addr::{AddrIncoming, AddrStream}; use boitalettres::server::Server; use tracing_subscriber; async fn handle_req(req: Request) -> Result { use imap_codec::types::response::{Capability, Data}; tracing::debug!("Got request: {:#?}", req); let capabilities = vec![Capability::Imap4Rev1, Capability::Idle]; let body = vec![Data::Capability(capabilities)]; Ok(Response::ok("Done")?.with_body(body)) } #[tokio::main] async fn main() -> eyre::Result<()> { tracing_subscriber::fmt::init(); let incoming = AddrIncoming::new("127.0.0.1:4567") .await .into_diagnostic()?; 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 = Server::new(incoming).serve(make_service); server.await.map_err(Into::into) }