1 use super::mailbox::Mailbox;
2
3 #[derive(Debug, Clone)]
4 pub enum ImapState {
5 NotAuthenticated,
6 Authenticated,
7 Selected(Mailbox),
8 Logout,
9 }
10
11 impl PartialEq for ImapState {
12 fn eq(&self, other: &Self) -> bool {
13 match (self, other) {
14 (ImapState::NotAuthenticated, ImapState::NotAuthenticated) => true,
15 (ImapState::Authenticated, ImapState::Authenticated) => true,
16 (ImapState::Logout, ImapState::Logout) => true,
17 (ImapState::Selected(_), ImapState::Selected(_)) => true,
18 _ => false,
19 }
20 }
21 }
22
23 impl ImapState {
24 pub fn is_authenticated(&self) -> bool {
25 matches!(self, ImapState::Authenticated | ImapState::Selected(_))
26 }
27
28 pub fn is_selected(&self) -> bool {
29 matches!(self, ImapState::Selected(_))
30 }
31
32 pub fn get_selected_mailbox(&self) -> Option<&Mailbox> {
33 if let ImapState::Selected(mailbox) = self {
34 Some(mailbox)
35 } else {
36 None
37 }
38 }
39 }