1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
pub use imap_proto::types::NameAttribute;
use imap_proto::{MailboxDatum, Response};
use crate::types::ResponseData;
#[ouroboros::self_referencing(pub_extras)]
#[derive(Debug)]
pub struct Name {
response: Box<ResponseData>,
#[borrows(response)]
#[covariant]
inner: InnerName<'this>,
}
#[derive(PartialEq, Eq, Debug)]
pub struct InnerName<'a> {
attributes: Vec<NameAttribute<'a>>,
delimiter: Option<&'a str>,
name: &'a str,
}
impl Name {
pub(crate) fn from_mailbox_data(resp: ResponseData) -> Self {
Name::new(Box::new(resp), |response| match response.parsed() {
Response::MailboxData(MailboxDatum::List {
name_attributes,
delimiter,
name,
}) => InnerName {
attributes: name_attributes.to_owned(),
delimiter: delimiter.as_deref(),
name,
},
_ => panic!("cannot construct from non mailbox data"),
})
}
pub fn attributes(&self) -> &[NameAttribute<'_>] {
&self.borrow_inner().attributes[..]
}
pub fn delimiter(&self) -> Option<&str> {
self.borrow_inner().delimiter
}
pub fn name(&self) -> &str {
self.borrow_inner().name
}
}