server: debug print unhandled mimetypes for some multipart messages

This commit is contained in:
Bill Thiede 2024-02-23 16:55:13 -08:00
parent 523584fbbc
commit f69dd0b198

View File

@ -322,7 +322,6 @@ impl QueryRoot {
let mut messages = Vec::new();
for (path, id) in std::iter::zip(nm.files(&thread_id)?, nm.message_ids(&thread_id)?) {
let tags = nm.tags_for_query(&format!("id:{id}"))?;
info!("{id}: {tags:?}\nfile: {path}");
let file = File::open(&path)?;
let mmap = unsafe { MmapOptions::new().map(&file)? };
let m = parse_mail(&mmap)?;
@ -486,6 +485,20 @@ fn extract_alternative(m: &ParsedMail) -> Result<Body, Error> {
// multipart/mixed defines multiple types of context all of which should be presented to the user
// 'serially'.
fn extract_mixed(m: &ParsedMail) -> Result<Body, Error> {
let handled_types = vec![
MULTIPART_ALTERNATIVE,
MULTIPART_RELATED,
TEXT_HTML,
TEXT_PLAIN,
];
let mut unhandled_types: Vec<_> = m
.subparts
.iter()
.map(|sp| sp.ctype.mimetype.as_str())
.filter(|mt| !handled_types.contains(&mt))
.collect();
unhandled_types.sort();
warn!("{MULTIPART_MIXED} contains the following unhandled mimetypes {unhandled_types:?}");
for sp in &m.subparts {
if sp.ctype.mimetype.as_str() == MULTIPART_ALTERNATIVE {
return extract_alternative(sp);
@ -506,18 +519,23 @@ fn extract_mixed(m: &ParsedMail) -> Result<Body, Error> {
}
Err(format!(
"extract_mixed failed to find suitable subpart, searched: {:?}",
vec![
MULTIPART_ALTERNATIVE,
MULTIPART_RELATED,
TEXT_HTML,
TEXT_PLAIN
]
handled_types
)
.into())
}
fn extract_related(m: &ParsedMail) -> Result<Body, Error> {
// TODO(wathiede): collect related things and change return type to new Body arm.
let handled_types = vec![TEXT_HTML, TEXT_PLAIN];
let mut unhandled_types: Vec<_> = m
.subparts
.iter()
.map(|sp| sp.ctype.mimetype.as_str())
.filter(|mt| !handled_types.contains(&mt))
.collect();
unhandled_types.sort();
warn!("{MULTIPART_RELATED} contains the following unhandled mimetypes {unhandled_types:?}");
for sp in &m.subparts {
if sp.ctype.mimetype == TEXT_HTML {
let body = sp.get_body()?;
@ -532,7 +550,7 @@ fn extract_related(m: &ParsedMail) -> Result<Body, Error> {
}
Err(format!(
"extract_related failed to find suitable subpart, searched: {:?}",
vec![TEXT_HTML, TEXT_PLAIN]
handled_types
)
.into())
}