mirror of
https://github.com/chatmail/core.git
synced 2026-05-13 03:46:32 +03:00
Squashed commit of the following:
commit6bc5d1b90eAuthor: holger krekel <holger@merlinux.eu> Date: Sun Jul 21 22:56:37 2019 +0200 fix fmt commit197d94ad9dMerge:7ce337c686678cAuthor: holger krekel <holger@merlinux.eu> Date: Sun Jul 21 22:51:16 2019 +0200 Merge remote-tracking branch 'origin/master' into eventlogging commit7ce337c6d0Author: holger krekel <holger@merlinux.eu> Date: Sun Jul 21 22:44:27 2019 +0200 left-over error logging commit10148d2e43Author: holger krekel <holger@merlinux.eu> Date: Sun Jul 21 22:03:17 2019 +0200 ignore non-utf8 parts of header fields (add comment why it shouldn't happen) don't throw error if no sql rows are returned commit69dc237ee3Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Sun Jul 21 12:56:04 2019 +0200 fix(receive_imf): remove recursive sql call commitdf5464ea80Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Sat Jul 20 17:05:24 2019 +0200 fix: blocked is an optional value commite4bf9956a5Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Sat Jul 20 16:50:56 2019 +0200 fix(msg): handle optional in_reply_to commitd353d9d9d8Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Sat Jul 20 16:17:25 2019 +0200 fix(chat): remove recursive sql usage commit1ad45ed4d6Author: holger krekel <holger@merlinux.eu> Date: Sat Jul 20 15:14:11 2019 +0200 fix rust fmt commit496e980a17Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Sat Jul 20 14:34:20 2019 +0200 use forked rusqlite commitfa09e46ed9Author: holger krekel <holger@merlinux.eu> Date: Sat Jul 20 12:37:51 2019 +0200 another pace where we might (and in my case did) get invalid utf8 commitd6de420b9aAuthor: holger krekel <holger@merlinux.eu> Date: Sat Jul 20 12:30:48 2019 +0200 fix some string issues, introduce to_string_lossy such that to_string() continues to panic on non-utf8 commit38eb708db8Author: holger krekel <holger@merlinux.eu> Date: Sat Jul 20 01:17:53 2019 +0200 for now make to_string() less strict as we often don't want to crash the whole app just because some non-proper utf8 came in (through a message we can't neccesarily congtrol) commit7a59da5f8fAuthor: holger krekel <holger@merlinux.eu> Date: Fri Jul 19 22:48:39 2019 +0200 fix linting commitf13a1d4a2fAuthor: holger krekel <holger@merlinux.eu> Date: Fri Jul 19 22:46:58 2019 +0200 fix some test flakyness commit7b3a450918Author: holger krekel <holger@merlinux.eu> Date: Fri Jul 19 22:35:07 2019 +0200 - fix saved_mime test which broke to improper conversion of imf_raw_not_terminated - some cargo.toml updates no clue where they come from - log Message-ID for received messages commit169923b102Author: holger krekel <holger@merlinux.eu> Date: Fri Jul 19 12:31:22 2019 +0200 formatting commit42688a0622Author: holger krekel <holger@merlinux.eu> Date: Fri Jul 19 12:24:56 2019 +0200 remove some print statements commit35f3c0edd1Merge:e7a2362f58b1d6Author: holger krekel <holger@merlinux.eu> Date: Fri Jul 19 10:25:21 2019 +0200 Merge branch 'master' into eventlogging commite7a236264aAuthor: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Thu Jul 18 23:20:20 2019 +0200 print invalid strings commitaaa5b820d9Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Thu Jul 18 23:12:35 2019 +0200 cleanup commite7f0745010Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Thu Jul 18 23:03:57 2019 +0200 reduce direc usage of CString commitc68e7ae14eAuthor: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Thu Jul 18 22:47:47 2019 +0200 audit use of to_cstring and fix ub commit618087e5a7Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Thu Jul 18 21:38:52 2019 +0200 fix(imap): body ptr lifetime commit245abb8384Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Thu Jul 18 19:44:10 2019 +0200 remove debug commita3e1042001Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Thu Jul 18 18:30:54 2019 +0200 fix some things, add more debugging statements commit7b7ce9348fAuthor: holger krekel <holger@merlinux.eu> Date: Thu Jul 18 15:11:57 2019 +0200 fix python lint issues commit7a4808ba0dAuthor: holger krekel <holger@merlinux.eu> Date: Thu Jul 18 14:35:54 2019 +0200 cargofmt commit8f240f7153Author: holger krekel <holger@merlinux.eu> Date: Thu Jul 18 14:03:57 2019 +0200 (dig,hpk) pull out job collection from sql query/lock logic commit7d0b5d8abbAuthor: holger krekel <holger@merlinux.eu> Date: Thu Jul 18 12:52:02 2019 +0200 remove print statements and fix a crash commitee317cb1b5Author: holger krekel <holger@merlinux.eu> Date: Thu Jul 18 11:38:10 2019 +0200 fix some merge issues commit7b736fe635Author: holger krekel <holger@merlinux.eu> Date: Thu Jul 18 11:16:38 2019 +0200 (dig,hpk) add test and fix for wrong dbs commitc7db15352aMerge:0b371670c5015dAuthor: holger krekel <holger@merlinux.eu> Date: Thu Jul 18 09:59:44 2019 +0200 Merge branch 'master' into eventlogging commit0b37167be8Author: holger krekel <holger@merlinux.eu> Date: Thu Jul 18 00:06:05 2019 +0200 address @dignifiedquire comments commit5cac4b5076Author: holger krekel <holger@merlinux.eu> Date: Wed Jul 17 12:47:22 2019 +0200 remove spurious print commit475a41beb3Author: holger krekel <holger@merlinux.eu> Date: Wed Jul 17 12:31:12 2019 +0200 address @dignifiedquire rustyness comment and fix changelog commitad4be80b4eAuthor: holger krekel <holger@merlinux.eu> Date: Wed Jul 17 10:25:25 2019 +0200 make smtp/imap connect() return bool instead of c-int commit8737c1d142Author: holger krekel <holger@merlinux.eu> Date: Wed Jul 17 09:26:33 2019 +0200 cleanup some parts, add comments commit964fe466ccAuthor: holger krekel <holger@merlinux.eu> Date: Tue Jul 16 20:05:41 2019 +0200 wip-commit which passes all tests with proper finalization commit43936e7db7Author: holger krekel <holger@merlinux.eu> Date: Tue Jul 16 16:17:42 2019 +0200 snapshot of my current debugging state commit0e80ce9c39Author: holger krekel <holger@merlinux.eu> Date: Tue Jul 16 12:57:19 2019 +0200 more aggressively skip perform API when threads are closing commitc652bae68aAuthor: holger krekel <holger@merlinux.eu> Date: Tue Jul 16 12:06:05 2019 +0200 intermediate wip commit commitbc904a495dAuthor: holger krekel <holger@merlinux.eu> Date: Tue Jul 16 11:18:56 2019 +0200 add some logging, and a more precise teardown for online python tests commit8d99444c6aAuthor: holger krekel <holger@merlinux.eu> Date: Tue Jul 16 00:22:12 2019 +0200 fix std commit9dab53e0afAuthor: holger krekel <holger@merlinux.eu> Date: Tue Jul 16 00:20:54 2019 +0200 rustfmt commit360089ac74Author: holger krekel <holger@merlinux.eu> Date: Tue Jul 16 00:03:49 2019 +0200 remove some debugging commite892c5cf4dAuthor: holger krekel <holger@merlinux.eu> Date: Mon Jul 15 23:31:30 2019 +0200 fix test for events commit9ad4c9a6feAuthor: holger krekel <holger@merlinux.eu> Date: Mon Jul 15 22:51:57 2019 +0200 wip try test that we see INFO events from the core
This commit is contained in:
@@ -443,7 +443,7 @@ pub unsafe fn dc_receive_imf(
|
||||
timestamp_sent, timestamp_rcvd, type, state, msgrmsg, txt, txt_raw, param, \
|
||||
bytes, hidden, mime_headers, mime_in_reply_to, mime_references) \
|
||||
VALUES (?,?,?,?,?,?, ?,?,?,?,?,?, ?,?,?,?,?,?, ?,?);",
|
||||
|mut stmt| {
|
||||
|mut stmt, conn| {
|
||||
let mut i = 0;
|
||||
loop {
|
||||
if !(i < icnt) {
|
||||
@@ -503,16 +503,21 @@ pub unsafe fn dc_receive_imf(
|
||||
} else {
|
||||
""
|
||||
},
|
||||
// txt_raw might contain invalid utf8
|
||||
if !txt_raw.is_null() {
|
||||
as_str(txt_raw)
|
||||
to_string_lossy(txt_raw)
|
||||
} else {
|
||||
""
|
||||
String::new()
|
||||
},
|
||||
as_str((*(*part).param).packed),
|
||||
(*part).bytes,
|
||||
hidden,
|
||||
if 0 != save_mime_headers {
|
||||
Some(to_string(imf_raw_not_terminated))
|
||||
let body_string = unsafe {
|
||||
std::str::from_utf8(std::slice::from_raw_parts(imf_raw_not_terminated as *const u8, imf_raw_bytes)).unwrap()
|
||||
};
|
||||
|
||||
Some(body_string)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
@@ -528,9 +533,9 @@ pub unsafe fn dc_receive_imf(
|
||||
} else {
|
||||
free(txt_raw as *mut libc::c_void);
|
||||
txt_raw = 0 as *mut libc::c_char;
|
||||
insert_msg_id = sql::get_rowid(
|
||||
insert_msg_id = sql::get_rowid_with_conn(
|
||||
context,
|
||||
&context.sql,
|
||||
conn,
|
||||
"msgs",
|
||||
"rfc724_mid",
|
||||
as_str(rfc724_mid),
|
||||
@@ -739,11 +744,9 @@ pub unsafe fn dc_receive_imf(
|
||||
}
|
||||
if 0 != mime_parser.is_send_by_messenger || 0 != mdn_consumed {
|
||||
let param = dc_param_new();
|
||||
dc_param_set(
|
||||
param,
|
||||
'Z' as i32,
|
||||
to_cstring(server_folder.as_ref()).as_ptr(),
|
||||
);
|
||||
let server_folder_c = to_cstring(server_folder.as_ref());
|
||||
dc_param_set(param, 'Z' as i32, server_folder_c);
|
||||
free(server_folder_c as *mut _);
|
||||
dc_param_set_int(param, 'z' as i32, server_uid as i32);
|
||||
if 0 != mime_parser.is_send_by_messenger
|
||||
&& 0 != context
|
||||
@@ -827,6 +830,14 @@ pub unsafe fn dc_receive_imf(
|
||||
}
|
||||
}
|
||||
|
||||
info!(
|
||||
context,
|
||||
0,
|
||||
"received message {} has Message-Id: {}",
|
||||
server_uid,
|
||||
to_string(rfc724_mid)
|
||||
);
|
||||
|
||||
free(rfc724_mid as *mut libc::c_void);
|
||||
free(mime_in_reply_to as *mut libc::c_void);
|
||||
free(mime_references as *mut libc::c_void);
|
||||
@@ -1375,7 +1386,7 @@ unsafe fn create_or_lookup_adhoc_group(
|
||||
),
|
||||
params![],
|
||||
|row| {
|
||||
Ok((row.get::<_, i32>(0)?, row.get::<_, i32>(1)?))
|
||||
Ok((row.get::<_, i32>(0)?, row.get::<_, Option<i32>>(1)?.unwrap_or_default()))
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1518,9 +1529,7 @@ fn hex_hash(s: impl AsRef<str>) -> *const libc::c_char {
|
||||
let bytes = s.as_ref().as_bytes();
|
||||
let result = Sha256::digest(bytes);
|
||||
let result_hex = hex::encode(&result[..8]);
|
||||
let result_cstring = to_cstring(result_hex);
|
||||
|
||||
unsafe { strdup(result_cstring.as_ptr()) }
|
||||
unsafe { to_cstring(result_hex) as *const _ }
|
||||
}
|
||||
|
||||
unsafe fn search_chat_ids_by_contact_ids(
|
||||
@@ -1604,8 +1613,7 @@ unsafe fn check_verified_properties(
|
||||
let contact = dc_contact_new(context);
|
||||
|
||||
let verify_fail = |reason: String| {
|
||||
*failure_reason =
|
||||
strdup(to_cstring(format!("{}. See \"Info\" for details.", reason)).as_ptr());
|
||||
*failure_reason = to_cstring(format!("{}. See \"Info\" for details.", reason));
|
||||
warn!(context, 0, "{}", reason);
|
||||
};
|
||||
|
||||
@@ -1651,68 +1659,61 @@ unsafe fn check_verified_properties(
|
||||
let to_ids_str = to_string(to_ids_str_c);
|
||||
free(to_ids_str_c as *mut libc::c_void);
|
||||
|
||||
let ok = context
|
||||
.sql
|
||||
.query_map(
|
||||
format!(
|
||||
"SELECT c.addr, LENGTH(ps.verified_key_fingerprint) FROM contacts c \
|
||||
LEFT JOIN acpeerstates ps ON c.addr=ps.addr WHERE c.id IN({}) ",
|
||||
&to_ids_str,
|
||||
),
|
||||
params![],
|
||||
|row| Ok((row.get::<_, String>(0)?, row.get::<_, i32>(1)?)),
|
||||
|rows| {
|
||||
for row in rows {
|
||||
let (to_addr, mut is_verified) = row?;
|
||||
let mut peerstate = Peerstate::from_addr(context, &context.sql, &to_addr);
|
||||
if mimeparser.e2ee_helper.gossipped_addr.contains(&to_addr)
|
||||
&& peerstate.is_some()
|
||||
{
|
||||
let peerstate = peerstate.as_mut().unwrap();
|
||||
let rows = context.sql.query_map(
|
||||
format!(
|
||||
"SELECT c.addr, LENGTH(ps.verified_key_fingerprint) FROM contacts c \
|
||||
LEFT JOIN acpeerstates ps ON c.addr=ps.addr WHERE c.id IN({}) ",
|
||||
&to_ids_str,
|
||||
),
|
||||
params![],
|
||||
|row| Ok((row.get::<_, String>(0)?, row.get::<_, i32>(1)?)),
|
||||
|rows| rows.collect::<Result<Vec<_>, _>>().map_err(Into::into),
|
||||
);
|
||||
|
||||
// if we're here, we know the gossip key is verified:
|
||||
// - use the gossip-key as verified-key if there is no verified-key
|
||||
// - OR if the verified-key does not match public-key or gossip-key
|
||||
// (otherwise a verified key can _only_ be updated through QR scan which might be annoying,
|
||||
// see https://github.com/nextleap-project/countermitm/issues/46 for a discussion about this point)
|
||||
if 0 == is_verified
|
||||
|| peerstate.verified_key_fingerprint
|
||||
!= peerstate.public_key_fingerprint
|
||||
&& peerstate.verified_key_fingerprint
|
||||
!= peerstate.gossip_key_fingerprint
|
||||
{
|
||||
info!(
|
||||
context,
|
||||
0,
|
||||
"{} has verfied {}.",
|
||||
as_str((*contact).addr),
|
||||
to_addr,
|
||||
);
|
||||
let fp = peerstate.gossip_key_fingerprint.clone();
|
||||
if let Some(fp) = fp {
|
||||
peerstate.set_verified(0, &fp, 2);
|
||||
peerstate.save_to_db(&context.sql, false);
|
||||
is_verified = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if 0 == is_verified {
|
||||
verify_fail(format!(
|
||||
"{} is not a member of this verified group",
|
||||
to_addr
|
||||
));
|
||||
cleanup();
|
||||
return Err(failure::format_err!("not a valid member").into());
|
||||
}
|
||||
if rows.is_err() {
|
||||
cleanup();
|
||||
return 0;
|
||||
}
|
||||
for (to_addr, mut is_verified) in rows.unwrap().into_iter() {
|
||||
let mut peerstate = Peerstate::from_addr(context, &context.sql, &to_addr);
|
||||
if mimeparser.e2ee_helper.gossipped_addr.contains(&to_addr) && peerstate.is_some() {
|
||||
let peerstate = peerstate.as_mut().unwrap();
|
||||
|
||||
// if we're here, we know the gossip key is verified:
|
||||
// - use the gossip-key as verified-key if there is no verified-key
|
||||
// - OR if the verified-key does not match public-key or gossip-key
|
||||
// (otherwise a verified key can _only_ be updated through QR scan which might be annoying,
|
||||
// see https://github.com/nextleap-project/countermitm/issues/46 for a discussion about this point)
|
||||
if 0 == is_verified
|
||||
|| peerstate.verified_key_fingerprint != peerstate.public_key_fingerprint
|
||||
&& peerstate.verified_key_fingerprint != peerstate.gossip_key_fingerprint
|
||||
{
|
||||
info!(
|
||||
context,
|
||||
0,
|
||||
"{} has verfied {}.",
|
||||
as_str((*contact).addr),
|
||||
to_addr,
|
||||
);
|
||||
let fp = peerstate.gossip_key_fingerprint.clone();
|
||||
if let Some(fp) = fp {
|
||||
peerstate.set_verified(0, &fp, 2);
|
||||
peerstate.save_to_db(&context.sql, false);
|
||||
is_verified = 1;
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
.is_ok(); // TODO: Better default
|
||||
}
|
||||
}
|
||||
if 0 == is_verified {
|
||||
verify_fail(format!(
|
||||
"{} is not a member of this verified group",
|
||||
to_addr
|
||||
));
|
||||
cleanup();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup();
|
||||
|
||||
ok as libc::c_int
|
||||
1
|
||||
}
|
||||
|
||||
unsafe fn set_better_msg(mime_parser: &dc_mimeparser_t, better_msg: *mut *mut libc::c_char) {
|
||||
|
||||
Reference in New Issue
Block a user