aboutsummaryrefslogtreecommitdiff
path: root/src/imap/command/selected.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-06-29 12:50:44 +0200
committerAlex Auvolat <alex@adnab.me>2022-06-29 12:50:44 +0200
commit90b143e1c57c6561998176878b2cc586b2d89c80 (patch)
treea9f07995d9d29e9f884756cad5732bfb2cbeb3fc /src/imap/command/selected.rs
parent9979671b001ccb25917da7091d13ad3fc1096330 (diff)
downloadaerogramme-90b143e1c57c6561998176878b2cc586b2d89c80.tar.gz
aerogramme-90b143e1c57c6561998176878b2cc586b2d89c80.zip
Refactor to allow mutability
Diffstat (limited to 'src/imap/command/selected.rs')
-rw-r--r--src/imap/command/selected.rs39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/imap/command/selected.rs b/src/imap/command/selected.rs
index cf0b71b..4e41561 100644
--- a/src/imap/command/selected.rs
+++ b/src/imap/command/selected.rs
@@ -1,4 +1,5 @@
use anyhow::{Error, Result};
+use boitalettres::proto::Request;
use boitalettres::proto::Response;
use imap_codec::types::command::CommandBody;
use imap_codec::types::core::Tag;
@@ -11,42 +12,38 @@ use crate::imap::flow;
use crate::imap::session::InnerContext;
use crate::mail::Mailbox;
-pub async fn dispatch<'a>(
- inner: InnerContext<'a>,
- user: &'a flow::User,
- mailbox: &'a Mailbox,
-) -> Result<(Response, flow::Transition)> {
- let ctx = StateContext {
- inner,
- user,
- mailbox,
- };
+pub struct SelectedContext<'a> {
+ pub req: &'a Request,
+ pub user: &'a flow::User,
+ pub mailbox: &'a mut Mailbox,
+}
- match &ctx.inner.req.command.body {
+pub async fn dispatch<'a>(ctx: SelectedContext<'a>) -> Result<(Response, flow::Transition)> {
+ match &ctx.req.command.body {
CommandBody::Fetch {
sequence_set,
attributes,
uid,
} => ctx.fetch(sequence_set, attributes, uid).await,
- _ => authenticated::dispatch(ctx.inner, user).await,
+ _ => {
+ let ctx = authenticated::AuthenticatedContext {
+ req: ctx.req,
+ user: ctx.user,
+ };
+ authenticated::dispatch(ctx).await
+ }
}
}
// --- PRIVATE ---
-struct StateContext<'a> {
- inner: InnerContext<'a>,
- user: &'a flow::User,
- mailbox: &'a Mailbox,
-}
-
-impl<'a> StateContext<'a> {
+impl<'a> SelectedContext<'a> {
pub async fn fetch(
- &self,
+ self,
sequence_set: &SequenceSet,
attributes: &MacroOrFetchAttributes,
uid: &bool,
) -> Result<(Response, flow::Transition)> {
- Ok((Response::bad("Not implemented")?, flow::Transition::No))
+ Ok((Response::bad("Not implemented")?, flow::Transition::None))
}
}