Refactor selected
This commit is contained in:
parent
50b1972987
commit
ac974184de
4 changed files with 27 additions and 29 deletions
|
@ -13,7 +13,7 @@ use crate::imap::session::InnerContext;
|
||||||
pub async fn dispatch<'a>(ctx: InnerContext<'a>) -> Result<(Response, flow::Transition)> {
|
pub async fn dispatch<'a>(ctx: InnerContext<'a>) -> Result<(Response, flow::Transition)> {
|
||||||
match &ctx.req.body {
|
match &ctx.req.body {
|
||||||
CommandBody::Capability => capability(ctx).await,
|
CommandBody::Capability => capability(ctx).await,
|
||||||
CommandBody::Login { username, password } => login(ctx, username.clone(), password.clone()).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.")
|
_ => 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(|s| (vec![ImapRes::Status(s)], flow::Transition::No))
|
||||||
.map_err(Error::msg),
|
.map_err(Error::msg),
|
||||||
|
@ -34,8 +34,8 @@ async fn capability<'a>(ctx: InnerContext<'a>) -> Result<(Response, flow::Transi
|
||||||
Ok((res, flow::Transition::No))
|
Ok((res, flow::Transition::No))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn login<'a>(ctx: InnerContext<'a>, username: AString, password: AString) -> Result<(Response, flow::Transition)> {
|
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)?);
|
let (u, p) = (String::try_from(username.clone())?, String::try_from(password.clone())?);
|
||||||
tracing::info!(user = %u, "command.login");
|
tracing::info!(user = %u, "command.login");
|
||||||
|
|
||||||
let creds = match ctx.login.login(&u, &p).await {
|
let creds = match ctx.login.login(&u, &p).await {
|
||||||
|
|
|
@ -15,9 +15,9 @@ pub async fn dispatch<'a>(inner: InnerContext<'a>, user: &'a flow::User) -> Resu
|
||||||
let ctx = StateContext { user, tag: &inner.req.tag, inner };
|
let ctx = StateContext { user, tag: &inner.req.tag, inner };
|
||||||
|
|
||||||
match &ctx.inner.req.body {
|
match &ctx.inner.req.body {
|
||||||
CommandBody::Lsub { reference, mailbox_wildcard, } => ctx.lsub(reference.clone(), mailbox_wildcard.clone()).await,
|
CommandBody::Lsub { reference, mailbox_wildcard, } => ctx.lsub(reference, mailbox_wildcard).await,
|
||||||
CommandBody::List { reference, mailbox_wildcard, } => ctx.list(reference.clone(), mailbox_wildcard.clone()).await,
|
CommandBody::List { reference, mailbox_wildcard, } => ctx.list(reference, mailbox_wildcard).await,
|
||||||
CommandBody::Select { mailbox } => ctx.select(mailbox.clone()).await,
|
CommandBody::Select { mailbox } => ctx.select(mailbox).await,
|
||||||
_ => anonymous::dispatch(ctx.inner).await,
|
_ => anonymous::dispatch(ctx.inner).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,8 @@ struct StateContext<'a> {
|
||||||
impl<'a> StateContext<'a> {
|
impl<'a> StateContext<'a> {
|
||||||
async fn lsub(
|
async fn lsub(
|
||||||
&self,
|
&self,
|
||||||
reference: MailboxCodec,
|
reference: &MailboxCodec,
|
||||||
mailbox_wildcard: ListMailbox,
|
mailbox_wildcard: &ListMailbox,
|
||||||
) -> Result<(Response, flow::Transition)> {
|
) -> Result<(Response, flow::Transition)> {
|
||||||
Ok((vec![ImapRes::Status(
|
Ok((vec![ImapRes::Status(
|
||||||
Status::bad(Some(self.tag.clone()), None, "Not implemented").map_err(Error::msg)?,
|
Status::bad(Some(self.tag.clone()), None, "Not implemented").map_err(Error::msg)?,
|
||||||
|
@ -44,8 +44,8 @@ impl<'a> StateContext<'a> {
|
||||||
|
|
||||||
async fn list(
|
async fn list(
|
||||||
&self,
|
&self,
|
||||||
reference: MailboxCodec,
|
reference: &MailboxCodec,
|
||||||
mailbox_wildcard: ListMailbox,
|
mailbox_wildcard: &ListMailbox,
|
||||||
) -> Result<(Response, flow::Transition)> {
|
) -> Result<(Response, flow::Transition)> {
|
||||||
Ok((vec![
|
Ok((vec![
|
||||||
ImapRes::Status(Status::bad(Some(self.tag.clone()), None, "Not implemented").map_err(Error::msg)?),
|
ImapRes::Status(Status::bad(Some(self.tag.clone()), None, "Not implemented").map_err(Error::msg)?),
|
||||||
|
@ -68,8 +68,8 @@ impl<'a> StateContext<'a> {
|
||||||
|
|
||||||
* TRACE END ---
|
* TRACE END ---
|
||||||
*/
|
*/
|
||||||
async fn select(&self, mailbox: MailboxCodec) -> Result<(Response, flow::Transition)> {
|
async fn select(&self, mailbox: &MailboxCodec) -> Result<(Response, flow::Transition)> {
|
||||||
let name = String::try_from(mailbox)?;
|
let name = String::try_from(mailbox.clone())?;
|
||||||
|
|
||||||
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");
|
tracing::info!(username=%self.user.name, mailbox=%name, "mailbox.selected");
|
||||||
|
|
|
@ -9,26 +9,25 @@ use imap_codec::types::sequence::SequenceSet;
|
||||||
|
|
||||||
use crate::imap::command::authenticated;
|
use crate::imap::command::authenticated;
|
||||||
use crate::imap::session::InnerContext;
|
use crate::imap::session::InnerContext;
|
||||||
use crate::imap::flow::User;
|
use crate::imap::flow;
|
||||||
use crate::mailbox::Mailbox;
|
use crate::mailbox::Mailbox;
|
||||||
|
|
||||||
/*
|
|
||||||
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 {
|
pub async fn dispatch<'a>(inner: InnerContext<'a>, user: &'a flow::User, mailbox: &'a Mailbox) -> Result<(Response, flow::Transition)> {
|
||||||
|
let ctx = StateContext { tag: &inner.req.tag, inner, user, mailbox };
|
||||||
|
|
||||||
|
match &ctx.inner.req.body {
|
||||||
CommandBody::Fetch { sequence_set, attributes, uid, } => ctx.fetch(sequence_set, attributes, uid).await,
|
CommandBody::Fetch { sequence_set, attributes, uid, } => ctx.fetch(sequence_set, attributes, uid).await,
|
||||||
_ => authenticated::dispatch(inner, user).await,
|
_ => authenticated::dispatch(ctx.inner, user).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// --- PRIVATE ---
|
// --- PRIVATE ---
|
||||||
|
|
||||||
/*
|
|
||||||
struct StateContext<'a> {
|
struct StateContext<'a> {
|
||||||
inner: InnerContext<'a>,
|
inner: InnerContext<'a>,
|
||||||
user: &'a User,
|
user: &'a flow::User,
|
||||||
mailbox: &'a Mailbox,
|
mailbox: &'a Mailbox,
|
||||||
tag: &'a Tag,
|
tag: &'a Tag,
|
||||||
}
|
}
|
||||||
|
@ -37,13 +36,12 @@ struct StateContext<'a> {
|
||||||
impl<'a> StateContext<'a> {
|
impl<'a> StateContext<'a> {
|
||||||
pub async fn fetch(
|
pub async fn fetch(
|
||||||
&self,
|
&self,
|
||||||
sequence_set: SequenceSet,
|
sequence_set: &SequenceSet,
|
||||||
attributes: MacroOrFetchAttributes,
|
attributes: &MacroOrFetchAttributes,
|
||||||
uid: bool,
|
uid: &bool,
|
||||||
) -> Result<Response> {
|
) -> Result<(Response, flow::Transition)> {
|
||||||
Ok(vec![
|
Ok((vec![
|
||||||
ImapRes::Status(Status::bad(Some(self.tag.clone()), None, "Not implemented").map_err(Error::msg)?),
|
ImapRes::Status(Status::bad(Some(self.tag.clone()), None, "Not implemented").map_err(Error::msg)?),
|
||||||
])
|
], flow::Transition::No))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ impl Instance {
|
||||||
let ctrl = match &self.state {
|
let ctrl = match &self.state {
|
||||||
flow::State::NotAuthenticated => anonymous::dispatch(ctx).await,
|
flow::State::NotAuthenticated => anonymous::dispatch(ctx).await,
|
||||||
flow::State::Authenticated(user) => authenticated::dispatch(ctx, user).await,
|
flow::State::Authenticated(user) => authenticated::dispatch(ctx, user).await,
|
||||||
/*flow::State::Selected(user, mailbox) => selected::dispatch(ctx, user, mailbox).await,*/
|
flow::State::Selected(user, mailbox) => selected::dispatch(ctx, user, mailbox).await,
|
||||||
_ => Status::bad(Some(ctx.req.tag.clone()), None, "No commands are allowed in the LOGOUT state.")
|
_ => Status::bad(Some(ctx.req.tag.clone()), None, "No commands are allowed in the LOGOUT state.")
|
||||||
.map(|s| (vec![ImapRes::Status(s)], flow::Transition::No))
|
.map(|s| (vec![ImapRes::Status(s)], flow::Transition::No))
|
||||||
.map_err(Error::msg),
|
.map_err(Error::msg),
|
||||||
|
|
Loading…
Reference in a new issue