diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2022-06-07 12:57:24 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2022-06-07 12:57:24 +0200 |
commit | c03be0a8c335c462bcc2f171145aef779a652736 (patch) | |
tree | 69a423fb52e6a384a94f03341db679425094687c /src/service.rs | |
parent | b82df13082869dc4d455e15c2955e20de0b55675 (diff) | |
download | aerogramme-c03be0a8c335c462bcc2f171145aef779a652736.tar.gz aerogramme-c03be0a8c335c462bcc2f171145aef779a652736.zip |
Implement a Mutex
Diffstat (limited to 'src/service.rs')
-rw-r--r-- | src/service.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/service.rs b/src/service.rs index 888a217..f032971 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::sync::{Arc, Mutex}; use std::task::{Context, Poll}; use anyhow::Result; @@ -10,6 +10,7 @@ use imap_codec::types::command::CommandBody; use tower::Service; use crate::command; +use crate::login::Credentials; use crate::mailstore::Mailstore; pub struct Instance { @@ -36,12 +37,17 @@ impl<'a> Service<&'a AddrStream> for Instance { } } +pub struct Session { + pub creds: Option<Credentials>, +} + pub struct Connection { pub mailstore: Arc<Mailstore>, + pub session: Arc<Mutex<Session>>, } impl Connection { pub fn new(mailstore: Arc<Mailstore>) -> Self { - Self { mailstore } + Self { mailstore, session: Arc::new(Mutex::new(Session { creds: None })) } } } impl Service<Request> for Connection { @@ -55,7 +61,7 @@ impl Service<Request> for Connection { fn call(&mut self, req: Request) -> Self::Future { tracing::debug!("Got request: {:#?}", req); - let cmd = command::Command::new(self.mailstore.clone()); + let cmd = command::Command::new(self.mailstore.clone(), self.session.clone()); Box::pin(async move { match req.body { CommandBody::Capability => cmd.capability().await, |