mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
Change type of dc_mimepart_t.msg to Option<String>
This commit is contained in:
committed by
Floris Bruynooghe
parent
b3df24d188
commit
eca11a74d7
@@ -34,7 +34,7 @@ pub struct dc_mimepart_t {
|
|||||||
pub type_0: Viewtype,
|
pub type_0: Viewtype,
|
||||||
pub is_meta: libc::c_int,
|
pub is_meta: libc::c_int,
|
||||||
pub int_mimetype: libc::c_int,
|
pub int_mimetype: libc::c_int,
|
||||||
pub msg: *mut libc::c_char,
|
pub msg: Option<String>,
|
||||||
pub msg_raw: *mut libc::c_char,
|
pub msg_raw: *mut libc::c_char,
|
||||||
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) {
|
||||||
free(mimepart.msg as *mut libc::c_void);
|
mimepart.msg = None;
|
||||||
mimepart.msg = 0 as *mut libc::c_char;
|
|
||||||
free(mimepart.msg_raw as *mut libc::c_void);
|
free(mimepart.msg_raw as *mut libc::c_void);
|
||||||
mimepart.msg_raw = 0 as *mut libc::c_char;
|
mimepart.msg_raw = 0 as *mut libc::c_char;
|
||||||
}
|
}
|
||||||
@@ -222,14 +221,11 @@ pub unsafe fn dc_mimeparser_parse<'a>(context: &'a Context, body: &[u8]) -> dc_m
|
|||||||
if need_drop {
|
if need_drop {
|
||||||
let mut filepart = mimeparser.parts.swap_remove(1);
|
let mut filepart = mimeparser.parts.swap_remove(1);
|
||||||
|
|
||||||
// clear old one
|
|
||||||
free(filepart.msg as *mut libc::c_void);
|
|
||||||
|
|
||||||
// insert new one
|
// insert new one
|
||||||
filepart.msg = mimeparser.parts[0].msg;
|
filepart.msg = mimeparser.parts[0].msg.as_ref().map(|s| s.to_string());
|
||||||
|
|
||||||
// forget the one we use now
|
// forget the one we use now
|
||||||
mimeparser.parts[0].msg = std::ptr::null_mut();
|
mimeparser.parts[0].msg = None;
|
||||||
|
|
||||||
// swap new with old
|
// swap new with old
|
||||||
let old = std::mem::replace(&mut mimeparser.parts[0], filepart);
|
let old = std::mem::replace(&mut mimeparser.parts[0], filepart);
|
||||||
@@ -264,13 +260,15 @@ pub unsafe fn dc_mimeparser_parse<'a>(context: &'a Context, body: &[u8]) -> dc_m
|
|||||||
if 0 != *subj.offset(0isize) {
|
if 0 != *subj.offset(0isize) {
|
||||||
for part in mimeparser.parts.iter_mut() {
|
for part in mimeparser.parts.iter_mut() {
|
||||||
if part.type_0 == Viewtype::Text {
|
if part.type_0 == Viewtype::Text {
|
||||||
|
let msg_c = part.msg.as_ref().unwrap().strdup();
|
||||||
let new_txt: *mut libc::c_char = dc_mprintf(
|
let new_txt: *mut libc::c_char = dc_mprintf(
|
||||||
b"%s \xe2\x80\x93 %s\x00" as *const u8 as *const libc::c_char,
|
b"%s \xe2\x80\x93 %s\x00" as *const u8 as *const libc::c_char,
|
||||||
subj,
|
subj,
|
||||||
part.msg,
|
msg_c,
|
||||||
);
|
);
|
||||||
free(part.msg as *mut libc::c_void);
|
free(msg_c.cast());
|
||||||
part.msg = new_txt;
|
part.msg = Some(to_string(new_txt));
|
||||||
|
free(new_txt.cast());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -356,9 +354,9 @@ pub unsafe fn dc_mimeparser_parse<'a>(context: &'a Context, body: &[u8]) -> dc_m
|
|||||||
let mut part_5 = dc_mimepart_new();
|
let mut part_5 = dc_mimepart_new();
|
||||||
part_5.type_0 = Viewtype::Text;
|
part_5.type_0 = Viewtype::Text;
|
||||||
if !mimeparser.subject.is_null() && !mimeparser.is_send_by_messenger {
|
if !mimeparser.subject.is_null() && !mimeparser.is_send_by_messenger {
|
||||||
part_5.msg = dc_strdup(mimeparser.subject)
|
part_5.msg = Some(to_string(mimeparser.subject));
|
||||||
} else {
|
} else {
|
||||||
part_5.msg = dc_strdup(b"\x00" as *const u8 as *const libc::c_char)
|
part_5.msg = Some("".into());
|
||||||
}
|
}
|
||||||
mimeparser.parts.push(part_5);
|
mimeparser.parts.push(part_5);
|
||||||
};
|
};
|
||||||
@@ -373,7 +371,7 @@ unsafe fn dc_mimepart_new() -> dc_mimepart_t {
|
|||||||
type_0: Viewtype::Unknown,
|
type_0: Viewtype::Unknown,
|
||||||
is_meta: 0,
|
is_meta: 0,
|
||||||
int_mimetype: 0,
|
int_mimetype: 0,
|
||||||
msg: std::ptr::null_mut(),
|
msg: None,
|
||||||
msg_raw: std::ptr::null_mut(),
|
msg_raw: std::ptr::null_mut(),
|
||||||
bytes: 0,
|
bytes: 0,
|
||||||
param: Params::new(),
|
param: Params::new(),
|
||||||
@@ -602,18 +600,14 @@ unsafe fn dc_mimeparser_parse_mime_recursive(
|
|||||||
40 => {
|
40 => {
|
||||||
let mut part = dc_mimepart_new();
|
let mut part = dc_mimepart_new();
|
||||||
part.type_0 = Viewtype::Text;
|
part.type_0 = Viewtype::Text;
|
||||||
let msg_body = CString::new(
|
let msg_body = mimeparser
|
||||||
mimeparser
|
.context
|
||||||
.context
|
.stock_str(StockMessage::CantDecryptMsgBody);
|
||||||
.stock_str(StockMessage::CantDecryptMsgBody)
|
|
||||||
.as_ref(),
|
let txt = format!("[{}]", msg_body);
|
||||||
)
|
part.msg_raw = txt.strdup();
|
||||||
.unwrap();
|
part.msg = Some(txt);
|
||||||
part.msg = dc_mprintf(
|
|
||||||
b"[%s]\x00" as *const u8 as *const libc::c_char,
|
|
||||||
msg_body.as_ptr(),
|
|
||||||
);
|
|
||||||
part.msg_raw = dc_strdup(part.msg);
|
|
||||||
mimeparser.parts.push(part);
|
mimeparser.parts.push(part);
|
||||||
any_part_added = 1i32;
|
any_part_added = 1i32;
|
||||||
mimeparser.decrypting_failed = 1i32
|
mimeparser.decrypting_failed = 1i32
|
||||||
@@ -1126,7 +1120,7 @@ unsafe fn dc_mimeparser_add_single_part_if_known(
|
|||||||
let mut part = dc_mimepart_new();
|
let mut part = dc_mimepart_new();
|
||||||
part.type_0 = Viewtype::Text;
|
part.type_0 = Viewtype::Text;
|
||||||
part.int_mimetype = mime_type;
|
part.int_mimetype = mime_type;
|
||||||
part.msg = simplified_txt.strdup();
|
part.msg = Some(simplified_txt);
|
||||||
part.msg_raw =
|
part.msg_raw =
|
||||||
strndup(decoded_data, decoded_data_bytes as libc::c_ulong);
|
strndup(decoded_data, decoded_data_bytes as libc::c_ulong);
|
||||||
do_add_single_part(mimeparser, part);
|
do_add_single_part(mimeparser, part);
|
||||||
@@ -1657,8 +1651,7 @@ pub unsafe fn dc_mimeparser_repl_msg_by_error(
|
|||||||
}
|
}
|
||||||
let part = &mut mimeparser.parts[0];
|
let part = &mut mimeparser.parts[0];
|
||||||
part.type_0 = Viewtype::Text;
|
part.type_0 = Viewtype::Text;
|
||||||
free(part.msg as *mut libc::c_void);
|
part.msg = Some(format!("[{}]", to_string(error_msg)));
|
||||||
part.msg = dc_mprintf(b"[%s]\x00" as *const u8 as *const libc::c_char, error_msg);
|
|
||||||
for part in mimeparser.parts.drain(1..) {
|
for part in mimeparser.parts.drain(1..) {
|
||||||
dc_mimepart_unref(part);
|
dc_mimepart_unref(part);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -630,18 +630,15 @@ unsafe fn add_parts(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !mime_parser.location_kml.is_none()
|
if let Some(ref msg) = part.msg {
|
||||||
&& icnt == 1
|
if !mime_parser.location_kml.is_none()
|
||||||
&& !part.msg.is_null()
|
&& icnt == 1
|
||||||
&& (strcmp(
|
&& (msg == "-location-" || msg.is_empty())
|
||||||
part.msg,
|
{
|
||||||
b"-location-\x00" as *const u8 as *const libc::c_char,
|
*hidden = 1;
|
||||||
) == 0
|
if state == MessageState::InFresh {
|
||||||
|| *part.msg.offset(0) as libc::c_int == 0)
|
state = MessageState::InNoticed;
|
||||||
{
|
}
|
||||||
*hidden = 1;
|
|
||||||
if state == MessageState::InFresh {
|
|
||||||
state = MessageState::InNoticed;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if part.type_0 == Viewtype::Text {
|
if part.type_0 == Viewtype::Text {
|
||||||
@@ -673,11 +670,7 @@ unsafe fn add_parts(
|
|||||||
part.type_0,
|
part.type_0,
|
||||||
state,
|
state,
|
||||||
msgrmsg,
|
msgrmsg,
|
||||||
if !part.msg.is_null() {
|
part.msg.as_ref().map_or("", String::as_str),
|
||||||
as_str(part.msg)
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
},
|
|
||||||
// txt_raw might contain invalid utf8
|
// txt_raw might contain invalid utf8
|
||||||
if !txt_raw.is_null() {
|
if !txt_raw.is_null() {
|
||||||
to_string_lossy(txt_raw)
|
to_string_lossy(txt_raw)
|
||||||
@@ -1861,8 +1854,7 @@ unsafe fn set_better_msg<T: AsRef<str>>(mime_parser: &mut dc_mimeparser_t, bette
|
|||||||
if msg.len() > 0 && !mime_parser.parts.is_empty() {
|
if msg.len() > 0 && !mime_parser.parts.is_empty() {
|
||||||
let part = &mut mime_parser.parts[0];
|
let part = &mut mime_parser.parts[0];
|
||||||
if (*part).type_0 == Viewtype::Text {
|
if (*part).type_0 == Viewtype::Text {
|
||||||
free(part.msg as *mut libc::c_void);
|
part.msg = Some(msg.to_string());
|
||||||
part.msg = msg.strdup();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user