From 98f55be7304ef1078960408ff4435109601c0206 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 22 Jun 2022 14:58:57 +0200 Subject: It compiles again! --- src/imap/command/anonymous.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/imap/command/anonymous.rs') diff --git a/src/imap/command/anonymous.rs b/src/imap/command/anonymous.rs index 55e701b..c6af354 100644 --- a/src/imap/command/anonymous.rs +++ b/src/imap/command/anonymous.rs @@ -10,19 +10,19 @@ use crate::imap::session::InnerContext; //--- dispatching -pub async fn dispatch<'a>(ctx: &'a InnerContext<'a>) -> Result { - match ctx.req.body { +pub async fn dispatch<'a>(ctx: InnerContext<'a>) -> Result<(Response, flow::Transition)> { + match &ctx.req.body { CommandBody::Capability => capability(ctx).await, - CommandBody::Login { username, password } => login(ctx, username, password).await, + CommandBody::Login { username, password } => login(ctx, username.clone(), password.clone()).await, _ => Status::no(Some(ctx.req.tag.clone()), None, "This command is not available in the ANONYMOUS state.") - .map(|s| vec![ImapRes::Status(s)]) + .map(|s| (vec![ImapRes::Status(s)], flow::Transition::No)) .map_err(Error::msg), } } //--- Command controllers, private -async fn capability<'a>(ctx: InnerContext<'a>) -> Result { +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)), @@ -31,20 +31,20 @@ async fn capability<'a>(ctx: InnerContext<'a>) -> Result { .map_err(Error::msg)?, ), ]; - Ok(res) + Ok((res, flow::Transition::No)) } -async fn login<'a>(ctx: InnerContext<'a>, username: AString, password: AString) -> Result { +async fn login<'a>(ctx: InnerContext<'a>, username: AString, password: AString) -> Result<(Response, flow::Transition)> { let (u, p) = (String::try_from(username)?, String::try_from(password)?); tracing::info!(user = %u, "command.login"); - let creds = match ctx.login_provider.login(&u, &p).await { + let creds = match ctx.login.login(&u, &p).await { Err(e) => { tracing::debug!(error=%e, "authentication failed"); - return Ok(vec![ImapRes::Status( + return Ok((vec![ImapRes::Status( Status::no(Some(ctx.req.tag.clone()), None, "Authentication failed") .map_err(Error::msg)?, - )]); + )], flow::Transition::No)); } Ok(c) => c, }; @@ -53,13 +53,13 @@ async fn login<'a>(ctx: InnerContext<'a>, username: AString, password: AString) creds, name: u.clone(), }; - ctx.state.authenticate(user)?; + let tr = flow::Transition::Authenticate(user); tracing::info!(username=%u, "connected"); - Ok(vec![ + 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)) } -- cgit v1.2.3