diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 511fdbc94..9e9834732 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -2362,7 +2362,11 @@ pub unsafe extern "C" fn dc_msg_get_filemime(msg: *mut dc_msg_t) -> *mut libc::c return dc_strdup(ptr::null()); } let ffi_msg = &*msg; - ffi_msg.message.get_filemime().strdup() + if let Some(x) = ffi_msg.message.get_filemime() { + x.strdup() + } else { + return dc_strdup(ptr::null()); + } } #[no_mangle] diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 72404a77b..77bf9a652 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -93,8 +93,9 @@ class TestOfflineContact: ac1 = acfactory.get_configured_offline_account() contact1 = ac1.create_contact(email="some1@example.com", name="some1") chat = ac1.create_chat_by_contact(contact1) - chat.send_text("one messae") + msg = chat.send_text("one messae") assert not ac1.delete_contact(contact1) + assert not msg.filemime class TestOfflineChat: diff --git a/src/message.rs b/src/message.rs index 04175defa..16d547d26 100644 --- a/src/message.rs +++ b/src/message.rs @@ -143,17 +143,18 @@ impl Message { } } - pub fn get_filemime(&self) -> String { + pub fn get_filemime(&self) -> Option { if let Some(m) = self.param.get(Param::MimeType) { - return m.to_string(); + return Some(m.to_string()); } else if let Some(file) = self.param.get(Param::File) { if let Some((_, mime)) = guess_msgtype_from_suffix(Path::new(file)) { - return mime.to_string(); + return Some(mime.to_string()); } - return "application/octet-stream".to_string() + // we have a file but no mimetype, let's use a generic one + return Some("application/octet-stream".to_string()); } - "".to_string() - + // no mimetype and no file + None } pub fn get_file(&self, context: &Context) -> Option { @@ -644,7 +645,7 @@ pub fn get_msg_info(context: &Context, msg_id: u32) -> String { ret += "Type: "; ret += &format!("{}", msg.type_0); ret += "\n"; - ret += &format!("Mimetype: {}\n", &msg.get_filemime()); + ret += &format!("Mimetype: {}\n", &msg.get_filemime().unwrap_or_default()); } let w = msg.param.get_int(Param::Width).unwrap_or_default(); let h = msg.param.get_int(Param::Height).unwrap_or_default(); @@ -1155,5 +1156,6 @@ mod tests { let msg_id = chat::prepare_msg(ctx, chat, &mut msg).unwrap(); let _msg2 = Message::load_from_db(ctx, msg_id).unwrap(); + assert_eq!(_msg2.get_filemime(), None); } }