Merge pull request #1857 from deltachat/mime-pdf

Guess MIME type for .pdf and many other extensions
This commit is contained in:
bjoern
2020-08-23 11:12:32 +02:00
committed by GitHub
2 changed files with 39 additions and 1 deletions

View File

@@ -1408,7 +1408,9 @@ async fn prepare_msg_blob(context: &Context, msg: &mut Message) -> Result<(), Er
message::guess_msgtype_from_suffix(&blob.to_abs_path()) message::guess_msgtype_from_suffix(&blob.to_abs_path())
{ {
msg.viewtype = better_type; msg.viewtype = better_type;
msg.param.set(Param::MimeType, better_mime); if !msg.param.exists(Param::MimeType) {
msg.param.set(Param::MimeType, better_mime);
}
} }
} else if !msg.param.exists(Param::MimeType) { } else if !msg.param.exists(Param::MimeType) {
if let Some((_, mime)) = message::guess_msgtype_from_suffix(&blob.to_abs_path()) { if let Some((_, mime)) = message::guess_msgtype_from_suffix(&blob.to_abs_path()) {

View File

@@ -1099,27 +1099,63 @@ pub fn guess_msgtype_from_suffix(path: &Path) -> Option<(Viewtype, &str)> {
"3gp" => (Viewtype::Video, "video/3gpp"), "3gp" => (Viewtype::Video, "video/3gpp"),
"aac" => (Viewtype::Audio, "audio/aac"), "aac" => (Viewtype::Audio, "audio/aac"),
"avi" => (Viewtype::Video, "video/x-msvideo"), "avi" => (Viewtype::Video, "video/x-msvideo"),
"doc" => (Viewtype::File, "application/msword"),
"docx" => (
Viewtype::File,
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
),
"epub" => (Viewtype::File, "application/epub+zip"),
"flac" => (Viewtype::Audio, "audio/flac"), "flac" => (Viewtype::Audio, "audio/flac"),
"gif" => (Viewtype::Gif, "image/gif"), "gif" => (Viewtype::Gif, "image/gif"),
"html" => (Viewtype::File, "text/html"),
"htm" => (Viewtype::File, "text/html"),
"ico" => (Viewtype::File, "image/vnd.microsoft.icon"),
"jar" => (Viewtype::File, "application/java-archive"),
"jpeg" => (Viewtype::Image, "image/jpeg"), "jpeg" => (Viewtype::Image, "image/jpeg"),
"jpe" => (Viewtype::Image, "image/jpeg"), "jpe" => (Viewtype::Image, "image/jpeg"),
"jpg" => (Viewtype::Image, "image/jpeg"), "jpg" => (Viewtype::Image, "image/jpeg"),
"json" => (Viewtype::File, "application/json"),
"mov" => (Viewtype::Video, "video/quicktime"), "mov" => (Viewtype::Video, "video/quicktime"),
"mp3" => (Viewtype::Audio, "audio/mpeg"), "mp3" => (Viewtype::Audio, "audio/mpeg"),
"mp4" => (Viewtype::Video, "video/mp4"), "mp4" => (Viewtype::Video, "video/mp4"),
"odp" => (
Viewtype::File,
"application/vnd.oasis.opendocument.presentation",
),
"ods" => (
Viewtype::File,
"application/vnd.oasis.opendocument.spreadsheet",
),
"odt" => (Viewtype::File, "application/vnd.oasis.opendocument.text"),
"oga" => (Viewtype::Audio, "audio/ogg"), "oga" => (Viewtype::Audio, "audio/ogg"),
"ogg" => (Viewtype::Audio, "audio/ogg"), "ogg" => (Viewtype::Audio, "audio/ogg"),
"ogv" => (Viewtype::Video, "video/ogg"), "ogv" => (Viewtype::Video, "video/ogg"),
"opus" => (Viewtype::Audio, "audio/ogg"), "opus" => (Viewtype::Audio, "audio/ogg"),
"otf" => (Viewtype::File, "font/otf"),
"pdf" => (Viewtype::File, "application/pdf"),
"png" => (Viewtype::Image, "image/png"), "png" => (Viewtype::Image, "image/png"),
"rar" => (Viewtype::File, "application/vnd.rar"),
"rtf" => (Viewtype::File, "application/rtf"),
"spx" => (Viewtype::Audio, "audio/ogg"), // Ogg Speex Profile "spx" => (Viewtype::Audio, "audio/ogg"), // Ogg Speex Profile
"svg" => (Viewtype::Image, "image/svg+xml"), "svg" => (Viewtype::Image, "image/svg+xml"),
"tgs" => (Viewtype::Sticker, "application/x-tgsticker"), "tgs" => (Viewtype::Sticker, "application/x-tgsticker"),
"tiff" => (Viewtype::File, "image/tiff"),
"tif" => (Viewtype::File, "image/tiff"),
"ttf" => (Viewtype::File, "font/ttf"),
"vcard" => (Viewtype::File, "text/vcard"), "vcard" => (Viewtype::File, "text/vcard"),
"vcf" => (Viewtype::File, "text/vcard"), "vcf" => (Viewtype::File, "text/vcard"),
"wav" => (Viewtype::File, "audio/wav"),
"weba" => (Viewtype::File, "audio/webm"),
"webm" => (Viewtype::Video, "video/webm"), "webm" => (Viewtype::Video, "video/webm"),
"webp" => (Viewtype::Image, "image/webp"), "webp" => (Viewtype::Image, "image/webp"),
"wmv" => (Viewtype::Video, "video/x-ms-wmv"), "wmv" => (Viewtype::Video, "video/x-ms-wmv"),
"xhtml" => (Viewtype::File, "application/xhtml+xml"),
"xlsx" => (
Viewtype::File,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
),
"xml" => (Viewtype::File, "application/vnd.ms-excel"),
"zip" => (Viewtype::File, "application/zip"),
_ => { _ => {
return None; return None;
} }