Implement logout

This commit is contained in:
Quentin 2022-06-28 15:38:06 +02:00
parent 36bbc2138b
commit 06b888d969
Signed by: quentin
GPG key ID: E9602264D639FF68
3 changed files with 22 additions and 5 deletions

View file

@ -1,8 +1,8 @@
use anyhow::{Error, Result}; use anyhow::{Error, Result};
use boitalettres::proto::Response; use boitalettres::proto::{res::body::Data as Body, Response};
use imap_codec::types::command::CommandBody; use imap_codec::types::command::CommandBody;
use imap_codec::types::core::AString; use imap_codec::types::core::{AString, Atom};
use imap_codec::types::response::{Capability, Data, Response as ImapRes, Status}; use imap_codec::types::response::{Capability, Code, Data, Response as ImapRes, Status};
use crate::imap::flow; use crate::imap::flow;
use crate::imap::session::InnerContext; use crate::imap::session::InnerContext;
@ -13,6 +13,7 @@ pub async fn dispatch<'a>(ctx: InnerContext<'a>) -> Result<(Response, flow::Tran
match &ctx.req.command.body { match &ctx.req.command.body {
CommandBody::Noop => Ok((Response::ok("Noop completed.")?, flow::Transition::No)), CommandBody::Noop => Ok((Response::ok("Noop completed.")?, flow::Transition::No)),
CommandBody::Capability => capability(ctx).await, CommandBody::Capability => capability(ctx).await,
CommandBody::Logout => logout(ctx).await,
CommandBody::Login { username, password } => login(ctx, username, password).await, CommandBody::Login { username, password } => login(ctx, username, password).await,
_ => Ok(( _ => Ok((
Response::no("This command is not available in the ANONYMOUS state.")?, Response::no("This command is not available in the ANONYMOUS state.")?,
@ -59,3 +60,17 @@ async fn login<'a>(
flow::Transition::Authenticate(user), flow::Transition::Authenticate(user),
)) ))
} }
// C: 10 logout
// S: * BYE Logging out
// S: 10 OK Logout completed.
async fn logout<'a>(ctx: InnerContext<'a>) -> Result<(Response, flow::Transition)> {
// @FIXME we should implement From<Vec<Status>> and From<Vec<ImapStatus>> in
// boitalettres/src/proto/res/body.rs
Ok((
Response::ok("Logout completed")?.with_body(vec![Body::Status(
Status::bye(None, "Logging out")
.map_err(|e| Error::msg(e).context("Unable to generate IMAP status"))?,
)]),
flow::Transition::Logout,
))
}

View file

@ -144,7 +144,9 @@ impl<'a> StateContext<'a> {
res.push(Body::Status(permanent_flags)); res.push(Body::Status(permanent_flags));
Ok(( Ok((
Response::ok("Select completed")?.with_body(res), Response::ok("Select completed")?
.with_extra_code(Code::ReadWrite)
.with_body(res),
flow::Transition::Select(mb), flow::Transition::Select(mb),
)) ))
} }

View file

@ -127,7 +127,7 @@ impl Instance {
//@FIXME remove unwrap //@FIXME remove unwrap
self.state = self.state.apply(tr).unwrap(); self.state = self.state.apply(tr).unwrap();
//@FIXME enrich here the command with some status //@FIXME enrich here the command with some global status
Ok(res) Ok(res)
} }