From 3d23f0c936516ed89f2888fb44babb3994e8d579 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 17 Jan 2024 08:22:15 +0100 Subject: WIP refactor idle --- src/imap/flow.rs | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src/imap/flow.rs') diff --git a/src/imap/flow.rs b/src/imap/flow.rs index 95810c1..ff348ca 100644 --- a/src/imap/flow.rs +++ b/src/imap/flow.rs @@ -19,17 +19,23 @@ impl StdError for Error {} pub enum State { NotAuthenticated, Authenticated(Arc), - Selected(Arc, MailboxView), - // Examined is like Selected, but indicates that the mailbox is read-only - Examined(Arc, MailboxView), + Selected(Arc, MailboxView, MailboxPerm), + Idle(Arc, MailboxView, MailboxPerm), Logout, } +#[derive(Clone)] +pub enum MailboxPerm { + ReadOnly, + ReadWrite, +} + pub enum Transition { None, Authenticate(Arc), - Examine(MailboxView), - Select(MailboxView), + Select(MailboxView, MailboxPerm), + Idle, + UnIdle, Unselect, Logout, } @@ -38,20 +44,22 @@ pub enum Transition { // https://datatracker.ietf.org/doc/html/rfc3501#page-13 impl State { pub fn apply(&mut self, tr: Transition) -> Result<(), Error> { - let new_state = match (&self, tr) { + let new_state = match (std::mem::replace(self, State::NotAuthenticated), tr) { (_s, Transition::None) => return Ok(()), (State::NotAuthenticated, Transition::Authenticate(u)) => State::Authenticated(u), ( - State::Authenticated(u) | State::Selected(u, _) | State::Examined(u, _), - Transition::Select(m), - ) => State::Selected(u.clone(), m), - ( - State::Authenticated(u) | State::Selected(u, _) | State::Examined(u, _), - Transition::Examine(m), - ) => State::Examined(u.clone(), m), - (State::Selected(u, _) | State::Examined(u, _), Transition::Unselect) => { + State::Authenticated(u) | State::Selected(u, _, _), + Transition::Select(m, p), + ) => State::Selected(u, m, p), + (State::Selected(u, _, _) , Transition::Unselect) => { State::Authenticated(u.clone()) } + (State::Selected(u, m, p), Transition::Idle) => { + State::Idle(u, m, p) + }, + (State::Idle(u, m, p), Transition::UnIdle) => { + State::Selected(u, m, p) + }, (_, Transition::Logout) => State::Logout, _ => return Err(Error::ForbiddenTransition), }; -- cgit v1.2.3