diff --git a/src/api/mt_form.rs b/src/api/mt_form.rs index 6a8ca26..9a5c299 100644 --- a/src/api/mt_form.rs +++ b/src/api/mt_form.rs @@ -289,12 +289,13 @@ impl MtForm { } } - fn get_temp_file(&mut self) -> Option<(String, String)> { + fn get_temp_file(&mut self) -> Option<(String, String, Option)> { let first = self.first_name.clone(); let last = self.last_name.clone(); let filename_noext = format!("{}_{}", first, last); - let file_name = if let Some(file) = self.file.as_ref() { - file.file_name.to_owned() + let (file_name, content_type) = if let Some(file) = self.file.as_ref() { + let content_type = file.content_type.clone().map(|m| m.to_string()); + (file.file_name.to_owned(), content_type) } else { return None; }; @@ -318,7 +319,7 @@ impl MtForm { return None; } info!(?f, "File saved successfully"); - Some((filename, path)) + Some((filename, path, content_type.clone())) } Err(e) => { error!("{:?}: Probably a missing image", e); @@ -334,9 +335,10 @@ impl MtForm { info!("{first} {last} signed up for mission trip!"); let email = self.build_email().await; let temp_file = self.get_temp_file(); - let multi = if let Some((file, path)) = temp_file { + let multi = if let Some((file, path, content_type)) = temp_file { let filebody = fs::read(path); - let content_type = ContentType::parse("image/jpg").unwrap(); + let content_type = + ContentType::parse(&content_type.unwrap_or(String::from("image/jpg"))).unwrap(); let attachment = Attachment::new(file).body(filebody.unwrap(), content_type); // info!(?attachment); MultiPart::mixed()