aerogramme/src/imap/command/selected.rs

96 lines
2.6 KiB
Rust
Raw Normal View History

2022-06-30 12:02:57 +00:00
use std::sync::Arc;
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-07-12 13:31:29 +00:00
2022-06-30 11:36:21 +00:00
use imap_codec::types::flag::{Flag, StoreResponse, StoreType};
use imap_codec::types::mailbox::Mailbox as MailboxCodec;
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::examined;
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-30 12:02:57 +00:00
pub user: &'a Arc<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 {
// Only write commands here, read commands are handled in
// `examined.rs`
CommandBody::Close => ctx.close().await,
CommandBody::Expunge => ctx.expunge().await,
CommandBody::Store {
2022-06-30 11:36:21 +00:00
sequence_set,
kind,
response,
flags,
uid,
} => ctx.store(sequence_set, kind, response, flags, uid).await,
CommandBody::Copy {
2022-06-22 15:26:52 +00:00
sequence_set,
mailbox,
2022-06-22 15:26:52 +00:00
uid,
} => ctx.copy(sequence_set, mailbox, uid).await,
2022-06-29 10:50:44 +00:00
_ => {
let ctx = examined::ExaminedContext {
2022-06-29 10:50:44 +00:00
req: ctx.req,
user: ctx.user,
mailbox: ctx.mailbox,
2022-06-29 10:50:44 +00:00
};
examined::dispatch(ctx).await
2022-06-29 10:50:44 +00:00
}
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-30 11:36:21 +00:00
async fn close(self) -> Result<(Response, flow::Transition)> {
// We expunge messages,
// but we don't send the untagged EXPUNGE responses
self.expunge().await?;
Ok((Response::ok("CLOSE completed")?, flow::Transition::Unselect))
}
2022-06-30 11:36:21 +00:00
async fn expunge(self) -> Result<(Response, flow::Transition)> {
Ok((Response::bad("Not implemented")?, flow::Transition::None))
}
async fn store(
2022-06-29 10:50:44 +00:00
self,
2022-07-12 15:32:57 +00:00
sequence_set: &SequenceSet,
kind: &StoreType,
response: &StoreResponse,
flags: &[Flag],
uid: &bool,
2022-06-22 15:26:52 +00:00
) -> Result<(Response, flow::Transition)> {
2022-07-12 15:32:57 +00:00
let data = self
.mailbox
.store(sequence_set, kind, response, flags, uid)
.await?;
Ok((
Response::ok("STORE completed")?.with_body(data),
flow::Transition::None,
))
2022-06-17 16:39:36 +00:00
}
2022-06-29 15:58:31 +00:00
async fn copy(
self,
2022-07-12 13:31:29 +00:00
_sequence_set: &SequenceSet,
_mailbox: &MailboxCodec,
_uid: &bool,
) -> Result<(Response, flow::Transition)> {
Ok((Response::bad("Not implemented")?, flow::Transition::None))
2022-06-29 15:58:31 +00:00
}
2022-06-20 16:09:20 +00:00
}