mirror of
https://github.com/chatmail/core.git
synced 2026-05-01 20:36:31 +03:00
Merge pull request #181 from deltachat/improve_receive_imf1
improve dc_receive_imf and friends a little (part 1)
This commit is contained in:
@@ -483,6 +483,8 @@ pub const DC_STR_MSGLOCATIONDISABLED: usize = 65;
|
|||||||
pub const DC_STR_LOCATION: usize = 66;
|
pub const DC_STR_LOCATION: usize = 66;
|
||||||
pub const DC_STR_COUNT: usize = 66;
|
pub const DC_STR_COUNT: usize = 66;
|
||||||
|
|
||||||
|
pub const DC_JOB_DELETE_MSG_ON_IMAP: i32 = 110;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum KeyType {
|
pub enum KeyType {
|
||||||
|
|||||||
@@ -176,10 +176,7 @@ pub unsafe fn dc_mimeparser_parse(
|
|||||||
&mut (*mimeparser).e2ee_helper,
|
&mut (*mimeparser).e2ee_helper,
|
||||||
);
|
);
|
||||||
dc_mimeparser_parse_mime_recursive(mimeparser, (*mimeparser).mimeroot);
|
dc_mimeparser_parse_mime_recursive(mimeparser, (*mimeparser).mimeroot);
|
||||||
let field: *mut mailimf_field = dc_mimeparser_lookup_field(
|
let field: *mut mailimf_field = dc_mimeparser_lookup_field(mimeparser, "Subject");
|
||||||
mimeparser,
|
|
||||||
b"Subject\x00" as *const u8 as *const libc::c_char,
|
|
||||||
);
|
|
||||||
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_SUBJECT as libc::c_int {
|
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_SUBJECT as libc::c_int {
|
||||||
(*mimeparser).subject =
|
(*mimeparser).subject =
|
||||||
dc_decode_header_words((*(*field).fld_data.fld_subject).sbj_value)
|
dc_decode_header_words((*(*field).fld_data.fld_subject).sbj_value)
|
||||||
@@ -192,12 +189,7 @@ pub unsafe fn dc_mimeparser_parse(
|
|||||||
{
|
{
|
||||||
(*mimeparser).is_send_by_messenger = 1i32
|
(*mimeparser).is_send_by_messenger = 1i32
|
||||||
}
|
}
|
||||||
if !dc_mimeparser_lookup_field(
|
if !dc_mimeparser_lookup_field(mimeparser, "Autocrypt-Setup-Message").is_null() {
|
||||||
mimeparser,
|
|
||||||
b"Autocrypt-Setup-Message\x00" as *const u8 as *const libc::c_char,
|
|
||||||
)
|
|
||||||
.is_null()
|
|
||||||
{
|
|
||||||
let mut i: libc::c_int;
|
let mut i: libc::c_int;
|
||||||
let mut has_setup_file: libc::c_int = 0i32;
|
let mut has_setup_file: libc::c_int = 0i32;
|
||||||
i = 0i32;
|
i = 0i32;
|
||||||
@@ -238,11 +230,7 @@ pub unsafe fn dc_mimeparser_parse(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !dc_mimeparser_lookup_field(
|
if !dc_mimeparser_lookup_field(mimeparser, "Chat-Group-Image").is_null()
|
||||||
mimeparser,
|
|
||||||
b"Chat-Group-Image\x00" as *const u8 as *const libc::c_char,
|
|
||||||
)
|
|
||||||
.is_null()
|
|
||||||
&& carray_count((*mimeparser).parts) >= 1i32 as libc::c_uint
|
&& carray_count((*mimeparser).parts) >= 1i32 as libc::c_uint
|
||||||
{
|
{
|
||||||
let textpart: *mut dc_mimepart_t =
|
let textpart: *mut dc_mimepart_t =
|
||||||
@@ -384,10 +372,8 @@ pub unsafe fn dc_mimeparser_parse(
|
|||||||
{
|
{
|
||||||
let dn_to_addr: *mut libc::c_char = mailimf_find_first_addr(mb_list);
|
let dn_to_addr: *mut libc::c_char = mailimf_find_first_addr(mb_list);
|
||||||
if !dn_to_addr.is_null() {
|
if !dn_to_addr.is_null() {
|
||||||
let from_field: *mut mailimf_field = dc_mimeparser_lookup_field(
|
let from_field: *mut mailimf_field =
|
||||||
mimeparser,
|
dc_mimeparser_lookup_field(mimeparser, "From");
|
||||||
b"From\x00" as *const u8 as *const libc::c_char,
|
|
||||||
);
|
|
||||||
if !from_field.is_null()
|
if !from_field.is_null()
|
||||||
&& (*from_field).fld_type == MAILIMF_FIELD_FROM as libc::c_int
|
&& (*from_field).fld_type == MAILIMF_FIELD_FROM as libc::c_int
|
||||||
&& !(*from_field).fld_data.fld_from.is_null()
|
&& !(*from_field).fld_data.fld_from.is_null()
|
||||||
@@ -488,13 +474,14 @@ pub unsafe fn mailimf_find_first_addr(mb_list: *const mailimf_mailbox_list) -> *
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* the following functions can be used only after a call to dc_mimeparser_parse() */
|
/* the following functions can be used only after a call to dc_mimeparser_parse() */
|
||||||
|
|
||||||
pub fn dc_mimeparser_lookup_field(
|
pub fn dc_mimeparser_lookup_field(
|
||||||
mimeparser: &dc_mimeparser_t,
|
mimeparser: &dc_mimeparser_t,
|
||||||
field_name: *const libc::c_char,
|
field_name: &str,
|
||||||
) -> *mut mailimf_field {
|
) -> *mut mailimf_field {
|
||||||
mimeparser
|
mimeparser
|
||||||
.header
|
.header
|
||||||
.get(as_str(field_name))
|
.get(field_name)
|
||||||
.map(|v| *v)
|
.map(|v| *v)
|
||||||
.unwrap_or_else(|| std::ptr::null_mut())
|
.unwrap_or_else(|| std::ptr::null_mut())
|
||||||
}
|
}
|
||||||
@@ -1627,12 +1614,7 @@ pub unsafe fn mailmime_transfer_decode(
|
|||||||
|
|
||||||
// TODO should return bool /rtn
|
// TODO should return bool /rtn
|
||||||
pub unsafe fn dc_mimeparser_is_mailinglist_message(mimeparser: &dc_mimeparser_t) -> libc::c_int {
|
pub unsafe fn dc_mimeparser_is_mailinglist_message(mimeparser: &dc_mimeparser_t) -> libc::c_int {
|
||||||
if !dc_mimeparser_lookup_field(
|
if !dc_mimeparser_lookup_field(&mimeparser, "List-Id").is_null() {
|
||||||
&mimeparser,
|
|
||||||
b"List-Id\x00" as *const u8 as *const libc::c_char,
|
|
||||||
)
|
|
||||||
.is_null()
|
|
||||||
{
|
|
||||||
return 1i32;
|
return 1i32;
|
||||||
}
|
}
|
||||||
let precedence: *mut mailimf_optional_field = dc_mimeparser_lookup_optional_field(
|
let precedence: *mut mailimf_optional_field = dc_mimeparser_lookup_optional_field(
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -401,10 +401,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
|||||||
let mut ret: libc::c_int = 0i32;
|
let mut ret: libc::c_int = 0i32;
|
||||||
let mut contact: *mut dc_contact_t = 0 as *mut dc_contact_t;
|
let mut contact: *mut dc_contact_t = 0 as *mut dc_contact_t;
|
||||||
if !(contact_id <= 9i32 as libc::c_uint) {
|
if !(contact_id <= 9i32 as libc::c_uint) {
|
||||||
step = lookup_field(
|
step = lookup_field(mimeparser, "Secure-Join");
|
||||||
mimeparser,
|
|
||||||
b"Secure-Join\x00" as *const u8 as *const libc::c_char,
|
|
||||||
);
|
|
||||||
if !step.is_null() {
|
if !step.is_null() {
|
||||||
dc_log_info(
|
dc_log_info(
|
||||||
context,
|
context,
|
||||||
@@ -438,32 +435,15 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
|||||||
// send_message() will fail with the error "End-to-end-encryption unavailable unexpectedly.", so, there is no additional check needed here.
|
// send_message() will fail with the error "End-to-end-encryption unavailable unexpectedly.", so, there is no additional check needed here.
|
||||||
// verify that the `Secure-Join-Invitenumber:`-header matches invitenumber written to the QR code
|
// verify that the `Secure-Join-Invitenumber:`-header matches invitenumber written to the QR code
|
||||||
let invitenumber: *const libc::c_char;
|
let invitenumber: *const libc::c_char;
|
||||||
invitenumber = lookup_field(
|
invitenumber = lookup_field(mimeparser, "Secure-Join-Invitenumber");
|
||||||
mimeparser,
|
|
||||||
b"Secure-Join-Invitenumber\x00" as *const u8 as *const libc::c_char,
|
|
||||||
);
|
|
||||||
if invitenumber.is_null() {
|
if invitenumber.is_null() {
|
||||||
dc_log_warning(
|
warn!(context, 0, "Secure-join denied (invitenumber missing).",);
|
||||||
context,
|
|
||||||
0i32,
|
|
||||||
b"Secure-join denied (invitenumber missing).\x00" as *const u8
|
|
||||||
as *const libc::c_char,
|
|
||||||
);
|
|
||||||
current_block = 4378276786830486580;
|
current_block = 4378276786830486580;
|
||||||
} else if dc_token_exists(context, DC_TOKEN_INVITENUMBER, invitenumber) == 0i32 {
|
} else if dc_token_exists(context, DC_TOKEN_INVITENUMBER, invitenumber) == 0i32 {
|
||||||
dc_log_warning(
|
warn!(context, 0, "Secure-join denied (bad invitenumber).",);
|
||||||
context,
|
|
||||||
0i32,
|
|
||||||
b"Secure-join denied (bad invitenumber).\x00" as *const u8
|
|
||||||
as *const libc::c_char,
|
|
||||||
);
|
|
||||||
current_block = 4378276786830486580;
|
current_block = 4378276786830486580;
|
||||||
} else {
|
} else {
|
||||||
dc_log_info(
|
info!(context, 0, "Secure-join requested.",);
|
||||||
context,
|
|
||||||
0i32,
|
|
||||||
b"Secure-join requested.\x00" as *const u8 as *const libc::c_char,
|
|
||||||
);
|
|
||||||
context.call_cb(
|
context.call_cb(
|
||||||
Event::SECUREJOIN_INVITER_PROGRESS,
|
Event::SECUREJOIN_INVITER_PROGRESS,
|
||||||
contact_id as uintptr_t,
|
contact_id as uintptr_t,
|
||||||
@@ -589,10 +569,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
|||||||
============================================================ */
|
============================================================ */
|
||||||
// verify that Secure-Join-Fingerprint:-header matches the fingerprint of Bob
|
// verify that Secure-Join-Fingerprint:-header matches the fingerprint of Bob
|
||||||
let fingerprint: *const libc::c_char;
|
let fingerprint: *const libc::c_char;
|
||||||
fingerprint = lookup_field(
|
fingerprint = lookup_field(mimeparser, "Secure-Join-Fingerprint");
|
||||||
mimeparser,
|
|
||||||
b"Secure-Join-Fingerprint\x00" as *const u8 as *const libc::c_char,
|
|
||||||
);
|
|
||||||
if fingerprint.is_null() {
|
if fingerprint.is_null() {
|
||||||
could_not_establish_secure_connection(
|
could_not_establish_secure_connection(
|
||||||
context,
|
context,
|
||||||
@@ -623,10 +600,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
|||||||
);
|
);
|
||||||
// verify that the `Secure-Join-Auth:`-header matches the secret written to the QR code
|
// verify that the `Secure-Join-Auth:`-header matches the secret written to the QR code
|
||||||
let auth_0: *const libc::c_char;
|
let auth_0: *const libc::c_char;
|
||||||
auth_0 = lookup_field(
|
auth_0 = lookup_field(mimeparser, "Secure-Join-Auth");
|
||||||
mimeparser,
|
|
||||||
b"Secure-Join-Auth\x00" as *const u8 as *const libc::c_char,
|
|
||||||
);
|
|
||||||
if auth_0.is_null() {
|
if auth_0.is_null() {
|
||||||
could_not_establish_secure_connection(
|
could_not_establish_secure_connection(
|
||||||
context,
|
context,
|
||||||
@@ -668,10 +642,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
|||||||
600i32 as uintptr_t,
|
600i32 as uintptr_t,
|
||||||
);
|
);
|
||||||
if 0 != join_vg {
|
if 0 != join_vg {
|
||||||
grpid = dc_strdup(lookup_field(
|
grpid = dc_strdup(lookup_field(mimeparser, "Secure-Join-Group"));
|
||||||
mimeparser,
|
|
||||||
b"Secure-Join-Group\x00" as *const u8 as *const libc::c_char,
|
|
||||||
));
|
|
||||||
let group_chat_id: uint32_t = dc_get_chat_id_by_grpid(
|
let group_chat_id: uint32_t = dc_get_chat_id_by_grpid(
|
||||||
context,
|
context,
|
||||||
grpid,
|
grpid,
|
||||||
@@ -805,11 +776,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
|
|||||||
if 0 != join_vg {
|
if 0 != join_vg {
|
||||||
if 0 == dc_addr_equals_self(
|
if 0 == dc_addr_equals_self(
|
||||||
context,
|
context,
|
||||||
lookup_field(
|
lookup_field(mimeparser, "Chat-Group-Member-Added"),
|
||||||
mimeparser,
|
|
||||||
b"Chat-Group-Member-Added\x00" as *const u8
|
|
||||||
as *const libc::c_char,
|
|
||||||
),
|
|
||||||
) {
|
) {
|
||||||
dc_log_info(context, 0i32,
|
dc_log_info(context, 0i32,
|
||||||
b"Message belongs to a different handshake (scaled up contact anyway to allow creation of group).\x00"
|
b"Message belongs to a different handshake (scaled up contact anyway to allow creation of group).\x00"
|
||||||
@@ -927,10 +894,7 @@ unsafe fn secure_connection_established(context: &Context, contact_chat_id: uint
|
|||||||
dc_contact_unref(contact);
|
dc_contact_unref(contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn lookup_field(
|
unsafe fn lookup_field(mimeparser: &dc_mimeparser_t, key: &str) -> *const libc::c_char {
|
||||||
mimeparser: &dc_mimeparser_t,
|
|
||||||
key: *const libc::c_char,
|
|
||||||
) -> *const libc::c_char {
|
|
||||||
let mut value: *const libc::c_char = 0 as *const libc::c_char;
|
let mut value: *const libc::c_char = 0 as *const libc::c_char;
|
||||||
let field: *mut mailimf_field = dc_mimeparser_lookup_field(mimeparser, key);
|
let field: *mut mailimf_field = dc_mimeparser_lookup_field(mimeparser, key);
|
||||||
if field.is_null()
|
if field.is_null()
|
||||||
|
|||||||
Reference in New Issue
Block a user