diff --git a/Cargo.lock b/Cargo.lock index a5364b8..44c9cb1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -362,7 +362,7 @@ dependencies = [ [[package]] name = "boitalettres" version = "0.0.1" -source = "git+https://git.deuxfleurs.fr/quentin/boitalettres.git?branch=expose_req_res#2c43b7686a7cd06f733719350bd61f792d20338e" +source = "git+https://git.deuxfleurs.fr/KokaKiwi/boitalettres.git?branch=main#01ee8c872b15e2aecb4c0ef5c2dd3aa6cc3c4d3c" dependencies = [ "async-compat", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 2cbf5f9..4393d1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ tower = "0.4" imap-codec = "0.5" k2v-client = { git = "https://git.deuxfleurs.fr/Deuxfleurs/garage.git", branch = "main" } -boitalettres = { git = "https://git.deuxfleurs.fr/quentin/boitalettres.git", branch = "expose_req_res" } +boitalettres = { git = "https://git.deuxfleurs.fr/KokaKiwi/boitalettres.git", branch = "main" } smtp-message = { git = "http://github.com/Alexis211/kannader", branch = "feature/lmtp" } smtp-server = { git = "http://github.com/Alexis211/kannader", branch = "feature/lmtp" } diff --git a/src/imap/command/anonymous.rs b/src/imap/command/anonymous.rs index c1b800e..a2f2260 100644 --- a/src/imap/command/anonymous.rs +++ b/src/imap/command/anonymous.rs @@ -10,16 +10,13 @@ use crate::imap::session::InnerContext; //--- dispatching pub async fn dispatch<'a>(ctx: InnerContext<'a>) -> Result<(Response, flow::Transition)> { - match &ctx.req.body { + match &ctx.req.command.body { CommandBody::Capability => capability(ctx).await, CommandBody::Login { username, password } => login(ctx, username, password).await, - _ => Status::no( - Some(ctx.req.tag.clone()), - None, - "This command is not available in the ANONYMOUS state.", - ) - .map(|s| (vec![ImapRes::Status(s)], flow::Transition::No)) - .map_err(Error::msg), + _ => Ok(( + Response::no("This command is not available in the ANONYMOUS state.")?, + flow::Transition::No + )), } } @@ -27,13 +24,7 @@ pub async fn dispatch<'a>(ctx: InnerContext<'a>) -> Result<(Response, flow::Tran async fn capability<'a>(ctx: InnerContext<'a>) -> Result<(Response, flow::Transition)> { let capabilities = vec![Capability::Imap4Rev1, Capability::Idle]; - let res = vec![ - ImapRes::Data(Data::Capability(capabilities)), - ImapRes::Status( - Status::ok(Some(ctx.req.tag.clone()), None, "Server capabilities") - .map_err(Error::msg)?, - ), - ]; + let res = Response::ok("Server capabilities")?.with_body(Data::Capability(capabilities)); Ok((res, flow::Transition::No)) } @@ -51,13 +42,7 @@ async fn login<'a>( let creds = match ctx.login.login(&u, &p).await { Err(e) => { tracing::debug!(error=%e, "authentication failed"); - return Ok(( - vec![ImapRes::Status( - Status::no(Some(ctx.req.tag.clone()), None, "Authentication failed") - .map_err(Error::msg)?, - )], - flow::Transition::No, - )); + return Ok((Response::no("Authentication failed")?, flow::Transition::No)); } Ok(c) => c, }; @@ -66,16 +51,10 @@ async fn login<'a>( creds, name: u.clone(), }; - let tr = flow::Transition::Authenticate(user); tracing::info!(username=%u, "connected"); Ok(( - vec![ - //@FIXME we could send a capability status here too - ImapRes::Status( - Status::ok(Some(ctx.req.tag.clone()), None, "completed").map_err(Error::msg)?, - ), - ], - tr, + Response::ok("Completed")?, + flow::Transition::Authenticate(user) )) } diff --git a/src/imap/command/authenticated.rs b/src/imap/command/authenticated.rs index 0b1f01e..85c1c82 100644 --- a/src/imap/command/authenticated.rs +++ b/src/imap/command/authenticated.rs @@ -1,7 +1,7 @@ use anyhow::{anyhow, Error, Result}; -use boitalettres::proto::Response; +use boitalettres::proto::{Response, res::body::Data as Body}; use imap_codec::types::command::CommandBody; -use imap_codec::types::core::{Atom, Tag}; +use imap_codec::types::core::Atom; use imap_codec::types::flag::Flag; use imap_codec::types::mailbox::{ListMailbox, Mailbox as MailboxCodec}; use imap_codec::types::response::{Code, Data, Response as ImapRes, Status}; @@ -23,13 +23,9 @@ pub async fn dispatch<'a>( inner: InnerContext<'a>, user: &'a flow::User, ) -> Result<(Response, flow::Transition)> { - let ctx = StateContext { - user, - tag: &inner.req.tag, - inner, - }; + let ctx = StateContext { user, inner }; - match &ctx.inner.req.body { + match &ctx.inner.req.command.body { CommandBody::Lsub { reference, mailbox_wildcard, @@ -48,7 +44,6 @@ pub async fn dispatch<'a>( struct StateContext<'a> { inner: InnerContext<'a>, user: &'a flow::User, - tag: &'a Tag, } impl<'a> StateContext<'a> { @@ -58,9 +53,7 @@ impl<'a> StateContext<'a> { mailbox_wildcard: &ListMailbox, ) -> Result<(Response, flow::Transition)> { Ok(( - vec![ImapRes::Status( - Status::bad(Some(self.tag.clone()), None, "Not implemented").map_err(Error::msg)?, - )], + Response::bad("Not implemented")?, flow::Transition::No, )) } @@ -71,9 +64,7 @@ impl<'a> StateContext<'a> { mailbox_wildcard: &ListMailbox, ) -> Result<(Response, flow::Transition)> { Ok(( - vec![ImapRes::Status( - Status::bad(Some(self.tag.clone()), None, "Not implemented").map_err(Error::msg)?, - )], + Response::bad("Not implemented")?, flow::Transition::No, )) } @@ -115,20 +106,11 @@ impl<'a> StateContext<'a> { let sum = mb.summary().await?; tracing::trace!(summary=%sum, "mailbox.summary"); - let r_unseen = Status::ok( - None, - Some(Code::Unseen( - std::num::NonZeroU32::new(1).ok_or(anyhow!("Invalid message identifier"))?, - )), - "First unseen UID", - ) - .map_err(Error::msg)?; + let mut res = Vec::
::new(); - let mut res = Vec::