aboutsummaryrefslogtreecommitdiff
path: root/src/imap/flow.rs
diff options
context:
space:
mode:
authorQuentin <quentin@dufour.io>2024-01-02 22:44:29 +0000
committerQuentin <quentin@dufour.io>2024-01-02 22:44:29 +0000
commitb9a0c1e6eced036eb71e8221a4f236f72832fec2 (patch)
treec498a7a2a5833f2c6f27d4ba97894747f9d454c0 /src/imap/flow.rs
parent6ff3c6f71efd802da422a371e6168ae528fb2ddc (diff)
parentc9a33c080d39d4a2b269e3c8f166a708b6606da5 (diff)
downloadaerogramme-b9a0c1e6eced036eb71e8221a4f236f72832fec2.tar.gz
aerogramme-b9a0c1e6eced036eb71e8221a4f236f72832fec2.zip
Merge pull request 'Implement imap-flow' (#34) from refactor/imap-flow into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/aerogramme/pulls/34
Diffstat (limited to 'src/imap/flow.rs')
-rw-r--r--src/imap/flow.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/imap/flow.rs b/src/imap/flow.rs
index eb94bb5..95810c1 100644
--- a/src/imap/flow.rs
+++ b/src/imap/flow.rs
@@ -37,23 +37,27 @@ pub enum Transition {
// See RFC3501 section 3.
// https://datatracker.ietf.org/doc/html/rfc3501#page-13
impl State {
- pub fn apply(self, tr: Transition) -> Result<Self, Error> {
- match (self, tr) {
- (s, Transition::None) => Ok(s),
- (State::NotAuthenticated, Transition::Authenticate(u)) => Ok(State::Authenticated(u)),
+ pub fn apply(&mut self, tr: Transition) -> Result<(), Error> {
+ let new_state = match (&self, 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),
- ) => Ok(State::Selected(u, m)),
+ ) => State::Selected(u.clone(), m),
(
State::Authenticated(u) | State::Selected(u, _) | State::Examined(u, _),
Transition::Examine(m),
- ) => Ok(State::Examined(u, m)),
+ ) => State::Examined(u.clone(), m),
(State::Selected(u, _) | State::Examined(u, _), Transition::Unselect) => {
- Ok(State::Authenticated(u))
+ State::Authenticated(u.clone())
}
- (_, Transition::Logout) => Ok(State::Logout),
- _ => Err(Error::ForbiddenTransition),
- }
+ (_, Transition::Logout) => State::Logout,
+ _ => return Err(Error::ForbiddenTransition),
+ };
+
+ *self = new_state;
+
+ Ok(())
}
}