aboutsummaryrefslogtreecommitdiff
path: root/src/imap/command/anonymous.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2022-06-28 09:34:24 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2022-06-28 09:34:24 +0200
commit927b461f25e8202a33fadc1f823d4feed6282f60 (patch)
treed40739209d2d6693c85e5888e0e3f14e4ccd1ce4 /src/imap/command/anonymous.rs
parent390bad0ec451a571e119903054b581a9d9a00cbe (diff)
downloadaerogramme-927b461f25e8202a33fadc1f823d4feed6282f60.tar.gz
aerogramme-927b461f25e8202a33fadc1f823d4feed6282f60.zip
Switching to upstream boitalettres
Diffstat (limited to 'src/imap/command/anonymous.rs')
-rw-r--r--src/imap/command/anonymous.rs39
1 files changed, 9 insertions, 30 deletions
diff --git a/src/imap/command/anonymous.rs b/src/imap/command/anonymous.rs
index c1b800e..a2f2260 100644
--- a/src/imap/command/anonymous.rs
+++ b/src/imap/command/anonymous.rs
@@ -10,16 +10,13 @@ use crate::imap::session::InnerContext;
//--- dispatching
pub async fn dispatch<'a>(ctx: InnerContext<'a>) -> Result<(Response, flow::Transition)> {
- match &ctx.req.body {
+ match &ctx.req.command.body {
CommandBody::Capability => capability(ctx).await,
CommandBody::Login { username, password } => login(ctx, username, password).await,
- _ => Status::no(
- Some(ctx.req.tag.clone()),
- None,
- "This command is not available in the ANONYMOUS state.",
- )
- .map(|s| (vec![ImapRes::Status(s)], flow::Transition::No))
- .map_err(Error::msg),
+ _ => Ok((
+ Response::no("This command is not available in the ANONYMOUS state.")?,
+ flow::Transition::No
+ )),
}
}
@@ -27,13 +24,7 @@ pub async fn dispatch<'a>(ctx: InnerContext<'a>) -> Result<(Response, flow::Tran
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)),
- ImapRes::Status(
- Status::ok(Some(ctx.req.tag.clone()), None, "Server capabilities")
- .map_err(Error::msg)?,
- ),
- ];
+ let res = Response::ok("Server capabilities")?.with_body(Data::Capability(capabilities));
Ok((res, flow::Transition::No))
}
@@ -51,13 +42,7 @@ async fn login<'a>(
let creds = match ctx.login.login(&u, &p).await {
Err(e) => {
tracing::debug!(error=%e, "authentication failed");
- return Ok((
- vec![ImapRes::Status(
- Status::no(Some(ctx.req.tag.clone()), None, "Authentication failed")
- .map_err(Error::msg)?,
- )],
- flow::Transition::No,
- ));
+ return Ok((Response::no("Authentication failed")?, flow::Transition::No));
}
Ok(c) => c,
};
@@ -66,16 +51,10 @@ async fn login<'a>(
creds,
name: u.clone(),
};
- let tr = flow::Transition::Authenticate(user);
tracing::info!(username=%u, "connected");
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,
+ Response::ok("Completed")?,
+ flow::Transition::Authenticate(user)
))
}