use alloc::vec::Vec;
use thiserror::Error;
pub const AUTH: &str = "AUTH";
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SmtpAuthCapability<'a>(Vec<&'a str>);
impl<'a> SmtpAuthCapability<'a> {
pub fn parse(s: &'a str) -> Result<Self, SmtpAuthCapabilityError> {
let mut parts = s.split_ascii_whitespace();
match parts.next() {
Some(kw) if kw.eq_ignore_ascii_case(AUTH) => {}
_ => return Err(SmtpAuthCapabilityError),
}
Ok(SmtpAuthCapability(parts.collect()))
}
pub fn has(&self, mechanism: &str) -> bool {
self.0.iter().any(|m| m.eq_ignore_ascii_case(mechanism))
}
pub fn mechanisms(&self) -> impl Iterator<Item = &str> {
self.0.iter().copied()
}
}
#[derive(Debug, Error)]
#[error("invalid AUTH capability string")]
pub struct SmtpAuthCapabilityError;