1use super::to_owned_cow;
2
3use std::borrow::Cow;
4
5#[derive(Debug, Eq, PartialEq)]
8pub struct Acl<'a> {
9 pub mailbox: Cow<'a, str>,
10 pub acls: Vec<AclEntry<'a>>,
11}
12
13impl<'a> Acl<'a> {
14 pub fn into_owned(self) -> Acl<'static> {
15 Acl {
16 mailbox: to_owned_cow(self.mailbox),
17 acls: self.acls.into_iter().map(AclEntry::into_owned).collect(),
18 }
19 }
20}
21
22#[derive(Debug, Eq, PartialEq)]
23pub struct AclEntry<'a> {
24 pub identifier: Cow<'a, str>,
25 pub rights: Vec<AclRight>,
26}
27
28impl<'a> AclEntry<'a> {
29 pub fn into_owned(self) -> AclEntry<'static> {
30 AclEntry {
31 identifier: to_owned_cow(self.identifier),
32 rights: self.rights,
33 }
34 }
35}
36
37#[derive(Debug, Eq, PartialEq)]
38pub struct ListRights<'a> {
39 pub mailbox: Cow<'a, str>,
40 pub identifier: Cow<'a, str>,
41 pub required: Vec<AclRight>,
42 pub optional: Vec<AclRight>,
43}
44
45impl<'a> ListRights<'a> {
46 pub fn into_owned(self) -> ListRights<'static> {
47 ListRights {
48 mailbox: to_owned_cow(self.mailbox),
49 identifier: to_owned_cow(self.identifier),
50 required: self.required,
51 optional: self.optional,
52 }
53 }
54}
55
56#[derive(Debug, Eq, PartialEq)]
57pub struct MyRights<'a> {
58 pub mailbox: Cow<'a, str>,
59 pub rights: Vec<AclRight>,
60}
61
62impl<'a> MyRights<'a> {
63 pub fn into_owned(self) -> MyRights<'static> {
64 MyRights {
65 mailbox: to_owned_cow(self.mailbox),
66 rights: self.rights,
67 }
68 }
69}
70
71#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
72pub enum AclRight {
73 Lookup,
76 Read,
78 Seen,
82 Write,
85 Insert,
87 Post,
90 CreateMailbox,
94 DeleteMailbox,
96 DeleteMessage,
99 Expunge,
101 Administer,
103 Annotation,
106 OldCreate,
108 OldDelete,
110 Custom(char),
112}
113
114impl From<char> for AclRight {
115 fn from(c: char) -> Self {
116 match c {
117 'l' => AclRight::Lookup,
118 'r' => AclRight::Read,
119 's' => AclRight::Seen,
120 'w' => AclRight::Write,
121 'i' => AclRight::Insert,
122 'p' => AclRight::Post,
123 'k' => AclRight::CreateMailbox,
124 'x' => AclRight::DeleteMailbox,
125 't' => AclRight::DeleteMessage,
126 'e' => AclRight::Expunge,
127 'a' => AclRight::Administer,
128 'n' => AclRight::Annotation,
129 'c' => AclRight::OldCreate,
130 'd' => AclRight::OldDelete,
131 _ => AclRight::Custom(c),
132 }
133 }
134}
135
136impl From<AclRight> for char {
137 fn from(right: AclRight) -> Self {
138 match right {
139 AclRight::Lookup => 'l',
140 AclRight::Read => 'r',
141 AclRight::Seen => 's',
142 AclRight::Write => 'w',
143 AclRight::Insert => 'i',
144 AclRight::Post => 'p',
145 AclRight::CreateMailbox => 'k',
146 AclRight::DeleteMailbox => 'x',
147 AclRight::DeleteMessage => 't',
148 AclRight::Expunge => 'e',
149 AclRight::Administer => 'a',
150 AclRight::Annotation => 'n',
151 AclRight::OldCreate => 'c',
152 AclRight::OldDelete => 'd',
153 AclRight::Custom(c) => c,
154 }
155 }
156}
157
158#[cfg(test)]
159mod tests {
160 use super::*;
161
162 #[test]
163 fn test_char_to_acl_right() {
164 assert_eq!(Into::<AclRight>::into('l'), AclRight::Lookup);
165 assert_eq!(Into::<AclRight>::into('c'), AclRight::OldCreate);
166 assert_eq!(Into::<AclRight>::into('k'), AclRight::CreateMailbox);
167 assert_eq!(Into::<AclRight>::into('0'), AclRight::Custom('0'));
168 }
169
170 #[test]
171 fn test_acl_right_to_char() {
172 assert_eq!(Into::<char>::into(AclRight::Lookup), 'l');
173 assert_eq!(Into::<char>::into(AclRight::OldCreate), 'c');
174 assert_eq!(Into::<char>::into(AclRight::CreateMailbox), 'k');
175 assert_eq!(Into::<char>::into(AclRight::Custom('0')), '0');
176 }
177}