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.rs52
1 files changed, 34 insertions, 18 deletions
diff --git a/src/imap/command/anonymous.rs b/src/imap/command/anonymous.rs
index 7a5e514..c1b800e 100644
--- a/src/imap/command/anonymous.rs
+++ b/src/imap/command/anonymous.rs
@@ -1,5 +1,4 @@
-
-use anyhow::{Result, Error};
+use anyhow::{Error, Result};
use boitalettres::proto::Response;
use imap_codec::types::command::CommandBody;
use imap_codec::types::core::AString;
@@ -14,9 +13,13 @@ pub async fn dispatch<'a>(ctx: InnerContext<'a>) -> Result<(Response, flow::Tran
match &ctx.req.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),
+ _ => 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),
}
}
@@ -28,23 +31,33 @@ async fn capability<'a>(ctx: InnerContext<'a>) -> Result<(Response, flow::Transi
ImapRes::Data(Data::Capability(capabilities)),
ImapRes::Status(
Status::ok(Some(ctx.req.tag.clone()), None, "Server capabilities")
- .map_err(Error::msg)?,
- ),
+ .map_err(Error::msg)?,
+ ),
];
Ok((res, flow::Transition::No))
}
-async fn login<'a>(ctx: InnerContext<'a>, username: &AString, password: &AString) -> Result<(Response, flow::Transition)> {
- let (u, p) = (String::try_from(username.clone())?, String::try_from(password.clone())?);
+async fn login<'a>(
+ ctx: InnerContext<'a>,
+ username: &AString,
+ password: &AString,
+) -> Result<(Response, flow::Transition)> {
+ let (u, p) = (
+ String::try_from(username.clone())?,
+ String::try_from(password.clone())?,
+ );
tracing::info!(user = %u, "command.login");
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));
+ .map_err(Error::msg)?,
+ )],
+ flow::Transition::No,
+ ));
}
Ok(c) => c,
};
@@ -56,10 +69,13 @@ async fn login<'a>(ctx: InnerContext<'a>, username: &AString, password: &AString
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))
+ 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,
+ ))
}