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;
|
|
|
|
|
2022-06-30 09:28:03 +00:00
|
|
|
use crate::imap::command::examined;
|
2022-06-22 15:25:04 +00:00
|
|
|
use crate::imap::flow;
|
2022-06-29 13:39:54 +00:00
|
|
|
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>,
|
2022-06-29 13:39:54 +00:00
|
|
|
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-30 09:28:03 +00:00
|
|
|
// 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,
|
2022-06-30 09:28:03 +00:00
|
|
|
} => ctx.store(sequence_set, kind, response, flags, uid).await,
|
|
|
|
CommandBody::Copy {
|
2022-06-22 15:26:52 +00:00
|
|
|
sequence_set,
|
2022-06-30 09:28:03 +00:00
|
|
|
mailbox,
|
2022-06-22 15:26:52 +00:00
|
|
|
uid,
|
2022-06-30 09:28:03 +00:00
|
|
|
} => ctx.copy(sequence_set, mailbox, uid).await,
|
2022-06-29 10:50:44 +00:00
|
|
|
_ => {
|
2022-06-30 09:28:03 +00:00
|
|
|
let ctx = examined::ExaminedContext {
|
2022-06-29 10:50:44 +00:00
|
|
|
req: ctx.req,
|
|
|
|
user: ctx.user,
|
2022-06-30 09:28:03 +00:00
|
|
|
mailbox: ctx.mailbox,
|
2022-06-29 10:50:44 +00:00
|
|
|
};
|
2022-06-30 09:28:03 +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)> {
|
2022-06-30 09:28:03 +00:00
|
|
|
// 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)> {
|
2022-06-30 09:28:03 +00:00
|
|
|
Ok((Response::bad("Not implemented")?, flow::Transition::None))
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn store(
|
2022-06-29 10:50:44 +00:00
|
|
|
self,
|
2022-07-12 13:31:29 +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-06-30 09:28:03 +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
|
|
|
|
2022-06-30 09:28:03 +00:00
|
|
|
async fn copy(
|
|
|
|
self,
|
2022-07-12 13:31:29 +00:00
|
|
|
_sequence_set: &SequenceSet,
|
|
|
|
_mailbox: &MailboxCodec,
|
|
|
|
_uid: &bool,
|
2022-06-30 09:28:03 +00:00
|
|
|
) -> 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
|
|
|
}
|