2024-01-01 18:25:28 +00:00
|
|
|
use anyhow::Result;
|
2024-01-03 11:29:19 +00:00
|
|
|
use imap_codec::imap_types::core::Tag;
|
|
|
|
use imap_codec::imap_types::response::Data;
|
2024-01-01 18:25:28 +00:00
|
|
|
|
2024-01-03 11:29:19 +00:00
|
|
|
use crate::imap::capability::ServerCapability;
|
2024-01-03 14:00:05 +00:00
|
|
|
use crate::imap::flow;
|
2024-01-01 18:25:28 +00:00
|
|
|
use crate::imap::response::Response;
|
|
|
|
|
2024-01-03 14:00:05 +00:00
|
|
|
pub(crate) fn capability(
|
|
|
|
tag: Tag<'static>,
|
|
|
|
cap: &ServerCapability,
|
|
|
|
) -> Result<(Response<'static>, flow::Transition)> {
|
2024-01-02 14:35:23 +00:00
|
|
|
let res = Response::build()
|
2024-01-01 18:25:28 +00:00
|
|
|
.tag(tag)
|
|
|
|
.message("Server capabilities")
|
2024-01-03 11:29:19 +00:00
|
|
|
.data(Data::Capability(cap.to_vec()))
|
2024-01-02 14:35:23 +00:00
|
|
|
.ok()?;
|
2024-01-01 18:25:28 +00:00
|
|
|
|
|
|
|
Ok((res, flow::Transition::None))
|
|
|
|
}
|
|
|
|
|
2024-01-02 19:23:33 +00:00
|
|
|
pub(crate) fn noop_nothing(tag: Tag<'static>) -> Result<(Response<'static>, flow::Transition)> {
|
2024-01-01 18:25:28 +00:00
|
|
|
Ok((
|
2024-01-02 14:35:23 +00:00
|
|
|
Response::build().tag(tag).message("Noop completed.").ok()?,
|
2024-01-01 18:25:28 +00:00
|
|
|
flow::Transition::None,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
2024-01-02 14:35:23 +00:00
|
|
|
pub(crate) fn logout() -> Result<(Response<'static>, flow::Transition)> {
|
2024-01-01 18:25:28 +00:00
|
|
|
Ok((Response::bye()?, flow::Transition::Logout))
|
|
|
|
}
|
|
|
|
|
2024-01-02 14:35:23 +00:00
|
|
|
pub(crate) fn not_implemented<'a>(
|
|
|
|
tag: Tag<'a>,
|
|
|
|
what: &str,
|
|
|
|
) -> Result<(Response<'a>, flow::Transition)> {
|
2024-01-01 18:25:28 +00:00
|
|
|
Ok((
|
2024-01-02 14:35:23 +00:00
|
|
|
Response::build()
|
2024-01-01 18:25:28 +00:00
|
|
|
.tag(tag)
|
|
|
|
.message(format!("Command not implemented {}", what))
|
2024-01-02 14:35:23 +00:00
|
|
|
.bad()?,
|
2024-01-01 18:25:28 +00:00
|
|
|
flow::Transition::None,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
2024-01-02 19:23:33 +00:00
|
|
|
pub(crate) fn wrong_state(tag: Tag<'static>) -> Result<(Response<'static>, flow::Transition)> {
|
2024-01-01 18:25:28 +00:00
|
|
|
Ok((
|
2024-01-02 14:35:23 +00:00
|
|
|
Response::build()
|
2024-01-01 18:25:28 +00:00
|
|
|
.tag(tag)
|
|
|
|
.message("Command not authorized in this state")
|
2024-01-02 14:35:23 +00:00
|
|
|
.bad()?,
|
2024-01-01 18:25:28 +00:00
|
|
|
flow::Transition::None,
|
|
|
|
))
|
|
|
|
}
|