mirror of
https://github.com/chatmail/core.git
synced 2026-04-25 01:16:29 +03:00
use .to_string_lossy() member of Path, CStr etc.
instead of calling to_str().unwrap_or_default().
This commit is contained in:
committed by
holger krekel
parent
e251c7b1c8
commit
db2064de14
@@ -2136,7 +2136,7 @@ pub unsafe extern "C" fn dc_chat_get_profile_image(chat: *mut dc_chat_t) -> *mut
|
|||||||
let ffi_context = &*ffi_chat.context;
|
let ffi_context = &*ffi_chat.context;
|
||||||
ffi_context
|
ffi_context
|
||||||
.with_inner(|ctx| match ffi_chat.chat.get_profile_image(ctx) {
|
.with_inner(|ctx| match ffi_chat.chat.get_profile_image(ctx) {
|
||||||
Some(p) => p.to_str().unwrap_or_default().to_string().strdup(),
|
Some(p) => p.to_string_lossy().strdup(),
|
||||||
None => ptr::null_mut(),
|
None => ptr::null_mut(),
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|_| ptr::null_mut())
|
.unwrap_or_else(|_| ptr::null_mut())
|
||||||
@@ -2773,7 +2773,7 @@ pub unsafe extern "C" fn dc_contact_get_profile_image(
|
|||||||
ffi_contact
|
ffi_contact
|
||||||
.contact
|
.contact
|
||||||
.get_profile_image(ctx)
|
.get_profile_image(ctx)
|
||||||
.map(|p| p.to_str().unwrap_or_default().to_string().strdup())
|
.map(|p| p.to_string_lossy().strdup())
|
||||||
.unwrap_or_else(|| std::ptr::null_mut())
|
.unwrap_or_else(|| std::ptr::null_mut())
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|_| ptr::null_mut())
|
.unwrap_or_else(|_| ptr::null_mut())
|
||||||
|
|||||||
@@ -16,12 +16,9 @@ pub unsafe fn charconv(
|
|||||||
) -> libc::c_int {
|
) -> libc::c_int {
|
||||||
assert!(!fromcode.is_null(), "invalid fromcode");
|
assert!(!fromcode.is_null(), "invalid fromcode");
|
||||||
assert!(!s.is_null(), "invalid input string");
|
assert!(!s.is_null(), "invalid input string");
|
||||||
if let Some(encoding) = charset::Charset::for_label(
|
if let Some(encoding) =
|
||||||
CStr::from_ptr(fromcode)
|
charset::Charset::for_label(CStr::from_ptr(fromcode).to_string_lossy().as_bytes())
|
||||||
.to_str()
|
{
|
||||||
.unwrap_or_default()
|
|
||||||
.as_bytes(),
|
|
||||||
) {
|
|
||||||
let data = std::slice::from_raw_parts(s as *const u8, strlen(s));
|
let data = std::slice::from_raw_parts(s as *const u8, strlen(s));
|
||||||
|
|
||||||
let (res, _, _) = encoding.decode(data);
|
let (res, _, _) = encoding.decode(data);
|
||||||
|
|||||||
@@ -1515,8 +1515,8 @@ pub unsafe fn mailmime_data_write_driver(
|
|||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
let filename = CStr::from_ptr((*mime_data).dt_data.dt_filename)
|
let filename = CStr::from_ptr((*mime_data).dt_data.dt_filename)
|
||||||
.to_str()
|
.to_string_lossy()
|
||||||
.unwrap_or_default();
|
.into_owned();
|
||||||
if let Ok(file) = std::fs::File::open(filename) {
|
if let Ok(file) = std::fs::File::open(filename) {
|
||||||
if let Ok(mut text) = memmap::MmapOptions::new().map_copy(&file) {
|
if let Ok(mut text) = memmap::MmapOptions::new().map_copy(&file) {
|
||||||
if 0 != (*mime_data).dt_encoded {
|
if 0 != (*mime_data).dt_encoded {
|
||||||
|
|||||||
@@ -79,19 +79,13 @@ impl Aheader {
|
|||||||
let optional_field = unsafe { (*field).fld_data.fld_optional_field };
|
let optional_field = unsafe { (*field).fld_data.fld_optional_field };
|
||||||
if !optional_field.is_null()
|
if !optional_field.is_null()
|
||||||
&& unsafe { !(*optional_field).fld_name.is_null() }
|
&& unsafe { !(*optional_field).fld_name.is_null() }
|
||||||
&& unsafe {
|
&& unsafe { CStr::from_ptr((*optional_field).fld_name).to_string_lossy() }
|
||||||
CStr::from_ptr((*optional_field).fld_name)
|
== "Autocrypt"
|
||||||
.to_str()
|
|
||||||
.unwrap_or_default()
|
|
||||||
} == "Autocrypt"
|
|
||||||
{
|
{
|
||||||
let value = unsafe {
|
let value =
|
||||||
CStr::from_ptr((*optional_field).fld_value)
|
unsafe { CStr::from_ptr((*optional_field).fld_value).to_string_lossy() };
|
||||||
.to_str()
|
|
||||||
.unwrap_or_default()
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Ok(test) = Self::from_str(value) {
|
if let Ok(test) = Self::from_str(&value) {
|
||||||
if addr_cmp(&test.addr, wanted_from) {
|
if addr_cmp(&test.addr, wanted_from) {
|
||||||
if fine_header.is_none() {
|
if fine_header.is_none() {
|
||||||
fine_header = Some(test);
|
fine_header = Some(test);
|
||||||
|
|||||||
@@ -620,12 +620,9 @@ impl<'a> MimeParser<'a> {
|
|||||||
&& strcmp(charset, b"utf-8\x00" as *const u8 as *const libc::c_char) != 0i32
|
&& strcmp(charset, b"utf-8\x00" as *const u8 as *const libc::c_char) != 0i32
|
||||||
&& strcmp(charset, b"UTF-8\x00" as *const u8 as *const libc::c_char) != 0i32
|
&& strcmp(charset, b"UTF-8\x00" as *const u8 as *const libc::c_char) != 0i32
|
||||||
{
|
{
|
||||||
if let Some(encoding) = Charset::for_label(
|
if let Some(encoding) =
|
||||||
CStr::from_ptr(charset)
|
Charset::for_label(CStr::from_ptr(charset).to_string_lossy().as_bytes())
|
||||||
.to_str()
|
{
|
||||||
.unwrap_or_default()
|
|
||||||
.as_bytes(),
|
|
||||||
) {
|
|
||||||
let (res, _, _) = encoding.decode(&decoded_data);
|
let (res, _, _) = encoding.decode(&decoded_data);
|
||||||
if res.is_empty() {
|
if res.is_empty() {
|
||||||
/* no error - but nothing to add */
|
/* no error - but nothing to add */
|
||||||
|
|||||||
Reference in New Issue
Block a user