From 6763dd653edda2a2e183f8182678498ef9baadee Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Sun, 23 Aug 2020 01:18:07 +0300 Subject: [PATCH 1/2] Do not override mime type set by the user --- src/chat.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/chat.rs b/src/chat.rs index 26f57b6bf..7d025cb6f 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -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()) { 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) { if let Some((_, mime)) = message::guess_msgtype_from_suffix(&blob.to_abs_path()) { From a01755b65b3d983c3adee3c6545df1c03285c28a Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Sat, 22 Aug 2020 23:46:20 +0300 Subject: [PATCH 2/2] Guess MIME type for .pdf and many other extensions --- src/message.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/message.rs b/src/message.rs index c33ec1a99..ba0993631 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1099,27 +1099,63 @@ pub fn guess_msgtype_from_suffix(path: &Path) -> Option<(Viewtype, &str)> { "3gp" => (Viewtype::Video, "video/3gpp"), "aac" => (Viewtype::Audio, "audio/aac"), "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"), "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"), "jpe" => (Viewtype::Image, "image/jpeg"), "jpg" => (Viewtype::Image, "image/jpeg"), + "json" => (Viewtype::File, "application/json"), "mov" => (Viewtype::Video, "video/quicktime"), "mp3" => (Viewtype::Audio, "audio/mpeg"), "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"), "ogg" => (Viewtype::Audio, "audio/ogg"), "ogv" => (Viewtype::Video, "video/ogg"), "opus" => (Viewtype::Audio, "audio/ogg"), + "otf" => (Viewtype::File, "font/otf"), + "pdf" => (Viewtype::File, "application/pdf"), "png" => (Viewtype::Image, "image/png"), + "rar" => (Viewtype::File, "application/vnd.rar"), + "rtf" => (Viewtype::File, "application/rtf"), "spx" => (Viewtype::Audio, "audio/ogg"), // Ogg Speex Profile "svg" => (Viewtype::Image, "image/svg+xml"), "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"), "vcf" => (Viewtype::File, "text/vcard"), + "wav" => (Viewtype::File, "audio/wav"), + "weba" => (Viewtype::File, "audio/webm"), "webm" => (Viewtype::Video, "video/webm"), "webp" => (Viewtype::Image, "image/webp"), "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; }