diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2022-06-28 09:34:24 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2022-06-28 09:34:24 +0200 |
commit | 927b461f25e8202a33fadc1f823d4feed6282f60 (patch) | |
tree | d40739209d2d6693c85e5888e0e3f14e4ccd1ce4 /src/imap/session.rs | |
parent | 390bad0ec451a571e119903054b581a9d9a00cbe (diff) | |
download | aerogramme-927b461f25e8202a33fadc1f823d4feed6282f60.tar.gz aerogramme-927b461f25e8202a33fadc1f823d4feed6282f60.zip |
Switching to upstream boitalettres
Diffstat (limited to 'src/imap/session.rs')
-rw-r--r-- | src/imap/session.rs | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/src/imap/session.rs b/src/imap/session.rs index 2ff4117..dfef0f4 100644 --- a/src/imap/session.rs +++ b/src/imap/session.rs @@ -40,7 +40,6 @@ impl Manager { pub fn process(&self, req: Request) -> BoxFuture<'static, Result<Response, BalError>> { let (tx, rx) = oneshot::channel(); - let tag = req.tag.clone(); let msg = Message { req, tx }; // We use try_send on a bounded channel to protect the daemons from DoS. @@ -51,17 +50,13 @@ impl Manager { Ok(()) => (), Err(TrySendError::Full(_)) => { return async { - Status::bad(Some(tag), None, "Too fast! Send less pipelined requests!") - .map(|s| vec![ImapRes::Status(s)]) - .map_err(|e| BalError::Text(e.to_string())) + Response::bad("Too fast! Send less pipelined requests.") } .boxed() } Err(TrySendError::Closed(_)) => { return async { - Status::bad(Some(tag), None, "The session task has exited") - .map(|s| vec![ImapRes::Status(s)]) - .map_err(|e| BalError::Text(e.to_string())) + Response::bad("Session task has existed.") } .boxed() } @@ -73,9 +68,7 @@ impl Manager { Ok(r) => r, Err(e) => { tracing::warn!("Got error {:#?}", e); - Status::bad(Some(tag), None, "No response from the session handler") - .map(|s| vec![ImapRes::Status(s)]) - .map_err(|e| BalError::Text(e.to_string())) + Response::bad("No response from the session handler") } } } @@ -122,21 +115,16 @@ impl Instance { }; // Command behavior is modulated by the state. - // To prevent state error, we handle the same command in separate code path depending - // on the State. + // To prevent state error, we handle the same command in separate code paths. 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), + _ => Response::bad("No commands are allowed in the LOGOUT state.") + .map(|r| (r, flow::Transition::No)) + .map_err(Error::msg), }; // Process result @@ -152,9 +140,7 @@ impl Instance { Ok(be) => Err(be), Err(e) => { tracing::warn!(error=%e, "internal.error"); - Status::bad(Some(msg.req.tag.clone()), None, "Internal error") - .map(|s| vec![ImapRes::Status(s)]) - .map_err(|e| BalError::Text(e.to_string())) + Response::bad("Internal error") } }, }; |