aerogramme/src/imap/command/selected.rs

90 lines
2.5 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;
use imap_codec::types::mailbox::{Mailbox as MailboxCodec};
use imap_codec::types::flag::{Flag, StoreType, StoreResponse};
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::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-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 {
// Only write commands here, read commands are handled in
// `examined.rs`
CommandBody::Close => ctx.close().await,
CommandBody::Expunge => ctx.expunge().await,
CommandBody::Store {
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> {
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))
}
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-06-29 17:24:21 +00:00
sequence_set: &SequenceSet,
kind: &StoreType,
response: &StoreResponse,
flags: &[Flag],
2022-06-29 17:24:21 +00:00
uid: &bool,
2022-06-22 15:26:52 +00:00
) -> Result<(Response, flow::Transition)> {
Ok((Response::bad("Not implemented")?, flow::Transition::None))
2022-06-17 16:39:36 +00:00
}
2022-06-29 15:58:31 +00:00
async fn copy(
self,
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
}