aboutsummaryrefslogtreecommitdiff
path: root/src/imap/command/anonymous.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/imap/command/anonymous.rs')
-rw-r--r--src/imap/command/anonymous.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/imap/command/anonymous.rs b/src/imap/command/anonymous.rs
index 55e701b..c6af354 100644
--- a/src/imap/command/anonymous.rs
+++ b/src/imap/command/anonymous.rs
@@ -10,19 +10,19 @@ use crate::imap::session::InnerContext;
//--- dispatching
-pub async fn dispatch<'a>(ctx: &'a InnerContext<'a>) -> Result<Response> {
- match ctx.req.body {
+pub async fn dispatch<'a>(ctx: InnerContext<'a>) -> Result<(Response, flow::Transition)> {
+ match &ctx.req.body {
CommandBody::Capability => capability(ctx).await,
- CommandBody::Login { username, password } => login(ctx, username, password).await,
+ CommandBody::Login { username, password } => login(ctx, username.clone(), password.clone()).await,
_ => Status::no(Some(ctx.req.tag.clone()), None, "This command is not available in the ANONYMOUS state.")
- .map(|s| vec![ImapRes::Status(s)])
+ .map(|s| (vec![ImapRes::Status(s)], flow::Transition::No))
.map_err(Error::msg),
}
}
//--- Command controllers, private
-async fn capability<'a>(ctx: InnerContext<'a>) -> Result<Response> {
+async fn capability<'a>(ctx: InnerContext<'a>) -> Result<(Response, flow::Transition)> {
let capabilities = vec![Capability::Imap4Rev1, Capability::Idle];
let res = vec![
ImapRes::Data(Data::Capability(capabilities)),
@@ -31,20 +31,20 @@ async fn capability<'a>(ctx: InnerContext<'a>) -> Result<Response> {
.map_err(Error::msg)?,
),
];
- Ok(res)
+ Ok((res, flow::Transition::No))
}
-async fn login<'a>(ctx: InnerContext<'a>, username: AString, password: AString) -> Result<Response> {
+async fn login<'a>(ctx: InnerContext<'a>, username: AString, password: AString) -> Result<(Response, flow::Transition)> {
let (u, p) = (String::try_from(username)?, String::try_from(password)?);
tracing::info!(user = %u, "command.login");
- let creds = match ctx.login_provider.login(&u, &p).await {
+ let creds = match ctx.login.login(&u, &p).await {
Err(e) => {
tracing::debug!(error=%e, "authentication failed");
- return Ok(vec![ImapRes::Status(
+ return Ok((vec![ImapRes::Status(
Status::no(Some(ctx.req.tag.clone()), None, "Authentication failed")
.map_err(Error::msg)?,
- )]);
+ )], flow::Transition::No));
}
Ok(c) => c,
};
@@ -53,13 +53,13 @@ async fn login<'a>(ctx: InnerContext<'a>, username: AString, password: AString)
creds,
name: u.clone(),
};
- ctx.state.authenticate(user)?;
+ let tr = flow::Transition::Authenticate(user);
tracing::info!(username=%u, "connected");
- Ok(vec![
+ Ok((vec![
//@FIXME we could send a capability status here too
ImapRes::Status(
Status::ok(Some(ctx.req.tag.clone()), None, "completed").map_err(Error::msg)?,
),
- ])
+ ], tr))
}