Rustify type of dc_mimepart_t.msg_raw

This commit is contained in:
Dmitry Bogatov
2019-09-06 04:06:40 +00:00
parent 28cfe36f43
commit 1d75f8478c
2 changed files with 14 additions and 8 deletions

View File

@@ -35,7 +35,7 @@ pub struct dc_mimepart_t {
pub is_meta: bool, pub is_meta: bool,
pub int_mimetype: libc::c_int, pub int_mimetype: libc::c_int,
pub msg: Option<String>, pub msg: Option<String>,
pub msg_raw: *mut libc::c_char, pub msg_raw: Option<String>,
pub bytes: libc::c_int, pub bytes: libc::c_int,
pub param: Params, pub param: Params,
} }
@@ -116,8 +116,7 @@ unsafe fn dc_mimeparser_empty(mimeparser: &mut dc_mimeparser_t) {
unsafe fn dc_mimepart_unref(mut mimepart: dc_mimepart_t) { unsafe fn dc_mimepart_unref(mut mimepart: dc_mimepart_t) {
mimepart.msg = None; mimepart.msg = None;
free(mimepart.msg_raw as *mut libc::c_void); mimepart.msg_raw = None;
mimepart.msg_raw = ptr::null_mut();
} }
const DC_MIMETYPE_AC_SETUP_FILE: i32 = 111; const DC_MIMETYPE_AC_SETUP_FILE: i32 = 111;
@@ -369,7 +368,7 @@ unsafe fn dc_mimepart_new() -> dc_mimepart_t {
is_meta: false, is_meta: false,
int_mimetype: 0, int_mimetype: 0,
msg: None, msg: None,
msg_raw: std::ptr::null_mut(), msg_raw: None,
bytes: 0, bytes: 0,
param: Params::new(), param: Params::new(),
} }
@@ -592,7 +591,7 @@ unsafe fn dc_mimeparser_parse_mime_recursive(
.stock_str(StockMessage::CantDecryptMsgBody); .stock_str(StockMessage::CantDecryptMsgBody);
let txt = format!("[{}]", msg_body); let txt = format!("[{}]", msg_body);
part.msg_raw = txt.strdup(); part.msg_raw = Some(txt.clone());
part.msg = Some(txt); part.msg = Some(txt);
mimeparser.parts.push(part); mimeparser.parts.push(part);
@@ -1120,8 +1119,13 @@ unsafe fn dc_mimeparser_add_single_part_if_known(
part.type_0 = Viewtype::Text; part.type_0 = Viewtype::Text;
part.int_mimetype = mime_type; part.int_mimetype = mime_type;
part.msg = Some(simplified_txt); part.msg = Some(simplified_txt);
part.msg_raw = part.msg_raw = {
let raw_c =
strndup(decoded_data, decoded_data_bytes as libc::c_ulong); strndup(decoded_data, decoded_data_bytes as libc::c_ulong);
let raw = to_string(raw_c);
free(raw_c.cast());
Some(raw)
};
do_add_single_part(mimeparser, part); do_add_single_part(mimeparser, part);
} }

View File

@@ -1,3 +1,4 @@
use std::ffi::CString;
use std::ptr; use std::ptr;
use itertools::join; use itertools::join;
@@ -641,6 +642,7 @@ unsafe fn add_parts(
} }
} }
if part.type_0 == Viewtype::Text { if part.type_0 == Viewtype::Text {
let msg_raw = CString::yolo(part.msg_raw.as_ref().unwrap().clone());
txt_raw = dc_mprintf( txt_raw = dc_mprintf(
b"%s\n\n%s\x00" as *const u8 as *const libc::c_char, b"%s\n\n%s\x00" as *const u8 as *const libc::c_char,
if !mime_parser.subject.is_null() { if !mime_parser.subject.is_null() {
@@ -648,7 +650,7 @@ unsafe fn add_parts(
} else { } else {
b"\x00" as *const u8 as *const libc::c_char b"\x00" as *const u8 as *const libc::c_char
}, },
part.msg_raw, msg_raw.as_ptr(),
) )
} }
if 0 != mime_parser.is_system_message { if 0 != mime_parser.is_system_message {