jmap_client/mailbox/
get.rs

1/*
2 * Copyright Stalwart Labs LLC See the COPYING
3 * file at the top-level directory of this distribution.
4 *
5 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
8 * option. This file may not be copied, modified, or distributed
9 * except according to those terms.
10 */
11
12use super::{Mailbox, MailboxRights, Role};
13use crate::{core::get::GetObject, principal::ACL, Get, Set};
14use ahash::AHashMap;
15
16impl Mailbox<Get> {
17    pub fn id(&self) -> Option<&str> {
18        self.id.as_deref()
19    }
20
21    pub fn take_id(&mut self) -> String {
22        self.id.take().unwrap_or_default()
23    }
24
25    pub fn name(&self) -> Option<&str> {
26        self.name.as_deref()
27    }
28
29    pub fn parent_id(&self) -> Option<&str> {
30        self.parent_id.as_deref()
31    }
32
33    pub fn role(&self) -> Role {
34        self.role.as_ref().cloned().unwrap_or(Role::None)
35    }
36
37    pub fn sort_order(&self) -> u32 {
38        self.sort_order.as_ref().copied().unwrap_or(0)
39    }
40
41    pub fn total_emails(&self) -> usize {
42        self.total_emails.as_ref().copied().unwrap_or(0)
43    }
44
45    pub fn unread_emails(&self) -> usize {
46        self.unread_emails.as_ref().copied().unwrap_or(0)
47    }
48
49    pub fn total_threads(&self) -> usize {
50        self.total_threads.as_ref().copied().unwrap_or(0)
51    }
52
53    pub fn unread_threads(&self) -> usize {
54        self.unread_threads.as_ref().copied().unwrap_or(0)
55    }
56
57    pub fn is_subscribed(&self) -> bool {
58        *self.is_subscribed.as_ref().unwrap_or(&false)
59    }
60
61    pub fn my_rights(&self) -> Option<&MailboxRights> {
62        self.my_rights.as_ref()
63    }
64
65    pub fn acl(&self) -> Option<&AHashMap<String, AHashMap<ACL, bool>>> {
66        self.share_with.as_ref()
67    }
68
69    pub fn take_acl(&mut self) -> Option<AHashMap<String, AHashMap<ACL, bool>>> {
70        self.share_with.take()
71    }
72}
73
74impl MailboxRights {
75    pub fn may_read_items(&self) -> bool {
76        self.may_read_items
77    }
78
79    pub fn may_add_items(&self) -> bool {
80        self.may_add_items
81    }
82
83    pub fn may_remove_items(&self) -> bool {
84        self.may_remove_items
85    }
86
87    pub fn may_set_seen(&self) -> bool {
88        self.may_set_seen
89    }
90
91    pub fn may_set_keywords(&self) -> bool {
92        self.may_set_keywords
93    }
94
95    pub fn may_create_child(&self) -> bool {
96        self.may_create_child
97    }
98
99    pub fn may_rename(&self) -> bool {
100        self.may_rename
101    }
102
103    pub fn may_delete(&self) -> bool {
104        self.may_delete
105    }
106
107    pub fn may_submit(&self) -> bool {
108        self.may_submit
109    }
110
111    pub fn acl_list(&self) -> Vec<ACL> {
112        let mut acl_list = Vec::new();
113        for (is_set, acl) in [
114            (self.may_read_items, ACL::ReadItems),
115            (self.may_add_items, ACL::AddItems),
116            (self.may_remove_items, ACL::RemoveItems),
117            (self.may_set_seen, ACL::SetSeen),
118            (self.may_set_keywords, ACL::SetKeywords),
119            (self.may_create_child, ACL::CreateChild),
120            (self.may_rename, ACL::Rename),
121            (self.may_delete, ACL::Delete),
122            (self.may_submit, ACL::Submit),
123        ] {
124            if is_set && !acl_list.contains(&acl) {
125                acl_list.push(acl);
126            }
127        }
128        acl_list
129    }
130}
131
132impl GetObject for Mailbox<Set> {
133    type GetArguments = ();
134}
135
136impl GetObject for Mailbox<Get> {
137    type GetArguments = ();
138}