mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
prefer to_string_lossy() over as_str() as the latter pancis on non-wellformatted utf-8
This commit is contained in:
committed by
holger krekel
parent
8ce05796da
commit
e4b3e23769
@@ -2,7 +2,7 @@ extern crate deltachat_provider_database;
|
|||||||
|
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
use deltachat::dc_tools::{as_str, StrExt};
|
use deltachat::dc_tools::{to_string_lossy, StrExt};
|
||||||
use deltachat_provider_database::StatusState;
|
use deltachat_provider_database::StatusState;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
@@ -12,7 +12,7 @@ pub type dc_provider_t = deltachat_provider_database::Provider;
|
|||||||
pub unsafe extern "C" fn dc_provider_new_from_domain(
|
pub unsafe extern "C" fn dc_provider_new_from_domain(
|
||||||
domain: *const libc::c_char,
|
domain: *const libc::c_char,
|
||||||
) -> *const dc_provider_t {
|
) -> *const dc_provider_t {
|
||||||
match deltachat_provider_database::get_provider_info(as_str(domain)) {
|
match deltachat_provider_database::get_provider_info(&to_string_lossy(domain)) {
|
||||||
Some(provider) => provider,
|
Some(provider) => provider,
|
||||||
None => ptr::null(),
|
None => ptr::null(),
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,8 @@ pub unsafe extern "C" fn dc_provider_new_from_domain(
|
|||||||
pub unsafe extern "C" fn dc_provider_new_from_email(
|
pub unsafe extern "C" fn dc_provider_new_from_email(
|
||||||
email: *const libc::c_char,
|
email: *const libc::c_char,
|
||||||
) -> *const dc_provider_t {
|
) -> *const dc_provider_t {
|
||||||
let domain = deltachat_provider_database::get_domain_from_email(as_str(email));
|
let email = to_string_lossy(email);
|
||||||
|
let domain = deltachat_provider_database::get_domain_from_email(&email);
|
||||||
match deltachat_provider_database::get_provider_info(domain) {
|
match deltachat_provider_database::get_provider_info(domain) {
|
||||||
Some(provider) => provider,
|
Some(provider) => provider,
|
||||||
None => ptr::null(),
|
None => ptr::null(),
|
||||||
|
|||||||
@@ -630,7 +630,7 @@ impl<'a> MimeParser<'a> {
|
|||||||
self.context,
|
self.context,
|
||||||
"Cannot convert {} bytes from \"{}\" to \"utf-8\".",
|
"Cannot convert {} bytes from \"{}\" to \"utf-8\".",
|
||||||
decoded_data.len(),
|
decoded_data.len(),
|
||||||
as_str(charset),
|
to_string_lossy(charset),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -729,8 +729,10 @@ impl<'a> MimeParser<'a> {
|
|||||||
if !(*mime).mm_content_type.is_null()
|
if !(*mime).mm_content_type.is_null()
|
||||||
&& !(*(*mime).mm_content_type).ct_subtype.is_null()
|
&& !(*(*mime).mm_content_type).ct_subtype.is_null()
|
||||||
{
|
{
|
||||||
desired_filename =
|
desired_filename = format!(
|
||||||
format!("file.{}", as_str((*(*mime).mm_content_type).ct_subtype));
|
"file.{}",
|
||||||
|
to_string_lossy((*(*mime).mm_content_type).ct_subtype)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -850,7 +852,8 @@ impl<'a> MimeParser<'a> {
|
|||||||
}) as *mut mailimf_mailbox;
|
}) as *mut mailimf_mailbox;
|
||||||
|
|
||||||
if !mb.is_null() {
|
if !mb.is_null() {
|
||||||
let from_addr_norm = addr_normalize(as_str((*mb).mb_addr_spec));
|
let from_addr = to_string_lossy((*mb).mb_addr_spec);
|
||||||
|
let from_addr_norm = addr_normalize(&from_addr);
|
||||||
let recipients = wrapmime::mailimf_get_recipients(self.header_root);
|
let recipients = wrapmime::mailimf_get_recipients(self.header_root);
|
||||||
if recipients.len() == 1 && recipients.contains(from_addr_norm) {
|
if recipients.len() == 1 && recipients.contains(from_addr_norm) {
|
||||||
sender_equals_recipient = true;
|
sender_equals_recipient = true;
|
||||||
|
|||||||
@@ -808,9 +808,9 @@ unsafe fn handle_reports(
|
|||||||
&& !of_org_msgid.is_null()
|
&& !of_org_msgid.is_null()
|
||||||
&& !(*of_org_msgid).fld_value.is_null()
|
&& !(*of_org_msgid).fld_value.is_null()
|
||||||
{
|
{
|
||||||
if let Ok(rfc724_mid) = wrapmime::parse_message_id(as_str(
|
if let Ok(rfc724_mid) = wrapmime::parse_message_id(
|
||||||
(*of_org_msgid).fld_value,
|
&to_string_lossy((*of_org_msgid).fld_value),
|
||||||
)) {
|
) {
|
||||||
if let Some((chat_id, msg_id)) = message::mdn_from_ext(
|
if let Some((chat_id, msg_id)) = message::mdn_from_ext(
|
||||||
context,
|
context,
|
||||||
from_id,
|
from_id,
|
||||||
@@ -993,7 +993,7 @@ unsafe fn create_or_lookup_group(
|
|||||||
let fld_message_id = (*field).fld_data.fld_message_id;
|
let fld_message_id = (*field).fld_data.fld_message_id;
|
||||||
if !fld_message_id.is_null() {
|
if !fld_message_id.is_null() {
|
||||||
if let Some(extracted_grpid) =
|
if let Some(extracted_grpid) =
|
||||||
dc_extract_grpid_from_rfc724_mid(as_str((*fld_message_id).mid_value))
|
dc_extract_grpid_from_rfc724_mid(&to_string_lossy((*fld_message_id).mid_value))
|
||||||
{
|
{
|
||||||
grpid = extracted_grpid.to_string();
|
grpid = extracted_grpid.to_string();
|
||||||
} else {
|
} else {
|
||||||
@@ -1731,7 +1731,7 @@ fn is_known_rfc724_mid(context: &Context, rfc724_mid: *const libc::c_char) -> li
|
|||||||
LEFT JOIN chats c ON m.chat_id=c.id \
|
LEFT JOIN chats c ON m.chat_id=c.id \
|
||||||
WHERE m.rfc724_mid=? \
|
WHERE m.rfc724_mid=? \
|
||||||
AND m.chat_id>9 AND c.blocked=0;",
|
AND m.chat_id>9 AND c.blocked=0;",
|
||||||
params![as_str(rfc724_mid)],
|
params![to_string_lossy(rfc724_mid)],
|
||||||
)
|
)
|
||||||
.unwrap_or_default() as libc::c_int
|
.unwrap_or_default() as libc::c_int
|
||||||
}
|
}
|
||||||
@@ -1783,11 +1783,7 @@ unsafe fn is_msgrmsg_rfc724_mid_in_list(context: &Context, mid_list: *const clis
|
|||||||
while !cur.is_null() {
|
while !cur.is_null() {
|
||||||
if 0 != is_msgrmsg_rfc724_mid(
|
if 0 != is_msgrmsg_rfc724_mid(
|
||||||
context,
|
context,
|
||||||
if !cur.is_null() {
|
&to_string_lossy((*cur).data as *const libc::c_char),
|
||||||
as_str((*cur).data as *const libc::c_char)
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
},
|
|
||||||
) {
|
) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -1923,7 +1919,7 @@ unsafe fn add_or_lookup_contact_by_addr(
|
|||||||
.get_config(Config::ConfiguredAddr)
|
.get_config(Config::ConfiguredAddr)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
if addr_cmp(self_addr, as_str(addr_spec)) {
|
if addr_cmp(self_addr, to_string_lossy(addr_spec)) {
|
||||||
*check_self = 1;
|
*check_self = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1933,13 +1929,18 @@ unsafe fn add_or_lookup_contact_by_addr(
|
|||||||
/* add addr_spec if missing, update otherwise */
|
/* add addr_spec if missing, update otherwise */
|
||||||
let mut display_name_dec = "".to_string();
|
let mut display_name_dec = "".to_string();
|
||||||
if !display_name_enc.is_null() {
|
if !display_name_enc.is_null() {
|
||||||
let tmp = dc_decode_header_words(as_str(display_name_enc));
|
let tmp = dc_decode_header_words(&to_string_lossy(display_name_enc));
|
||||||
display_name_dec = normalize_name(&tmp);
|
display_name_dec = normalize_name(&tmp);
|
||||||
}
|
}
|
||||||
/*can be NULL*/
|
/*can be NULL*/
|
||||||
let row_id = Contact::add_or_lookup(context, display_name_dec, as_str(addr_spec), origin)
|
let row_id = Contact::add_or_lookup(
|
||||||
.map(|(id, _)| id)
|
context,
|
||||||
.unwrap_or_default();
|
display_name_dec,
|
||||||
|
to_string_lossy(addr_spec),
|
||||||
|
origin,
|
||||||
|
)
|
||||||
|
.map(|(id, _)| id)
|
||||||
|
.unwrap_or_default();
|
||||||
if 0 != row_id && !ids.contains(&row_id) {
|
if 0 != row_id && !ids.contains(&row_id) {
|
||||||
ids.push(row_id);
|
ids.push(row_id);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ pub(crate) fn dc_str_from_clist(list: *const clist, delimiter: &str) -> String {
|
|||||||
if !res.is_empty() {
|
if !res.is_empty() {
|
||||||
res += delimiter;
|
res += delimiter;
|
||||||
}
|
}
|
||||||
res += as_str(rfc724_mid as *const libc::c_char);
|
res += &to_string_lossy(rfc724_mid as *const libc::c_char);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
@@ -303,9 +303,9 @@ pub(crate) fn dc_extract_grpid_from_rfc724_mid_list(list: *const clist) -> *mut
|
|||||||
if !list.is_null() {
|
if !list.is_null() {
|
||||||
unsafe {
|
unsafe {
|
||||||
for cur in (*list).into_iter() {
|
for cur in (*list).into_iter() {
|
||||||
let mid = as_str(cur as *const libc::c_char);
|
let mid = to_string_lossy(cur as *const libc::c_char);
|
||||||
|
|
||||||
if let Some(grpid) = dc_extract_grpid_from_rfc724_mid(mid) {
|
if let Some(grpid) = dc_extract_grpid_from_rfc724_mid(&mid) {
|
||||||
return grpid.strdup();
|
return grpid.strdup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -449,7 +449,7 @@ fn update_gossip_peerstates(
|
|||||||
|
|
||||||
let optional_field = unsafe { *optional_field };
|
let optional_field = unsafe { *optional_field };
|
||||||
if !optional_field.fld_name.is_null()
|
if !optional_field.fld_name.is_null()
|
||||||
&& as_str(optional_field.fld_name) == "Autocrypt-Gossip"
|
&& to_string_lossy(optional_field.fld_name) == "Autocrypt-Gossip"
|
||||||
{
|
{
|
||||||
let value = to_string_lossy(optional_field.fld_value);
|
let value = to_string_lossy(optional_field.fld_value);
|
||||||
let gossip_header = Aheader::from_str(&value);
|
let gossip_header = Aheader::from_str(&value);
|
||||||
@@ -655,7 +655,7 @@ fn contains_report(mime: *mut Mailmime) -> bool {
|
|||||||
|
|
||||||
if tp_type == MAILMIME_TYPE_COMPOSITE_TYPE as libc::c_int
|
if tp_type == MAILMIME_TYPE_COMPOSITE_TYPE as libc::c_int
|
||||||
&& ct_type == MAILMIME_COMPOSITE_TYPE_MULTIPART as libc::c_int
|
&& ct_type == MAILMIME_COMPOSITE_TYPE_MULTIPART as libc::c_int
|
||||||
&& as_str(unsafe { (*mime.mm_content_type).ct_subtype }) == "report"
|
&& to_string_lossy(unsafe { (*mime.mm_content_type).ct_subtype }) == "report"
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,7 +143,8 @@ pub fn get_field_date(imffields: *mut mailimf_fields) -> Result<i64, Error> {
|
|||||||
|
|
||||||
fn mailimf_get_recipients_add_addr(recipients: &mut HashSet<String>, mb: *mut mailimf_mailbox) {
|
fn mailimf_get_recipients_add_addr(recipients: &mut HashSet<String>, mb: *mut mailimf_mailbox) {
|
||||||
if !mb.is_null() {
|
if !mb.is_null() {
|
||||||
let addr_norm = addr_normalize(as_str(unsafe { (*mb).mb_addr_spec }));
|
let addr = to_string_lossy(unsafe { (*mb).mb_addr_spec });
|
||||||
|
let addr_norm = addr_normalize(&addr);
|
||||||
recipients.insert(addr_norm.into());
|
recipients.insert(addr_norm.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -382,8 +383,8 @@ pub fn mailimf_find_first_addr(mb_list: *const mailimf_mailbox_list) -> Option<S
|
|||||||
for cur in unsafe { (*(*mb_list).mb_list).into_iter() } {
|
for cur in unsafe { (*(*mb_list).mb_list).into_iter() } {
|
||||||
let mb = cur as *mut mailimf_mailbox;
|
let mb = cur as *mut mailimf_mailbox;
|
||||||
if !mb.is_null() && !unsafe { (*mb).mb_addr_spec.is_null() } {
|
if !mb.is_null() && !unsafe { (*mb).mb_addr_spec.is_null() } {
|
||||||
let addr = unsafe { as_str((*mb).mb_addr_spec) };
|
let addr = unsafe { to_string_lossy((*mb).mb_addr_spec) };
|
||||||
return Some(addr_normalize(addr).to_string());
|
return Some(addr_normalize(&addr).to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -489,7 +490,9 @@ pub fn content_type_needs_encoding(content: *const mailmime_content) -> bool {
|
|||||||
if (*(*content).ct_type).tp_type == MAILMIME_TYPE_COMPOSITE_TYPE as libc::c_int {
|
if (*(*content).ct_type).tp_type == MAILMIME_TYPE_COMPOSITE_TYPE as libc::c_int {
|
||||||
let composite = (*(*content).ct_type).tp_data.tp_composite_type;
|
let composite = (*(*content).ct_type).tp_data.tp_composite_type;
|
||||||
match (*composite).ct_type as u32 {
|
match (*composite).ct_type as u32 {
|
||||||
MAILMIME_COMPOSITE_TYPE_MESSAGE => as_str((*content).ct_subtype) != "rfc822",
|
MAILMIME_COMPOSITE_TYPE_MESSAGE => {
|
||||||
|
to_string_lossy((*content).ct_subtype) != "rfc822"
|
||||||
|
}
|
||||||
MAILMIME_COMPOSITE_TYPE_MULTIPART => false,
|
MAILMIME_COMPOSITE_TYPE_MULTIPART => false,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user