use base_message::{FieldType, FieldValueError, ascii_text, combination::Singleton};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ContentTransferEncoding {
SevenBit,
EightBit,
Binary,
}
impl ContentTransferEncoding {
pub fn as_str(self) -> &'static str {
match self {
Self::SevenBit => "7bit",
Self::EightBit => "8bit",
Self::Binary => "binary",
}
}
}
impl std::fmt::Display for ContentTransferEncoding {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str(self.as_str())
}
}
impl FieldType<'_> for ContentTransferEncoding {
type Combination = Singleton;
fn parse(value: &[u8]) -> Result<Self, FieldValueError> {
let text = ascii_text(value)?;
[Self::SevenBit, Self::EightBit, Self::Binary]
.into_iter()
.find(|encoding| encoding.as_str().eq_ignore_ascii_case(text))
.ok_or(FieldValueError::new(
"unsupported content transfer encoding",
))
}
}