use imap_proto::types::Capability;
use std::collections::hash_set::Iter;
use std::collections::HashSet;
const IMAP4REV1_CAPABILITY: &str = "IMAP4rev1";
const AUTH_CAPABILITY_PREFIX: &str = "AUTH=";
pub struct Capabilities(
pub(crate) HashSet<Capability<'static>>,
);
impl Capabilities {
pub fn has<'a>(&self, cap: &Capability<'a>) -> bool {
self.0.contains(cap)
}
pub fn has_str<S: AsRef<str>>(&self, cap: S) -> bool {
let s = cap.as_ref();
if s.eq_ignore_ascii_case(IMAP4REV1_CAPABILITY) {
return self.has(&Capability::Imap4rev1);
}
if s.len() > AUTH_CAPABILITY_PREFIX.len() {
let (pre, val) = s.split_at(AUTH_CAPABILITY_PREFIX.len());
if pre.eq_ignore_ascii_case(AUTH_CAPABILITY_PREFIX) {
return self.has(&Capability::Auth(val));
}
}
self.has(&Capability::Atom(s))
}
pub fn iter(&self) -> Iter<'_, Capability<'_>> {
self.0.iter()
}
pub fn len(&self) -> usize {
self.0.len()
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
}