mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
refactor(mimeparser): some more sanity
This commit is contained in:
1565
src/dc_mimeparser.rs
1565
src/dc_mimeparser.rs
File diff suppressed because it is too large
Load Diff
@@ -63,7 +63,8 @@ pub unsafe fn dc_receive_imf(
|
|||||||
// somewhen, I did not found out anything that speaks against this approach yet)
|
// somewhen, I did not found out anything that speaks against this approach yet)
|
||||||
|
|
||||||
let body = std::slice::from_raw_parts(imf_raw_not_terminated as *const u8, imf_raw_bytes);
|
let body = std::slice::from_raw_parts(imf_raw_not_terminated as *const u8, imf_raw_bytes);
|
||||||
let mut mime_parser = dc_mimeparser_parse(context, body);
|
let mut mime_parser = MimeParser::new(context);
|
||||||
|
mime_parser.parse(body);
|
||||||
|
|
||||||
if mime_parser.header.is_empty() {
|
if mime_parser.header.is_empty() {
|
||||||
// Error - even adding an empty record won't help as we do not know the message ID
|
// Error - even adding an empty record won't help as we do not know the message ID
|
||||||
@@ -149,7 +150,7 @@ pub unsafe fn dc_receive_imf(
|
|||||||
);
|
);
|
||||||
if 0 != check_self {
|
if 0 != check_self {
|
||||||
incoming = 0;
|
incoming = 0;
|
||||||
if 0 != dc_mimeparser_sender_equals_recipient(&mime_parser) {
|
if mime_parser.sender_equals_recipient() {
|
||||||
from_id = DC_CONTACT_ID_SELF;
|
from_id = DC_CONTACT_ID_SELF;
|
||||||
}
|
}
|
||||||
} else if from_list.len() >= 1 {
|
} else if from_list.len() >= 1 {
|
||||||
@@ -183,7 +184,7 @@ pub unsafe fn dc_receive_imf(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add parts
|
// Add parts
|
||||||
if dc_mimeparser_get_last_nonmeta(&mut mime_parser).is_some() {
|
if mime_parser.get_last_nonmeta().is_some() {
|
||||||
if let Err(err) = add_parts(
|
if let Err(err) = add_parts(
|
||||||
context,
|
context,
|
||||||
&mut mime_parser,
|
&mut mime_parser,
|
||||||
@@ -278,7 +279,7 @@ pub unsafe fn dc_receive_imf(
|
|||||||
|
|
||||||
unsafe fn add_parts(
|
unsafe fn add_parts(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
mut mime_parser: &mut dc_mimeparser_t,
|
mut mime_parser: &mut MimeParser,
|
||||||
imf_raw_not_terminated: *const libc::c_char,
|
imf_raw_not_terminated: *const libc::c_char,
|
||||||
imf_raw_bytes: libc::size_t,
|
imf_raw_bytes: libc::size_t,
|
||||||
incoming: i32,
|
incoming: i32,
|
||||||
@@ -414,7 +415,7 @@ unsafe fn add_parts(
|
|||||||
*to_id = 1;
|
*to_id = 1;
|
||||||
// handshake messages must be processed _before_ chats are created
|
// handshake messages must be processed _before_ chats are created
|
||||||
// (eg. contacs may be marked as verified)
|
// (eg. contacs may be marked as verified)
|
||||||
if !dc_mimeparser_lookup_field(mime_parser, "Secure-Join").is_null() {
|
if mime_parser.lookup_field("Secure-Join").is_some() {
|
||||||
// avoid discarding by show_emails setting
|
// avoid discarding by show_emails setting
|
||||||
msgrmsg = 1;
|
msgrmsg = 1;
|
||||||
*chat_id = 0;
|
*chat_id = 0;
|
||||||
@@ -463,7 +464,7 @@ unsafe fn add_parts(
|
|||||||
|
|
||||||
if *chat_id == 0 {
|
if *chat_id == 0 {
|
||||||
// check if the message belongs to a mailing list
|
// check if the message belongs to a mailing list
|
||||||
if dc_mimeparser_is_mailinglist_message(mime_parser) {
|
if mime_parser.is_mailinglist_message() {
|
||||||
*chat_id = 3;
|
*chat_id = 3;
|
||||||
info!(context, "Message belongs to a mailing list and is ignored.",);
|
info!(context, "Message belongs to a mailing list and is ignored.",);
|
||||||
}
|
}
|
||||||
@@ -656,7 +657,7 @@ unsafe fn add_parts(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if part.type_0 == Viewtype::Text {
|
if part.typ == Viewtype::Text {
|
||||||
let msg_raw =
|
let msg_raw =
|
||||||
CString::yolo(part.msg_raw.as_ref().cloned().unwrap_or_default());
|
CString::yolo(part.msg_raw.as_ref().cloned().unwrap_or_default());
|
||||||
let subject_c = CString::yolo(
|
let subject_c = CString::yolo(
|
||||||
@@ -687,7 +688,7 @@ unsafe fn add_parts(
|
|||||||
sort_timestamp,
|
sort_timestamp,
|
||||||
*sent_timestamp,
|
*sent_timestamp,
|
||||||
rcvd_timestamp,
|
rcvd_timestamp,
|
||||||
part.type_0,
|
part.typ,
|
||||||
state,
|
state,
|
||||||
msgrmsg,
|
msgrmsg,
|
||||||
part.msg.as_ref().map_or("", String::as_str),
|
part.msg.as_ref().map_or("", String::as_str),
|
||||||
@@ -762,23 +763,22 @@ unsafe fn add_parts(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Lookup a mime field given its name and type.
|
/// Lookup a mime field given its name and type.
|
||||||
unsafe fn lookup_field(
|
fn lookup_field(parser: &MimeParser, name: &str, typ: u32) -> Option<*const mailimf_field> {
|
||||||
parser: &dc_mimeparser_t,
|
if let Some(field) = parser.lookup_field(name) {
|
||||||
name: &str,
|
if unsafe { (*field).fld_type } == typ as libc::c_int {
|
||||||
typ: u32,
|
|
||||||
) -> Option<*const mailimf_field> {
|
|
||||||
let field = dc_mimeparser_lookup_field(parser, name);
|
|
||||||
if !field.is_null() && (*field).fld_type == typ as libc::c_int {
|
|
||||||
Some(field)
|
Some(field)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle reports (mainly MDNs)
|
// Handle reports (mainly MDNs)
|
||||||
unsafe fn handle_reports(
|
unsafe fn handle_reports(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
mime_parser: &dc_mimeparser_t,
|
mime_parser: &MimeParser,
|
||||||
from_id: u32,
|
from_id: u32,
|
||||||
sent_timestamp: i64,
|
sent_timestamp: i64,
|
||||||
rr_event_to_send: &mut Vec<(u32, u32)>,
|
rr_event_to_send: &mut Vec<(u32, u32)>,
|
||||||
@@ -941,7 +941,7 @@ unsafe fn handle_reports(
|
|||||||
|
|
||||||
fn save_locations(
|
fn save_locations(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
mime_parser: &dc_mimeparser_t,
|
mime_parser: &MimeParser,
|
||||||
chat_id: u32,
|
chat_id: u32,
|
||||||
from_id: u32,
|
from_id: u32,
|
||||||
insert_msg_id: u32,
|
insert_msg_id: u32,
|
||||||
@@ -1039,7 +1039,7 @@ unsafe fn calc_timestamps(
|
|||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
unsafe fn create_or_lookup_group(
|
unsafe fn create_or_lookup_group(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
mime_parser: &mut dc_mimeparser_t,
|
mime_parser: &mut MimeParser,
|
||||||
allow_creation: libc::c_int,
|
allow_creation: libc::c_int,
|
||||||
create_blocked: Blocked,
|
create_blocked: Blocked,
|
||||||
from_id: u32,
|
from_id: u32,
|
||||||
@@ -1062,16 +1062,13 @@ unsafe fn create_or_lookup_group(
|
|||||||
let mut X_MrGrpNameChanged = 0;
|
let mut X_MrGrpNameChanged = 0;
|
||||||
let mut X_MrGrpImageChanged = "".to_string();
|
let mut X_MrGrpImageChanged = "".to_string();
|
||||||
let mut better_msg: String = From::from("");
|
let mut better_msg: String = From::from("");
|
||||||
let mut failure_reason = std::ptr::null_mut();
|
|
||||||
|
|
||||||
let cleanup = |grpname: *mut libc::c_char,
|
let cleanup = |grpname: *mut libc::c_char,
|
||||||
failure_reason: *mut libc::c_char,
|
|
||||||
ret_chat_id: *mut u32,
|
ret_chat_id: *mut u32,
|
||||||
ret_chat_id_blocked: &mut Blocked,
|
ret_chat_id_blocked: &mut Blocked,
|
||||||
chat_id: u32,
|
chat_id: u32,
|
||||||
chat_id_blocked: Blocked| {
|
chat_id_blocked: Blocked| {
|
||||||
free(grpname.cast());
|
free(grpname.cast());
|
||||||
free(failure_reason.cast());
|
|
||||||
|
|
||||||
if !ret_chat_id.is_null() {
|
if !ret_chat_id.is_null() {
|
||||||
*ret_chat_id = chat_id;
|
*ret_chat_id = chat_id;
|
||||||
@@ -1089,10 +1086,10 @@ unsafe fn create_or_lookup_group(
|
|||||||
}
|
}
|
||||||
set_better_msg(mime_parser, &better_msg);
|
set_better_msg(mime_parser, &better_msg);
|
||||||
|
|
||||||
let optional_field = dc_mimeparser_lookup_optional_field(mime_parser, "Chat-Group-ID");
|
if let Some(optional_field) = mime_parser.lookup_optional_field("Chat-Group-ID") {
|
||||||
if !optional_field.is_null() {
|
grpid = to_string((*optional_field).fld_value);
|
||||||
grpid = to_string((*optional_field).fld_value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if grpid.is_empty() {
|
if grpid.is_empty() {
|
||||||
if let Some(field) = lookup_field(mime_parser, "Message-ID", MAILIMF_FIELD_MESSAGE_ID) {
|
if let Some(field) = lookup_field(mime_parser, "Message-ID", MAILIMF_FIELD_MESSAGE_ID) {
|
||||||
let fld_message_id = (*field).fld_data.fld_message_id;
|
let fld_message_id = (*field).fld_data.fld_message_id;
|
||||||
@@ -1141,7 +1138,6 @@ unsafe fn create_or_lookup_group(
|
|||||||
);
|
);
|
||||||
cleanup(
|
cleanup(
|
||||||
grpname,
|
grpname,
|
||||||
failure_reason,
|
|
||||||
ret_chat_id,
|
ret_chat_id,
|
||||||
ret_chat_id_blocked,
|
ret_chat_id_blocked,
|
||||||
chat_id,
|
chat_id,
|
||||||
@@ -1153,13 +1149,10 @@ unsafe fn create_or_lookup_group(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let optional_field = dc_mimeparser_lookup_optional_field(mime_parser, "Chat-Group-Name");
|
if let Some(optional_field) = mime_parser.lookup_optional_field("Chat-Group-Name") {
|
||||||
if !optional_field.is_null() {
|
grpname = dc_decode_header_words((*optional_field).fld_value);
|
||||||
grpname = dc_decode_header_words((*optional_field).fld_value)
|
|
||||||
}
|
}
|
||||||
let optional_field =
|
if let Some(optional_field) = mime_parser.lookup_optional_field("Chat-Group-Member-Removed") {
|
||||||
dc_mimeparser_lookup_optional_field(mime_parser, "Chat-Group-Member-Removed");
|
|
||||||
if !optional_field.is_null() {
|
|
||||||
X_MrRemoveFromGrp = (*optional_field).fld_value;
|
X_MrRemoveFromGrp = (*optional_field).fld_value;
|
||||||
mime_parser.is_system_message = DC_CMD_MEMBER_REMOVED_FROM_GROUP;
|
mime_parser.is_system_message = DC_CMD_MEMBER_REMOVED_FROM_GROUP;
|
||||||
let left_group = (Contact::lookup_id_by_addr(context, as_str(X_MrRemoveFromGrp))
|
let left_group = (Contact::lookup_id_by_addr(context, as_str(X_MrRemoveFromGrp))
|
||||||
@@ -1175,14 +1168,10 @@ unsafe fn create_or_lookup_group(
|
|||||||
from_id as u32,
|
from_id as u32,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
let optional_field =
|
if let Some(optional_field) = mime_parser.lookup_optional_field("Chat-Group-Member-Added") {
|
||||||
dc_mimeparser_lookup_optional_field(mime_parser, "Chat-Group-Member-Added");
|
|
||||||
if !optional_field.is_null() {
|
|
||||||
X_MrAddToGrp = (*optional_field).fld_value;
|
X_MrAddToGrp = (*optional_field).fld_value;
|
||||||
mime_parser.is_system_message = DC_CMD_MEMBER_ADDED_TO_GROUP;
|
mime_parser.is_system_message = DC_CMD_MEMBER_ADDED_TO_GROUP;
|
||||||
let optional_field =
|
if let Some(optional_field) = mime_parser.lookup_optional_field("Chat-Group-Image") {
|
||||||
dc_mimeparser_lookup_optional_field(mime_parser, "Chat-Group-Image");
|
|
||||||
if !optional_field.is_null() {
|
|
||||||
// fld_value is a pointer somewhere into mime_parser, must not be freed
|
// fld_value is a pointer somewhere into mime_parser, must not be freed
|
||||||
X_MrGrpImageChanged = as_str((*optional_field).fld_value).to_string();
|
X_MrGrpImageChanged = as_str((*optional_field).fld_value).to_string();
|
||||||
}
|
}
|
||||||
@@ -1193,9 +1182,9 @@ unsafe fn create_or_lookup_group(
|
|||||||
from_id as u32,
|
from_id as u32,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
let optional_field =
|
if let Some(optional_field) =
|
||||||
dc_mimeparser_lookup_optional_field(mime_parser, "Chat-Group-Name-Changed");
|
mime_parser.lookup_optional_field("Chat-Group-Name-Changed")
|
||||||
if !optional_field.is_null() {
|
{
|
||||||
X_MrGrpNameChanged = 1;
|
X_MrGrpNameChanged = 1;
|
||||||
mime_parser.is_system_message = DC_CMD_GROUPNAME_CHANGED;
|
mime_parser.is_system_message = DC_CMD_GROUPNAME_CHANGED;
|
||||||
better_msg = context.stock_system_msg(
|
better_msg = context.stock_system_msg(
|
||||||
@@ -1205,9 +1194,8 @@ unsafe fn create_or_lookup_group(
|
|||||||
from_id as u32,
|
from_id as u32,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
let optional_field =
|
if let Some(optional_field) = mime_parser.lookup_optional_field("Chat-Group-Image")
|
||||||
dc_mimeparser_lookup_optional_field(mime_parser, "Chat-Group-Image");
|
{
|
||||||
if !optional_field.is_null() {
|
|
||||||
// fld_value is a pointer somewhere into mime_parser, must not be freed
|
// fld_value is a pointer somewhere into mime_parser, must not be freed
|
||||||
X_MrGrpImageChanged = as_str((*optional_field).fld_value).to_string();
|
X_MrGrpImageChanged = as_str((*optional_field).fld_value).to_string();
|
||||||
mime_parser.is_system_message = DC_CMD_GROUPIMAGE_CHANGED;
|
mime_parser.is_system_message = DC_CMD_GROUPIMAGE_CHANGED;
|
||||||
@@ -1230,6 +1218,8 @@ unsafe fn create_or_lookup_group(
|
|||||||
// check, if we have a chat with this group ID
|
// check, if we have a chat with this group ID
|
||||||
let (mut chat_id, chat_id_verified, _blocked) = chat::get_chat_id_by_grpid(context, &grpid);
|
let (mut chat_id, chat_id_verified, _blocked) = chat::get_chat_id_by_grpid(context, &grpid);
|
||||||
if chat_id != 0 {
|
if chat_id != 0 {
|
||||||
|
let mut failure_reason = std::ptr::null_mut();
|
||||||
|
|
||||||
if chat_id_verified
|
if chat_id_verified
|
||||||
&& 0 == check_verified_properties(
|
&& 0 == check_verified_properties(
|
||||||
context,
|
context,
|
||||||
@@ -1239,8 +1229,10 @@ unsafe fn create_or_lookup_group(
|
|||||||
&mut failure_reason,
|
&mut failure_reason,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
dc_mimeparser_repl_msg_by_error(mime_parser, failure_reason);
|
mime_parser.repl_msg_by_error(to_string(failure_reason));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(failure_reason.cast());
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the sender is a member of the existing group -
|
// check if the sender is a member of the existing group -
|
||||||
@@ -1257,7 +1249,7 @@ unsafe fn create_or_lookup_group(
|
|||||||
.get_config(context, "configured_addr")
|
.get_config(context, "configured_addr")
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
if chat_id == 0
|
if chat_id == 0
|
||||||
&& !dc_mimeparser_is_mailinglist_message(mime_parser)
|
&& !mime_parser.is_mailinglist_message()
|
||||||
&& !grpid.is_empty()
|
&& !grpid.is_empty()
|
||||||
&& !grpname.is_null()
|
&& !grpname.is_null()
|
||||||
// otherwise, a pending "quit" message may pop up
|
// otherwise, a pending "quit" message may pop up
|
||||||
@@ -1267,8 +1259,10 @@ unsafe fn create_or_lookup_group(
|
|||||||
|| !X_MrAddToGrp.is_null() && addr_cmp(&self_addr, as_str(X_MrAddToGrp)))
|
|| !X_MrAddToGrp.is_null() && addr_cmp(&self_addr, as_str(X_MrAddToGrp)))
|
||||||
{
|
{
|
||||||
let mut create_verified = VerifiedStatus::Unverified;
|
let mut create_verified = VerifiedStatus::Unverified;
|
||||||
if !dc_mimeparser_lookup_field(mime_parser, "Chat-Verified").is_null() {
|
if mime_parser.lookup_field("Chat-Verified").is_some() {
|
||||||
create_verified = VerifiedStatus::Verified;
|
create_verified = VerifiedStatus::Verified;
|
||||||
|
let mut failure_reason = std::ptr::null_mut();
|
||||||
|
|
||||||
if 0 == check_verified_properties(
|
if 0 == check_verified_properties(
|
||||||
context,
|
context,
|
||||||
mime_parser,
|
mime_parser,
|
||||||
@@ -1276,13 +1270,13 @@ unsafe fn create_or_lookup_group(
|
|||||||
to_ids,
|
to_ids,
|
||||||
&mut failure_reason,
|
&mut failure_reason,
|
||||||
) {
|
) {
|
||||||
dc_mimeparser_repl_msg_by_error(mime_parser, failure_reason);
|
mime_parser.repl_msg_by_error(to_string(failure_reason));
|
||||||
}
|
}
|
||||||
|
free(failure_reason.cast());
|
||||||
}
|
}
|
||||||
if 0 == allow_creation {
|
if 0 == allow_creation {
|
||||||
cleanup(
|
cleanup(
|
||||||
grpname,
|
grpname,
|
||||||
failure_reason,
|
|
||||||
ret_chat_id,
|
ret_chat_id,
|
||||||
ret_chat_id_blocked,
|
ret_chat_id_blocked,
|
||||||
chat_id,
|
chat_id,
|
||||||
@@ -1314,7 +1308,6 @@ unsafe fn create_or_lookup_group(
|
|||||||
}
|
}
|
||||||
cleanup(
|
cleanup(
|
||||||
grpname,
|
grpname,
|
||||||
failure_reason,
|
|
||||||
ret_chat_id,
|
ret_chat_id,
|
||||||
ret_chat_id_blocked,
|
ret_chat_id_blocked,
|
||||||
chat_id,
|
chat_id,
|
||||||
@@ -1350,7 +1343,7 @@ unsafe fn create_or_lookup_group(
|
|||||||
changed = true;
|
changed = true;
|
||||||
} else {
|
} else {
|
||||||
for part in &mut mime_parser.parts {
|
for part in &mut mime_parser.parts {
|
||||||
if part.type_0 == Viewtype::Image {
|
if part.typ == Viewtype::Image {
|
||||||
grpimage = part
|
grpimage = part
|
||||||
.param
|
.param
|
||||||
.get(Param::File)
|
.get(Param::File)
|
||||||
@@ -1444,7 +1437,6 @@ unsafe fn create_or_lookup_group(
|
|||||||
|
|
||||||
cleanup(
|
cleanup(
|
||||||
grpname,
|
grpname,
|
||||||
failure_reason,
|
|
||||||
ret_chat_id,
|
ret_chat_id,
|
||||||
ret_chat_id_blocked,
|
ret_chat_id_blocked,
|
||||||
chat_id,
|
chat_id,
|
||||||
@@ -1455,7 +1447,7 @@ unsafe fn create_or_lookup_group(
|
|||||||
/// Handle groups for received messages
|
/// Handle groups for received messages
|
||||||
unsafe fn create_or_lookup_adhoc_group(
|
unsafe fn create_or_lookup_adhoc_group(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
mime_parser: &dc_mimeparser_t,
|
mime_parser: &MimeParser,
|
||||||
allow_creation: libc::c_int,
|
allow_creation: libc::c_int,
|
||||||
create_blocked: Blocked,
|
create_blocked: Blocked,
|
||||||
from_id: u32,
|
from_id: u32,
|
||||||
@@ -1483,7 +1475,7 @@ unsafe fn create_or_lookup_adhoc_group(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// build member list from the given ids
|
// build member list from the given ids
|
||||||
if to_ids.is_empty() || dc_mimeparser_is_mailinglist_message(mime_parser) {
|
if to_ids.is_empty() || mime_parser.is_mailinglist_message() {
|
||||||
// too few contacts or a mailinglist
|
// too few contacts or a mailinglist
|
||||||
cleanup(
|
cleanup(
|
||||||
grpname,
|
grpname,
|
||||||
@@ -1744,7 +1736,7 @@ fn search_chat_ids_by_contact_ids(context: &Context, unsorted_contact_ids: &Vec<
|
|||||||
|
|
||||||
unsafe fn check_verified_properties(
|
unsafe fn check_verified_properties(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
mimeparser: &dc_mimeparser_t,
|
mimeparser: &MimeParser,
|
||||||
from_id: u32,
|
from_id: u32,
|
||||||
to_ids: &Vec<u32>,
|
to_ids: &Vec<u32>,
|
||||||
failure_reason: *mut *mut libc::c_char,
|
failure_reason: *mut *mut libc::c_char,
|
||||||
@@ -1844,46 +1836,53 @@ unsafe fn check_verified_properties(
|
|||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn set_better_msg<T: AsRef<str>>(mime_parser: &mut dc_mimeparser_t, better_msg: T) {
|
fn set_better_msg(mime_parser: &mut MimeParser, better_msg: impl AsRef<str>) {
|
||||||
let msg = better_msg.as_ref();
|
let msg = better_msg.as_ref();
|
||||||
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.typ == Viewtype::Text {
|
||||||
part.msg = Some(msg.to_string());
|
part.msg = Some(msg.to_string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn dc_is_reply_to_known_message(
|
unsafe fn dc_is_reply_to_known_message(context: &Context, mime_parser: &MimeParser) -> libc::c_int {
|
||||||
context: &Context,
|
|
||||||
mime_parser: &dc_mimeparser_t,
|
|
||||||
) -> libc::c_int {
|
|
||||||
/* check if the message is a reply to a known message; the replies are identified by the Message-ID from
|
/* check if the message is a reply to a known message; the replies are identified by the Message-ID from
|
||||||
`In-Reply-To`/`References:` (to support non-Delta-Clients) or from `Chat-Predecessor:` (Delta clients, see comment in dc_chat.c) */
|
`In-Reply-To`/`References:` (to support non-Delta-Clients) or from `Chat-Predecessor:` (Delta clients, see comment in dc_chat.c) */
|
||||||
let optional_field = dc_mimeparser_lookup_optional_field(mime_parser, "Chat-Predecessor");
|
if let Some(optional_field) = mime_parser.lookup_optional_field("Chat-Predecessor") {
|
||||||
if !optional_field.is_null() {
|
|
||||||
if 0 != is_known_rfc724_mid(context, (*optional_field).fld_value) {
|
if 0 != is_known_rfc724_mid(context, (*optional_field).fld_value) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let field = dc_mimeparser_lookup_field(mime_parser, "In-Reply-To");
|
|
||||||
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_IN_REPLY_TO as libc::c_int {
|
if let Some(field) = mime_parser.lookup_field("In-Reply-To") {
|
||||||
let fld_in_reply_to: *mut mailimf_in_reply_to = (*field).fld_data.fld_in_reply_to;
|
if (*field).fld_type == MAILIMF_FIELD_IN_REPLY_TO as libc::c_int {
|
||||||
|
let fld_in_reply_to = (*field).fld_data.fld_in_reply_to;
|
||||||
if !fld_in_reply_to.is_null() {
|
if !fld_in_reply_to.is_null() {
|
||||||
if is_known_rfc724_mid_in_list(context, (*(*field).fld_data.fld_in_reply_to).mid_list) {
|
if is_known_rfc724_mid_in_list(
|
||||||
|
context,
|
||||||
|
(*(*field).fld_data.fld_in_reply_to).mid_list,
|
||||||
|
) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let field = dc_mimeparser_lookup_field(mime_parser, "References");
|
}
|
||||||
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_REFERENCES as libc::c_int {
|
|
||||||
let fld_references: *mut mailimf_references = (*field).fld_data.fld_references;
|
if let Some(field) = mime_parser.lookup_field("References") {
|
||||||
|
if (*field).fld_type == MAILIMF_FIELD_REFERENCES as libc::c_int {
|
||||||
|
let fld_references = (*field).fld_data.fld_references;
|
||||||
if !fld_references.is_null() {
|
if !fld_references.is_null() {
|
||||||
if is_known_rfc724_mid_in_list(context, (*(*field).fld_data.fld_references).mid_list) {
|
if is_known_rfc724_mid_in_list(
|
||||||
|
context,
|
||||||
|
(*(*field).fld_data.fld_references).mid_list,
|
||||||
|
) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1920,16 +1919,17 @@ fn is_known_rfc724_mid(context: &Context, rfc724_mid: *const libc::c_char) -> li
|
|||||||
|
|
||||||
unsafe fn dc_is_reply_to_messenger_message(
|
unsafe fn dc_is_reply_to_messenger_message(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
mime_parser: &dc_mimeparser_t,
|
mime_parser: &MimeParser,
|
||||||
) -> libc::c_int {
|
) -> libc::c_int {
|
||||||
/* function checks, if the message defined by mime_parser references a message send by us from Delta Chat.
|
/* function checks, if the message defined by mime_parser references a message send by us from Delta Chat.
|
||||||
This is similar to is_reply_to_known_message() but
|
This is similar to is_reply_to_known_message() but
|
||||||
- checks also if any of the referenced IDs are send by a messenger
|
- checks also if any of the referenced IDs are send by a messenger
|
||||||
- it is okay, if the referenced messages are moved to trash here
|
- it is okay, if the referenced messages are moved to trash here
|
||||||
- no check for the Chat-* headers (function is only called if it is no messenger message itself) */
|
- no check for the Chat-* headers (function is only called if it is no messenger message itself) */
|
||||||
let field = dc_mimeparser_lookup_field(mime_parser, "In-Reply-To");
|
|
||||||
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_IN_REPLY_TO as libc::c_int {
|
if let Some(field) = mime_parser.lookup_field("In-Reply-To") {
|
||||||
let fld_in_reply_to: *mut mailimf_in_reply_to = (*field).fld_data.fld_in_reply_to;
|
if (*field).fld_type == MAILIMF_FIELD_IN_REPLY_TO as libc::c_int {
|
||||||
|
let fld_in_reply_to = (*field).fld_data.fld_in_reply_to;
|
||||||
if !fld_in_reply_to.is_null() {
|
if !fld_in_reply_to.is_null() {
|
||||||
if 0 != is_msgrmsg_rfc724_mid_in_list(
|
if 0 != is_msgrmsg_rfc724_mid_in_list(
|
||||||
context,
|
context,
|
||||||
@@ -1939,8 +1939,10 @@ unsafe fn dc_is_reply_to_messenger_message(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let field = dc_mimeparser_lookup_field(mime_parser, "References");
|
}
|
||||||
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_REFERENCES as libc::c_int {
|
|
||||||
|
if let Some(field) = mime_parser.lookup_field("References") {
|
||||||
|
if (*field).fld_type == MAILIMF_FIELD_REFERENCES as libc::c_int {
|
||||||
let fld_references: *mut mailimf_references = (*field).fld_data.fld_references;
|
let fld_references: *mut mailimf_references = (*field).fld_data.fld_references;
|
||||||
if !fld_references.is_null() {
|
if !fld_references.is_null() {
|
||||||
if 0 != is_msgrmsg_rfc724_mid_in_list(
|
if 0 != is_msgrmsg_rfc724_mid_in_list(
|
||||||
@@ -1951,6 +1953,8 @@ unsafe fn dc_is_reply_to_messenger_message(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
23
src/e2ee.rs
23
src/e2ee.rs
@@ -386,16 +386,17 @@ impl E2eeHelper {
|
|||||||
/*just a pointer into mailmime structure, must not be freed*/
|
/*just a pointer into mailmime structure, must not be freed*/
|
||||||
let imffields: *mut mailimf_fields = mailmime_find_mailimf_fields(in_out_message);
|
let imffields: *mut mailimf_fields = mailmime_find_mailimf_fields(in_out_message);
|
||||||
let mut message_time = 0;
|
let mut message_time = 0;
|
||||||
let mut from: *mut libc::c_char = ptr::null_mut();
|
let mut from = None;
|
||||||
let mut private_keyring = Keyring::default();
|
let mut private_keyring = Keyring::default();
|
||||||
let mut public_keyring_for_validate = Keyring::default();
|
let mut public_keyring_for_validate = Keyring::default();
|
||||||
let mut gossip_headers: *mut mailimf_fields = ptr::null_mut();
|
let mut gossip_headers: *mut mailimf_fields = ptr::null_mut();
|
||||||
if !(in_out_message.is_null() || imffields.is_null()) {
|
if !(in_out_message.is_null() || imffields.is_null()) {
|
||||||
let mut field: *mut mailimf_field =
|
let mut field = mailimf_find_field(imffields, MAILIMF_FIELD_FROM as libc::c_int);
|
||||||
mailimf_find_field(imffields, MAILIMF_FIELD_FROM as libc::c_int);
|
|
||||||
if !field.is_null() && !(*field).fld_data.fld_from.is_null() {
|
if !field.is_null() && !(*field).fld_data.fld_from.is_null() {
|
||||||
from = mailimf_find_first_addr((*(*field).fld_data.fld_from).frm_mb_list)
|
from = mailimf_find_first_addr((*(*field).fld_data.fld_from).frm_mb_list)
|
||||||
}
|
}
|
||||||
|
|
||||||
field = mailimf_find_field(imffields, MAILIMF_FIELD_ORIG_DATE as libc::c_int);
|
field = mailimf_find_field(imffields, MAILIMF_FIELD_ORIG_DATE as libc::c_int);
|
||||||
if !field.is_null() && !(*field).fld_data.fld_orig_date.is_null() {
|
if !field.is_null() && !(*field).fld_data.fld_orig_date.is_null() {
|
||||||
let orig_date: *mut mailimf_orig_date = (*field).fld_data.fld_orig_date;
|
let orig_date: *mut mailimf_orig_date = (*field).fld_data.fld_orig_date;
|
||||||
@@ -407,10 +408,12 @@ impl E2eeHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut peerstate = None;
|
let mut peerstate = None;
|
||||||
let autocryptheader =
|
let autocryptheader = from
|
||||||
as_opt_str(from).and_then(|from| Aheader::from_imffields(from, imffields));
|
.as_ref()
|
||||||
if message_time > 0 && !from.is_null() {
|
.and_then(|from| Aheader::from_imffields(from, imffields));
|
||||||
peerstate = Peerstate::from_addr(context, &context.sql, as_str(from));
|
if message_time > 0 {
|
||||||
|
if let Some(ref from) = from {
|
||||||
|
peerstate = Peerstate::from_addr(context, &context.sql, from);
|
||||||
|
|
||||||
if let Some(ref mut peerstate) = peerstate {
|
if let Some(ref mut peerstate) = peerstate {
|
||||||
if let Some(ref header) = autocryptheader {
|
if let Some(ref header) = autocryptheader {
|
||||||
@@ -428,6 +431,7 @@ impl E2eeHelper {
|
|||||||
peerstate = Some(p);
|
peerstate = Some(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* load private key for decryption */
|
/* load private key for decryption */
|
||||||
let self_addr = context.get_config(Config::ConfiguredAddr);
|
let self_addr = context.get_config(Config::ConfiguredAddr);
|
||||||
if let Some(self_addr) = self_addr {
|
if let Some(self_addr) = self_addr {
|
||||||
@@ -437,7 +441,8 @@ impl E2eeHelper {
|
|||||||
&context.sql,
|
&context.sql,
|
||||||
) {
|
) {
|
||||||
if peerstate.as_ref().map(|p| p.last_seen).unwrap_or_else(|| 0) == 0 {
|
if peerstate.as_ref().map(|p| p.last_seen).unwrap_or_else(|| 0) == 0 {
|
||||||
peerstate = Peerstate::from_addr(&context, &context.sql, as_str(from));
|
peerstate =
|
||||||
|
Peerstate::from_addr(&context, &context.sql, &from.unwrap_or_default());
|
||||||
}
|
}
|
||||||
if let Some(ref peerstate) = peerstate {
|
if let Some(ref peerstate) = peerstate {
|
||||||
if peerstate.degrade_event.is_some() {
|
if peerstate.degrade_event.is_some() {
|
||||||
@@ -486,8 +491,6 @@ impl E2eeHelper {
|
|||||||
if !gossip_headers.is_null() {
|
if !gossip_headers.is_null() {
|
||||||
mailimf_fields_free(gossip_headers);
|
mailimf_fields_free(gossip_headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(from as *mut libc::c_void);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -335,7 +335,7 @@ fn fingerprint_equals_sender(
|
|||||||
/* library private: secure-join */
|
/* library private: secure-join */
|
||||||
pub fn handle_securejoin_handshake(
|
pub fn handle_securejoin_handshake(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
mimeparser: &dc_mimeparser_t,
|
mimeparser: &MimeParser,
|
||||||
contact_id: u32,
|
contact_id: u32,
|
||||||
) -> libc::c_int {
|
) -> libc::c_int {
|
||||||
let own_fingerprint: String;
|
let own_fingerprint: String;
|
||||||
@@ -651,21 +651,21 @@ fn secure_connection_established(context: &Context, contact_chat_id: u32) {
|
|||||||
emit_event!(context, Event::ChatModified(contact_chat_id));
|
emit_event!(context, Event::ChatModified(contact_chat_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lookup_field(mimeparser: &dc_mimeparser_t, key: &str) -> Option<String> {
|
fn lookup_field(mime_parser: &MimeParser, key: &str) -> Option<String> {
|
||||||
let field: *mut mailimf_field = dc_mimeparser_lookup_field(mimeparser, key);
|
if let Some(field) = mime_parser.lookup_field(key) {
|
||||||
unsafe {
|
|
||||||
let mut value: *const libc::c_char = ptr::null();
|
let mut value: *const libc::c_char = ptr::null();
|
||||||
if field.is_null()
|
if unsafe { (*field).fld_type } != MAILIMF_FIELD_OPTIONAL_FIELD as libc::c_int
|
||||||
|| (*field).fld_type != MAILIMF_FIELD_OPTIONAL_FIELD as libc::c_int
|
|| unsafe { (*field).fld_data.fld_optional_field.is_null() }
|
||||||
|| (*field).fld_data.fld_optional_field.is_null()
|
|
||||||
|| {
|
|| {
|
||||||
value = (*(*field).fld_data.fld_optional_field).fld_value;
|
value = unsafe { (*(*field).fld_data.fld_optional_field).fld_value };
|
||||||
value.is_null()
|
value.is_null()
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some(as_str(value).to_string())
|
Some(to_string(value))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -706,10 +706,7 @@ fn mark_peer_as_verified(context: &Context, fingerprint: impl AsRef<str>) -> Res
|
|||||||
* Tools: Misc.
|
* Tools: Misc.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
fn encrypted_and_signed(
|
fn encrypted_and_signed(mimeparser: &MimeParser, expected_fingerprint: impl AsRef<str>) -> bool {
|
||||||
mimeparser: &dc_mimeparser_t,
|
|
||||||
expected_fingerprint: impl AsRef<str>,
|
|
||||||
) -> bool {
|
|
||||||
if !mimeparser.e2ee_helper.encrypted {
|
if !mimeparser.e2ee_helper.encrypted {
|
||||||
warn!(mimeparser.context, "Message not encrypted.",);
|
warn!(mimeparser.context, "Message not encrypted.",);
|
||||||
false
|
false
|
||||||
|
|||||||
Reference in New Issue
Block a user