From 91fa0d38c3b9733030c3ac06a5f5784dc1cad019 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 25 Jul 2023 14:39:30 +0200 Subject: [PATCH] implement to_string for some types --- src/mime/charset.rs | 6 ++++++ src/mime/type.rs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/mime/charset.rs b/src/mime/charset.rs index 5a9d020..ed668fa 100644 --- a/src/mime/charset.rs +++ b/src/mime/charset.rs @@ -77,6 +77,12 @@ impl<'a> From<&'a [u8]> for EmailCharset { } } +impl ToString for EmailCharset { + fn to_string(&self) -> String { + self.as_str().into() + } +} + impl EmailCharset { pub fn as_str(&self) -> &'static str { use EmailCharset::*; diff --git a/src/mime/type.rs b/src/mime/type.rs index 082679f..b83e643 100644 --- a/src/mime/type.rs +++ b/src/mime/type.rs @@ -101,6 +101,11 @@ pub struct Multipart { pub subtype: MultipartSubtype, pub boundary: String, } +impl Multipart { + pub fn main_type(&self) -> String { + "multipart".into() + } +} impl<'a> TryFrom<&'a NaiveType<'a>> for Multipart { type Error = (); @@ -125,6 +130,18 @@ pub enum MultipartSubtype { Report, Unknown, } +impl ToString for MultipartSubtype { + fn to_string(&self) -> String { + match self { + Self::Alternative => "alternative", + Self::Mixed => "mixed", + Self::Digest => "digest", + Self::Parallel => "parallel", + Self::Report => "report", + Self::Unknown => "mixed", + }.into() + } +} impl<'a> From<&NaiveType<'a>> for MultipartSubtype { fn from(nt: &NaiveType<'a>) -> Self { match nt.sub.to_ascii_lowercase().as_slice() { @@ -148,6 +165,16 @@ pub enum MessageSubtype { External, Unknown, } +impl ToString for MessageSubtype { + fn to_string(&self) -> String { + match self { + Self::RFC822 => "rfc822", + Self::Partial => "partial", + Self::External => "external", + Self::Unknown => "rfc822", + }.into() + } +} pub type DeductibleMessage = Deductible; #[derive(Debug, PartialEq, Default, Clone)] @@ -206,6 +233,14 @@ pub enum TextSubtype { Html, Unknown, } +impl ToString for TextSubtype { + fn to_string(&self) -> String { + match self { + Self::Plain | Self::Unknown => "plain", + Self::Html => "html", + }.into() + } +} impl<'a> From<&NaiveType<'a>> for TextSubtype { fn from(nt: &NaiveType<'a>) -> Self { match nt.sub.to_ascii_lowercase().as_slice() {