aboutsummaryrefslogtreecommitdiff
path: root/src/imap/command/anonymous.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2022-06-20 18:09:20 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2022-06-20 18:09:20 +0200
commitca4c2e7505f28acad688705d45cc5c5dca1799c3 (patch)
tree6820ad27dfdaa5e51e2f296832d75a4a9a6678ae /src/imap/command/anonymous.rs
parent5dd5ae8bcd6f88703bc483d7f8d5882fefad4e7e (diff)
downloadaerogramme-ca4c2e7505f28acad688705d45cc5c5dca1799c3.tar.gz
aerogramme-ca4c2e7505f28acad688705d45cc5c5dca1799c3.zip
WIP refactor
Diffstat (limited to 'src/imap/command/anonymous.rs')
-rw-r--r--src/imap/command/anonymous.rs23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/imap/command/anonymous.rs b/src/imap/command/anonymous.rs
index e4222f7..55e701b 100644
--- a/src/imap/command/anonymous.rs
+++ b/src/imap/command/anonymous.rs
@@ -1,23 +1,28 @@
-use boitalettres::proto::{Request, Response};
-use crate::login::ArcLoginProvider;
-use crate::imap::Context;
+use anyhow::{Result, Error};
+use boitalettres::proto::Response;
+use imap_codec::types::command::CommandBody;
+use imap_codec::types::core::AString;
+use imap_codec::types::response::{Capability, Data, Response as ImapRes, Status};
+
+use crate::imap::flow;
+use crate::imap::session::InnerContext;
//--- dispatching
-pub async fn dispatch(ctx: Context) -> Result<Response> {
+pub async fn dispatch<'a>(ctx: &'a InnerContext<'a>) -> Result<Response> {
match ctx.req.body {
- CommandBody::Capability => anonymous::capability(ctx).await,
- CommandBody::Login { username, password } => anonymous::login(ctx, username, password).await,
+ 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)])
.map_err(Error::msg),
}
}
-//--- Command controllers
+//--- Command controllers, private
-pub async fn capability(ctx: Context) -> Result<Response> {
+async fn capability<'a>(ctx: InnerContext<'a>) -> Result<Response> {
let capabilities = vec![Capability::Imap4Rev1, Capability::Idle];
let res = vec![
ImapRes::Data(Data::Capability(capabilities)),
@@ -29,7 +34,7 @@ pub async fn capability(ctx: Context) -> Result<Response> {
Ok(res)
}
-pub async fn login(ctx: Context, username: AString, password: AString) -> Result<Response> {
+async fn login<'a>(ctx: InnerContext<'a>, username: AString, password: AString) -> Result<Response> {
let (u, p) = (String::try_from(username)?, String::try_from(password)?);
tracing::info!(user = %u, "command.login");