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