mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 19:06:35 +03:00
Implement Rust version of {dc_msg_guess_msgtype_from_suffix}
This commit is contained in:
committed by
holger krekel
parent
2bb2ef07e9
commit
8f0e554bc4
@@ -1,4 +1,5 @@
|
||||
use std::ffi::CString;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::constants::*;
|
||||
use crate::contact::*;
|
||||
@@ -352,6 +353,24 @@ pub unsafe fn dc_msg_guess_msgtype_from_suffix(
|
||||
free(dummy_buf as *mut libc::c_void);
|
||||
}
|
||||
|
||||
pub fn dc_msg_guess_msgtype_from_suffix2(path: &Path) -> Option<(Viewtype, &str)> {
|
||||
let known = hashmap! {
|
||||
"mp3" => (Viewtype::Audio, "audio/mpeg"),
|
||||
"aac" => (Viewtype::Audio, "audio/aac"),
|
||||
"mp4" => (Viewtype::Video, "video/mp4"),
|
||||
"jpg" => (Viewtype::Image, "image/jpeg"),
|
||||
"jpeg" => (Viewtype::Image, "image/jpeg"),
|
||||
"png" => (Viewtype::Image, "image/png"),
|
||||
"webp" => (Viewtype::Image, "image/webp"),
|
||||
"gif" => (Viewtype::Gif, "image/gif"),
|
||||
"vcf" => (Viewtype::File, "text/vcard"),
|
||||
"vcard" => (Viewtype::File, "text/vcard"),
|
||||
};
|
||||
let extension = path.extension()?.to_str()?;
|
||||
|
||||
known.get(extension).map(|x| *x)
|
||||
}
|
||||
|
||||
pub unsafe fn dc_msg_get_file(msg: *const dc_msg_t) -> *mut libc::c_char {
|
||||
let mut file_abs = 0 as *mut libc::c_char;
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ extern crate rusqlite;
|
||||
extern crate strum;
|
||||
#[macro_use]
|
||||
extern crate strum_macros;
|
||||
#[macro_use]
|
||||
extern crate maplit;
|
||||
|
||||
#[macro_use]
|
||||
mod log;
|
||||
|
||||
Reference in New Issue
Block a user