aboutsummaryrefslogtreecommitdiff
path: root/aero-proto/imap/command/anystate.rs
blob: 718ba3f7e15c97b679cae7f7d91b23f30bfae0a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use anyhow::Result;
use imap_codec::imap_types::core::Tag;
use imap_codec::imap_types::response::Data;

use crate::imap::capability::ServerCapability;
use crate::imap::flow;
use crate::imap::response::Response;

pub(crate) fn capability(
    tag: Tag<'static>,
    cap: &ServerCapability,
) -> Result<(Response<'static>, flow::Transition)> {
    let res = Response::build()
        .tag(tag)
        .message("Server capabilities")
        .data(Data::Capability(cap.to_vec()))
        .ok()?;

    Ok((res, flow::Transition::None))
}

pub(crate) fn noop_nothing(tag: Tag<'static>) -> Result<(Response<'static>, flow::Transition)> {
    Ok((
        Response::build().tag(tag).message("Noop completed.").ok()?,
        flow::Transition::None,
    ))
}

pub(crate) fn logout() -> Result<(Response<'static>, flow::Transition)> {
    Ok((Response::bye()?, flow::Transition::Logout))
}

pub(crate) fn not_implemented<'a>(
    tag: Tag<'a>,
    what: &str,
) -> Result<(Response<'a>, flow::Transition)> {
    Ok((
        Response::build()
            .tag(tag)
            .message(format!("Command not implemented {}", what))
            .bad()?,
        flow::Transition::None,
    ))
}

pub(crate) fn wrong_state(tag: Tag<'static>) -> Result<(Response<'static>, flow::Transition)> {
    Ok((
        Response::build()
            .tag(tag)
            .message("Command not authorized in this state")
            .bad()?,
        flow::Transition::None,
    ))
}