From 1bc109df72a3d785211a128b3f28746232258924 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 29 Jun 2022 13:16:58 +0200 Subject: Refactoring --- src/imap/command/anonymous.rs | 8 ++++---- src/imap/command/authenticated.rs | 11 ++++++----- src/imap/command/selected.rs | 5 +++-- src/imap/flow.rs | 8 ++------ 4 files changed, 15 insertions(+), 17 deletions(-) (limited to 'src/imap') diff --git a/src/imap/command/anonymous.rs b/src/imap/command/anonymous.rs index 7e72458..5f982ba 100644 --- a/src/imap/command/anonymous.rs +++ b/src/imap/command/anonymous.rs @@ -5,6 +5,7 @@ use imap_codec::types::core::{AString}; use imap_codec::types::response::{Capability, Data, Status}; use crate::imap::flow; +use crate::mail::user::User; use crate::login::ArcLoginProvider; //--- dispatching @@ -68,10 +69,9 @@ impl<'a> AnonymousContext<'a> { Ok(c) => c, }; - let user = flow::User { - creds, - name: u.clone(), - }; + let s3_client = creds.s3_client(); + let k2v_client = creds.k2v_client(); + let user = User::new(u.clone(), creds)?; tracing::info!(username=%u, "connected"); Ok(( diff --git a/src/imap/command/authenticated.rs b/src/imap/command/authenticated.rs index 392069f..b79865f 100644 --- a/src/imap/command/authenticated.rs +++ b/src/imap/command/authenticated.rs @@ -9,7 +9,8 @@ use imap_codec::types::response::{Code, Data, Status}; use crate::imap::command::anonymous; use crate::imap::flow; -use crate::mail::Mailbox; +use crate::mail::mailbox::Mailbox; +use crate::mail::user::User; const DEFAULT_FLAGS: [Flag; 5] = [ Flag::Seen, @@ -21,7 +22,7 @@ const DEFAULT_FLAGS: [Flag; 5] = [ pub struct AuthenticatedContext<'a> { pub req: &'a Request, - pub user: &'a flow::User, + pub user: &'a User, } pub async fn dispatch<'a>(ctx: AuthenticatedContext<'a>) -> Result<(Response, flow::Transition)> { @@ -95,8 +96,8 @@ impl<'a> AuthenticatedContext<'a> { async fn select(self, mailbox: &MailboxCodec) -> Result<(Response, flow::Transition)> { let name = String::try_from(mailbox.clone())?; - let mut mb = Mailbox::new(&self.user.creds, name.clone())?; - tracing::info!(username=%self.user.name, mailbox=%name, "mailbox.selected"); + let mut mb = self.user.open_mailbox(name.clone())?; + tracing::info!(username=%self.user.username, mailbox=%name, "mailbox.selected"); let sum = mb.summary().await?; tracing::trace!(summary=%sum, "mailbox.summary"); @@ -112,7 +113,7 @@ impl<'a> AuthenticatedContext<'a> { Some('$') if f == "$unseen" => None, Some(_) => match Atom::try_from(f.clone()) { Err(_) => { - tracing::error!(username=%self.user.name, mailbox=%name, flag=%f, "Unable to encode flag as IMAP atom"); + tracing::error!(username=%self.user.username, mailbox=%name, flag=%f, "Unable to encode flag as IMAP atom"); None }, Ok(a) => Some(Flag::Keyword(a)), diff --git a/src/imap/command/selected.rs b/src/imap/command/selected.rs index d3dddd4..bd46bd5 100644 --- a/src/imap/command/selected.rs +++ b/src/imap/command/selected.rs @@ -10,11 +10,12 @@ use imap_codec::types::sequence::SequenceSet; use crate::imap::command::authenticated; use crate::imap::flow; -use crate::mail::Mailbox; +use crate::mail::mailbox::Mailbox; +use crate::mail::user::User; pub struct SelectedContext<'a> { pub req: &'a Request, - pub user: &'a flow::User, + pub user: &'a User, pub mailbox: &'a mut Mailbox, } diff --git a/src/imap/flow.rs b/src/imap/flow.rs index 7370bd1..369bee6 100644 --- a/src/imap/flow.rs +++ b/src/imap/flow.rs @@ -1,13 +1,9 @@ use std::error::Error as StdError; use std::fmt; -use crate::login::Credentials; -use crate::mail::Mailbox; +use crate::mail::mailbox::Mailbox; +use crate::mail::user::User; -pub struct User { - pub name: String, - pub creds: Credentials, -} #[derive(Debug)] pub enum Error { -- cgit v1.2.3