From b15026ec9ca2045f7ddb21a759cb075bb1dbd014 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 30 Jun 2022 14:02:57 +0200 Subject: Refactor user to be shared using Arc --- src/imap/command/anonymous.rs | 2 +- src/imap/command/authenticated.rs | 4 +++- src/imap/command/examined.rs | 4 +++- src/imap/command/selected.rs | 4 +++- src/imap/flow.rs | 9 +++++---- 5 files changed, 15 insertions(+), 8 deletions(-) (limited to 'src/imap') diff --git a/src/imap/command/anonymous.rs b/src/imap/command/anonymous.rs index b84b0da..3ac1f20 100644 --- a/src/imap/command/anonymous.rs +++ b/src/imap/command/anonymous.rs @@ -66,7 +66,7 @@ impl<'a> AnonymousContext<'a> { Ok(c) => c, }; - let user = User::new(u.clone(), creds)?; + let user = User::new(u.clone(), creds).await?; tracing::info!(username=%u, "connected"); Ok(( diff --git a/src/imap/command/authenticated.rs b/src/imap/command/authenticated.rs index dfcb52e..0b34223 100644 --- a/src/imap/command/authenticated.rs +++ b/src/imap/command/authenticated.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use anyhow::Result; use boitalettres::proto::{Request, Response}; use imap_codec::types::command::{CommandBody, StatusAttribute}; @@ -12,7 +14,7 @@ use crate::mail::user::User; pub struct AuthenticatedContext<'a> { pub req: &'a Request, - pub user: &'a User, + pub user: &'a Arc, } pub async fn dispatch<'a>(ctx: AuthenticatedContext<'a>) -> Result<(Response, flow::Transition)> { diff --git a/src/imap/command/examined.rs b/src/imap/command/examined.rs index aad7874..91ad950 100644 --- a/src/imap/command/examined.rs +++ b/src/imap/command/examined.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use anyhow::Result; use boitalettres::proto::Request; use boitalettres::proto::Response; @@ -15,7 +17,7 @@ use crate::mail::user::User; pub struct ExaminedContext<'a> { pub req: &'a Request, - pub user: &'a User, + pub user: &'a Arc, pub mailbox: &'a mut MailboxView, } diff --git a/src/imap/command/selected.rs b/src/imap/command/selected.rs index a447a49..bb78cbd 100644 --- a/src/imap/command/selected.rs +++ b/src/imap/command/selected.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use anyhow::Result; use boitalettres::proto::Request; use boitalettres::proto::Response; @@ -16,7 +18,7 @@ use crate::mail::user::User; pub struct SelectedContext<'a> { pub req: &'a Request, - pub user: &'a User, + pub user: &'a Arc, pub mailbox: &'a mut MailboxView, } diff --git a/src/imap/flow.rs b/src/imap/flow.rs index feb78ac..303b498 100644 --- a/src/imap/flow.rs +++ b/src/imap/flow.rs @@ -1,5 +1,6 @@ use std::error::Error as StdError; use std::fmt; +use std::sync::Arc; use crate::imap::mailbox_view::MailboxView; use crate::mail::user::User; @@ -17,16 +18,16 @@ impl StdError for Error {} pub enum State { NotAuthenticated, - Authenticated(User), - Selected(User, MailboxView), + Authenticated(Arc), + Selected(Arc, MailboxView), // Examined is like Selected, but indicates that the mailbox is read-only - Examined(User, MailboxView), + Examined(Arc, MailboxView), Logout, } pub enum Transition { None, - Authenticate(User), + Authenticate(Arc), Examine(MailboxView), Select(MailboxView), Unselect, -- cgit v1.2.3