aboutsummaryrefslogtreecommitdiff
path: root/src/imap/command
diff options
context:
space:
mode:
Diffstat (limited to 'src/imap/command')
-rw-r--r--src/imap/command/anonymous.rs26
-rw-r--r--src/imap/command/authenticated.rs20
-rw-r--r--src/imap/command/selected.rs6
3 files changed, 29 insertions, 23 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))
}
diff --git a/src/imap/command/authenticated.rs b/src/imap/command/authenticated.rs
index 49bfa9c..093521a 100644
--- a/src/imap/command/authenticated.rs
+++ b/src/imap/command/authenticated.rs
@@ -11,21 +11,22 @@ use crate::imap::session::InnerContext;
use crate::imap::flow::User;
use crate::mailbox::Mailbox;
-pub async fn dispatch<'a>(inner: &'a InnerContext<'a>, user: &'a User) -> Result<Response> {
+/*pub async fn dispatch<'a>(inner: &'a mut InnerContext<'a>, user: &'a User) -> Result<Response> {
let ctx = StateContext { inner, user, tag: &inner.req.tag };
- match ctx.req.body.as_ref() {
- CommandBody::Lsub { reference, mailbox_wildcard, } => ctx.lsub(reference, mailbox_wildcard).await,
- CommandBody::List { reference, mailbox_wildcard, } => ctx.list(reference, mailbox_wildcard).await,
- CommandBody::Select { mailbox } => ctx.select(mailbox).await,
+ match &ctx.inner.req.body {
+ CommandBody::Lsub { reference, mailbox_wildcard, } => ctx.lsub(reference.clone(), mailbox_wildcard.clone()).await,
+ CommandBody::List { reference, mailbox_wildcard, } => ctx.list(reference.clone(), mailbox_wildcard.clone()).await,
+ CommandBody::Select { mailbox } => ctx.select(mailbox.clone()).await,
_ => anonymous::dispatch(ctx.inner).await,
}
-}
+}*/
// --- PRIVATE ---
+/*
struct StateContext<'a> {
- inner: InnerContext<'a>,
+ inner: &'a mut InnerContext<'a>,
user: &'a User,
tag: &'a Tag,
}
@@ -70,7 +71,7 @@ impl<'a> StateContext<'a> {
async fn select(&self, mailbox: MailboxCodec) -> Result<Response> {
let name = String::try_from(mailbox)?;
- let mut mb = Mailbox::new(self.user.creds, name.clone())?;
+ let mut mb = Mailbox::new(&self.user.creds, name.clone())?;
tracing::info!(username=%self.user.name, mailbox=%name, "mailbox.selected");
let sum = mb.summary().await?;
@@ -80,7 +81,7 @@ impl<'a> StateContext<'a> {
self.inner.state.select(mb)?;
- let r_unseen = Status::ok(None, Some(Code::Unseen(0)), "").map_err(Error::msg)?;
+ let r_unseen = Status::ok(None, Some(Code::Unseen(std::num::NonZeroU32::new(1)?)), "").map_err(Error::msg)?;
//let r_permanentflags = Status::ok(None, Some(Code::
Ok(vec![
@@ -99,3 +100,4 @@ impl<'a> StateContext<'a> {
])
}
}
+*/
diff --git a/src/imap/command/selected.rs b/src/imap/command/selected.rs
index 61e9c1a..93592c1 100644
--- a/src/imap/command/selected.rs
+++ b/src/imap/command/selected.rs
@@ -12,7 +12,8 @@ use crate::imap::session::InnerContext;
use crate::imap::flow::User;
use crate::mailbox::Mailbox;
-pub async fn dispatch<'a>(inner: &'a InnerContext<'a>, user: &'a User, mailbox: &'a Mailbox) -> Result<Response> {
+/*
+pub async fn dispatch<'a>(inner: InnerContext<'a>, user: &'a User, mailbox: &'a Mailbox) -> Result<Response> {
let ctx = StateContext { inner, user, mailbox, tag: &inner.req.tag };
match ctx.inner.req.body {
@@ -20,9 +21,11 @@ pub async fn dispatch<'a>(inner: &'a InnerContext<'a>, user: &'a User, mailbox:
_ => authenticated::dispatch(inner, user).await,
}
}
+*/
// --- PRIVATE ---
+/*
struct StateContext<'a> {
inner: InnerContext<'a>,
user: &'a User,
@@ -43,3 +46,4 @@ impl<'a> StateContext<'a> {
])
}
}
+*/