From 7f35e68bfe21c61f4da9e37f127dd7abb73291fa Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 27 Feb 2024 18:33:49 +0100 Subject: Refactor --- src/imap/command/anonymous.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/imap/command/anonymous.rs') diff --git a/src/imap/command/anonymous.rs b/src/imap/command/anonymous.rs index 0582b06..811d1e4 100644 --- a/src/imap/command/anonymous.rs +++ b/src/imap/command/anonymous.rs @@ -9,7 +9,7 @@ use crate::imap::command::anystate; use crate::imap::flow; use crate::imap::response::Response; use crate::login::ArcLoginProvider; -use crate::mail::user::User; +use crate::user::User; //--- dispatching -- cgit v1.2.3 From 1a43ce5ac7033c148f64a033f2b1d335e95e11d5 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 8 Mar 2024 08:17:03 +0100 Subject: WIP refactor --- src/imap/command/anonymous.rs | 83 ------------------------------------------- 1 file changed, 83 deletions(-) delete mode 100644 src/imap/command/anonymous.rs (limited to 'src/imap/command/anonymous.rs') diff --git a/src/imap/command/anonymous.rs b/src/imap/command/anonymous.rs deleted file mode 100644 index 811d1e4..0000000 --- a/src/imap/command/anonymous.rs +++ /dev/null @@ -1,83 +0,0 @@ -use anyhow::Result; -use imap_codec::imap_types::command::{Command, CommandBody}; -use imap_codec::imap_types::core::AString; -use imap_codec::imap_types::response::Code; -use imap_codec::imap_types::secret::Secret; - -use crate::imap::capability::ServerCapability; -use crate::imap::command::anystate; -use crate::imap::flow; -use crate::imap::response::Response; -use crate::login::ArcLoginProvider; -use crate::user::User; - -//--- dispatching - -pub struct AnonymousContext<'a> { - pub req: &'a Command<'static>, - pub server_capabilities: &'a ServerCapability, - pub login_provider: &'a ArcLoginProvider, -} - -pub async fn dispatch(ctx: AnonymousContext<'_>) -> Result<(Response<'static>, flow::Transition)> { - match &ctx.req.body { - // Any State - CommandBody::Noop => anystate::noop_nothing(ctx.req.tag.clone()), - CommandBody::Capability => { - anystate::capability(ctx.req.tag.clone(), ctx.server_capabilities) - } - CommandBody::Logout => anystate::logout(), - - // Specific to anonymous context (3 commands) - CommandBody::Login { username, password } => ctx.login(username, password).await, - CommandBody::Authenticate { .. } => { - anystate::not_implemented(ctx.req.tag.clone(), "authenticate") - } - //StartTLS is not implemented for now, we will probably go full TLS. - - // Collect other commands - _ => anystate::wrong_state(ctx.req.tag.clone()), - } -} - -//--- Command controllers, private - -impl<'a> AnonymousContext<'a> { - async fn login( - self, - username: &AString<'a>, - password: &Secret>, - ) -> Result<(Response<'static>, flow::Transition)> { - let (u, p) = ( - std::str::from_utf8(username.as_ref())?, - std::str::from_utf8(password.declassify().as_ref())?, - ); - tracing::info!(user = %u, "command.login"); - - let creds = match self.login_provider.login(&u, &p).await { - Err(e) => { - tracing::debug!(error=%e, "authentication failed"); - return Ok(( - Response::build() - .to_req(self.req) - .message("Authentication failed") - .no()?, - flow::Transition::None, - )); - } - Ok(c) => c, - }; - - let user = User::new(u.to_string(), creds).await?; - - tracing::info!(username=%u, "connected"); - Ok(( - Response::build() - .to_req(self.req) - .code(Code::Capability(self.server_capabilities.to_vec())) - .message("Completed") - .ok()?, - flow::Transition::Authenticate(user), - )) - } -} -- cgit v1.2.3