From ca4c2e7505f28acad688705d45cc5c5dca1799c3 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Mon, 20 Jun 2022 18:09:20 +0200 Subject: WIP refactor --- src/imap/command/anonymous.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/imap/command/anonymous.rs') diff --git a/src/imap/command/anonymous.rs b/src/imap/command/anonymous.rs index e4222f7..55e701b 100644 --- a/src/imap/command/anonymous.rs +++ b/src/imap/command/anonymous.rs @@ -1,23 +1,28 @@ -use boitalettres::proto::{Request, Response}; -use crate::login::ArcLoginProvider; -use crate::imap::Context; +use anyhow::{Result, Error}; +use boitalettres::proto::Response; +use imap_codec::types::command::CommandBody; +use imap_codec::types::core::AString; +use imap_codec::types::response::{Capability, Data, Response as ImapRes, Status}; + +use crate::imap::flow; +use crate::imap::session::InnerContext; //--- dispatching -pub async fn dispatch(ctx: Context) -> Result { +pub async fn dispatch<'a>(ctx: &'a InnerContext<'a>) -> Result { match ctx.req.body { - CommandBody::Capability => anonymous::capability(ctx).await, - CommandBody::Login { username, password } => anonymous::login(ctx, username, password).await, + 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)]) .map_err(Error::msg), } } -//--- Command controllers +//--- Command controllers, private -pub async fn capability(ctx: Context) -> Result { +async fn capability<'a>(ctx: InnerContext<'a>) -> Result { let capabilities = vec![Capability::Imap4Rev1, Capability::Idle]; let res = vec![ ImapRes::Data(Data::Capability(capabilities)), @@ -29,7 +34,7 @@ pub async fn capability(ctx: Context) -> Result { Ok(res) } -pub async fn login(ctx: Context, username: AString, password: AString) -> Result { +async fn login<'a>(ctx: InnerContext<'a>, username: AString, password: AString) -> Result { let (u, p) = (String::try_from(username)?, String::try_from(password)?); tracing::info!(user = %u, "command.login"); -- cgit v1.2.3