From 92826f982f795d0a61fa0807c5205437c5d826f5 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Wed, 18 Dec 2019 15:45:50 +0200 Subject: [PATCH] melib/attachments: add MultipartType::Related kind --- melib/src/email/attachment_types.rs | 8 ++++-- melib/src/email/attachments.rs | 42 +++-------------------------- 2 files changed, 10 insertions(+), 40 deletions(-) diff --git a/melib/src/email/attachment_types.rs b/melib/src/email/attachment_types.rs index 812761129..ac05affb2 100644 --- a/melib/src/email/attachment_types.rs +++ b/melib/src/email/attachment_types.rs @@ -97,9 +97,10 @@ impl Display for Charset { #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum MultipartType { - Mixed, Alternative, Digest, + Mixed, + Related, Signed, } @@ -112,9 +113,10 @@ impl Default for MultipartType { impl Display for MultipartType { fn fmt(&self, f: &mut Formatter) -> FmtResult { match self { - MultipartType::Mixed => write!(f, "multipart/mixed"), MultipartType::Alternative => write!(f, "multipart/alternative"), MultipartType::Digest => write!(f, "multipart/digest"), + MultipartType::Mixed => write!(f, "multipart/mixed"), + MultipartType::Related => write!(f, "multipart/related"), MultipartType::Signed => write!(f, "multipart/signed"), } } @@ -130,6 +132,8 @@ impl From<&[u8]> for MultipartType { MultipartType::Digest } else if val.eq_ignore_ascii_case(b"signed") { MultipartType::Signed + } else if val.eq_ignore_ascii_case(b"related") { + MultipartType::Related } else { Default::default() } diff --git a/melib/src/email/attachments.rs b/melib/src/email/attachments.rs index ed1a8e48a..e8cda961c 100644 --- a/melib/src/email/attachments.rs +++ b/melib/src/email/attachments.rs @@ -486,9 +486,7 @@ impl Attachment { self.get_text_recursive(&mut text); String::from_utf8_lossy(text.as_slice().trim()).into() } - pub fn description(&self) -> Vec { - self.attachments().iter().map(Attachment::text).collect() - } + pub fn mime_type(&self) -> String { format!("{}", self.content_type).to_string() } @@ -540,41 +538,9 @@ impl Attachment { kind: MultipartType::Alternative, ref parts, .. - } => { - for a in parts.iter() { - if let ContentType::Text { - kind: Text::Plain, .. - } = a.content_type - { - return false; - } - } - true - } - ContentType::Multipart { - kind: MultipartType::Signed, - ref parts, - .. - } => parts - .iter() - .find(|s| s.content_type != ContentType::PGPSignature) - .map(Attachment::is_html) - .unwrap_or(false), - ContentType::Multipart { ref parts, .. } => { - parts.iter().fold(true, |acc, a| match &a.content_type { - ContentType::Text { - kind: Text::Plain, .. - } => false, - ContentType::Text { - kind: Text::Html, .. - } => acc, - ContentType::Multipart { - kind: MultipartType::Alternative, - .. - } => a.is_html(), - _ => acc, - }) - } + } => parts.iter().all(Attachment::is_html), + + ContentType::Multipart { ref parts, .. } => parts.iter().any(Attachment::is_html), _ => false, } }