melib/attachments: add MultipartType::Related kind
parent
9211913405
commit
92826f982f
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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<String> {
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue