aboutsummaryrefslogtreecommitdiff
path: root/src/imap/session.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2022-06-22 17:26:52 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2022-06-22 17:26:52 +0200
commitcea27474f9dfed289be4e7be017913d7165342f3 (patch)
tree6e971a12acfe82a2dca9d39d2cd36bafe3e59c6d /src/imap/session.rs
parentac974184def76fefba6c36c5c9e0ff0298f860ff (diff)
downloadaerogramme-cea27474f9dfed289be4e7be017913d7165342f3.tar.gz
aerogramme-cea27474f9dfed289be4e7be017913d7165342f3.zip
cargo fmt
Diffstat (limited to 'src/imap/session.rs')
-rw-r--r--src/imap/session.rs39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/imap/session.rs b/src/imap/session.rs
index a500e2b..2ff4117 100644
--- a/src/imap/session.rs
+++ b/src/imap/session.rs
@@ -7,7 +7,7 @@ use imap_codec::types::response::{Response as ImapRes, Status};
use tokio::sync::mpsc::error::TrySendError;
use tokio::sync::{mpsc, oneshot};
-use crate::imap::command::{anonymous,authenticated,selected};
+use crate::imap::command::{anonymous, authenticated, selected};
use crate::imap::flow;
use crate::login::ArcLoginProvider;
@@ -98,10 +98,7 @@ pub struct Instance {
pub state: flow::State,
}
impl Instance {
- fn new(
- login_provider: ArcLoginProvider,
- rx: mpsc::Receiver<Message>,
- ) -> Self {
+ fn new(login_provider: ArcLoginProvider, rx: mpsc::Receiver<Message>) -> Self {
Self {
login_provider,
rx,
@@ -118,7 +115,11 @@ impl Instance {
tracing::debug!("starting runner");
while let Some(msg) = self.rx.recv().await {
- let ctx = InnerContext { req: &msg.req, state: &self.state, login: &self.login_provider };
+ let ctx = InnerContext {
+ req: &msg.req,
+ state: &self.state,
+ login: &self.login_provider,
+ };
// Command behavior is modulated by the state.
// To prevent state error, we handle the same command in separate code path depending
@@ -126,10 +127,16 @@ impl Instance {
let ctrl = match &self.state {
flow::State::NotAuthenticated => anonymous::dispatch(ctx).await,
flow::State::Authenticated(user) => authenticated::dispatch(ctx, user).await,
- flow::State::Selected(user, mailbox) => selected::dispatch(ctx, user, mailbox).await,
- _ => Status::bad(Some(ctx.req.tag.clone()), None, "No commands are allowed in the LOGOUT state.")
- .map(|s| (vec![ImapRes::Status(s)], flow::Transition::No))
- .map_err(Error::msg),
+ flow::State::Selected(user, mailbox) => {
+ selected::dispatch(ctx, user, mailbox).await
+ }
+ _ => Status::bad(
+ Some(ctx.req.tag.clone()),
+ None,
+ "No commands are allowed in the LOGOUT state.",
+ )
+ .map(|s| (vec![ImapRes::Status(s)], flow::Transition::No))
+ .map_err(Error::msg),
};
// Process result
@@ -138,7 +145,7 @@ impl Instance {
//@FIXME unwrap
self.state = self.state.apply(tr).unwrap();
Ok(res)
- },
+ }
// Cast from anyhow::Error to Bal::Error
// @FIXME proper error handling would be great
Err(e) => match e.downcast::<BalError>() {
@@ -149,7 +156,7 @@ impl Instance {
.map(|s| vec![ImapRes::Status(s)])
.map_err(|e| BalError::Text(e.to_string()))
}
- }
+ },
};
//@FIXME I think we should quit this thread on error and having our manager watch it,
@@ -157,9 +164,9 @@ impl Instance {
msg.tx.send(res).unwrap_or_else(|e| {
tracing::warn!("failed to send imap response to manager: {:#?}", e)
});
- }
+ }
- //@FIXME add more info about the runner
- tracing::debug!("exiting runner");
-}
+ //@FIXME add more info about the runner
+ tracing::debug!("exiting runner");
+ }
}