mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 10:56:29 +03:00
refactor: make dc_dehtml() function safe
* Make dc_dehtml() function safe
* Change type of is_msgrmsg parameter to bool
* Narrow type of local variable in simplify_plain_text()
* Export less fields of `Simplify' record
* Demote is_cut_* from fields of `Simplify' to local variables
* Refactor part of simplify_plain_text()
Refactor footer ("-- " and similar) code into separate function,
and re-implement it with standard Rust string methods.
It simplifies code and allows removing one mutable local variable.
* Replace dc_split_into_lines with String.split()
* src/dc_simplify.rs(find_message_footer): adjust type signature to accept
slice of &str, not slice of pointers
* src/dc_simplify.rs(simplify_plain_text): adjust code to use '==' operator
instead of strcmp(3).
* src/dc_simplify.rs(is_empty_line, is_quoted_headline, is_plain_quote):
+ adjust type signatures to accept &str, not 'const char *'
+ remove no longer needed 'unsafe' qualifier
* src/dc_tools(dc_split_into_lines, dc_free_splitted_lines): remove no longer
used functions.
In addition to additional type-safety, this change reduces number of
allocations: String.split returns iterator of &str.
* Make simplify_plain_text() safe
* Make Simplify.simplify return String, not pointer
* Refactor Simplify.simplify to use String methods, not pointers
* Make Simplify.simplify() safe
* Avoid neeless allocation in Simplify.simplify when input is html
* Add tests for simplify utilities
* Document discussion about is_empty_line() discussion
This commit is contained in:
committed by
Friedel Ziegelmayer
parent
8a73f84003
commit
d7d7147549
@@ -1154,28 +1154,30 @@ unsafe fn dc_mimeparser_add_single_part_if_known(
|
||||
if ok_to_continue {
|
||||
/* check header directly as is_send_by_messenger is not yet set up */
|
||||
let is_msgrmsg =
|
||||
(!dc_mimeparser_lookup_optional_field(&mimeparser, "Chat-Version")
|
||||
.is_null()) as libc::c_int;
|
||||
!dc_mimeparser_lookup_optional_field(&mimeparser, "Chat-Version")
|
||||
.is_null();
|
||||
|
||||
let simplified_txt = simplifier.unwrap().simplify(
|
||||
decoded_data,
|
||||
decoded_data_bytes as libc::c_int,
|
||||
mime_type == 70i32,
|
||||
is_msgrmsg,
|
||||
);
|
||||
if !simplified_txt.is_null()
|
||||
&& 0 != *simplified_txt.offset(0isize) as libc::c_int
|
||||
{
|
||||
let simplified_txt =
|
||||
if decoded_data_bytes <= 0 || decoded_data.is_null() {
|
||||
"".into()
|
||||
} else {
|
||||
let input_c = strndup(decoded_data, decoded_data_bytes as _);
|
||||
let input = to_string_lossy(input_c);
|
||||
let is_html = mime_type == 70;
|
||||
free(input_c as *mut _);
|
||||
|
||||
simplifier.unwrap().simplify(&input, is_html, is_msgrmsg)
|
||||
};
|
||||
if !simplified_txt.is_empty() {
|
||||
let mut part = dc_mimepart_new();
|
||||
part.type_0 = 10i32;
|
||||
part.int_mimetype = mime_type;
|
||||
part.msg = simplified_txt;
|
||||
part.msg = simplified_txt.strdup();
|
||||
part.msg_raw =
|
||||
strndup(decoded_data, decoded_data_bytes as libc::c_ulong);
|
||||
do_add_single_part(mimeparser, part);
|
||||
} else {
|
||||
free(simplified_txt as *mut libc::c_void);
|
||||
}
|
||||
|
||||
if simplifier.unwrap().is_forwarded {
|
||||
mimeparser.is_forwarded = 1i32
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user