aerogramme/src/imap/command/selected.rs

60 lines
1.6 KiB
Rust
Raw Normal View History

2022-06-29 11:41:05 +00:00
use anyhow::Result;
2022-06-29 10:50:44 +00:00
use boitalettres::proto::Request;
2022-06-20 16:09:20 +00:00
use boitalettres::proto::Response;
use imap_codec::types::command::CommandBody;
2022-06-29 10:52:58 +00:00
2022-06-20 16:09:20 +00:00
use imap_codec::types::fetch_attributes::MacroOrFetchAttributes;
2022-06-29 10:52:58 +00:00
2022-06-20 16:09:20 +00:00
use imap_codec::types::sequence::SequenceSet;
use crate::imap::command::authenticated;
2022-06-22 15:25:04 +00:00
use crate::imap::flow;
use crate::imap::mailbox_view::MailboxView;
2022-06-29 10:52:58 +00:00
2022-06-29 11:16:58 +00:00
use crate::mail::user::User;
2022-06-20 16:09:20 +00:00
2022-06-29 10:50:44 +00:00
pub struct SelectedContext<'a> {
pub req: &'a Request,
2022-06-29 11:16:58 +00:00
pub user: &'a User,
pub mailbox: &'a mut MailboxView,
2022-06-29 10:50:44 +00:00
}
2022-06-22 15:25:04 +00:00
2022-06-29 10:50:44 +00:00
pub async fn dispatch<'a>(ctx: SelectedContext<'a>) -> Result<(Response, flow::Transition)> {
match &ctx.req.command.body {
2022-06-29 15:58:31 +00:00
CommandBody::Noop => ctx.noop().await,
2022-06-22 15:26:52 +00:00
CommandBody::Fetch {
sequence_set,
attributes,
uid,
} => ctx.fetch(sequence_set, attributes, uid).await,
2022-06-29 10:50:44 +00:00
_ => {
let ctx = authenticated::AuthenticatedContext {
req: ctx.req,
user: ctx.user,
};
authenticated::dispatch(ctx).await
}
2022-06-20 16:09:20 +00:00
}
}
2022-06-22 15:25:04 +00:00
2022-06-20 16:09:20 +00:00
// --- PRIVATE ---
2022-06-29 10:50:44 +00:00
impl<'a> SelectedContext<'a> {
2022-06-17 16:39:36 +00:00
pub async fn fetch(
2022-06-29 10:50:44 +00:00
self,
2022-06-29 10:52:58 +00:00
_sequence_set: &SequenceSet,
_attributes: &MacroOrFetchAttributes,
_uid: &bool,
2022-06-22 15:26:52 +00:00
) -> Result<(Response, flow::Transition)> {
2022-06-29 10:50:44 +00:00
Ok((Response::bad("Not implemented")?, flow::Transition::None))
2022-06-17 16:39:36 +00:00
}
2022-06-29 15:58:31 +00:00
pub async fn noop(self) -> Result<(Response, flow::Transition)> {
let updates = self.mailbox.update().await?;
Ok((
Response::ok("Noop completed.")?.with_body(updates),
flow::Transition::None,
))
}
2022-06-20 16:09:20 +00:00
}