From 4b92b06ddf038043e00c6ca46ad897a149dcc0e5 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 19 Dec 2019 07:59:38 +0100 Subject: [PATCH] add a test that contacts are properly created and fix ordering in dc_receive_imf to pass the test --- python/tests/test_account.py | 9 +++++++++ src/contact.rs | 3 ++- src/dc_receive_imf.rs | 36 ++++++++++++++++++------------------ 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/python/tests/test_account.py b/python/tests/test_account.py index f6fbdd442..61d4d770c 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -1209,6 +1209,15 @@ class TestGroupStressTests: print("chat is", msg.chat) assert len(msg.chat.get_contacts()) == 4 + lp.sec("ac3: checking that 'ac4' is a known contact") + ac3 = accounts[1] + msg3 = ac3.wait_next_incoming_message() + assert msg3.text == "hello" + contacts = ac3.get_contacts() + assert len(contacts) == 3 + ac4_contacts = ac3.get_contacts(query=accounts[2].get_config("addr")) + assert len(ac4_contacts) == 1 + lp.sec("ac1: removing one contacts and checking things are right") to_remove = msg.chat.get_contacts()[-1] msg.chat.remove_contact(to_remove) diff --git a/src/contact.rs b/src/contact.rs index bd1cb1b3a..2d26de322 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -401,6 +401,7 @@ impl Contact { { row_id = sql::get_rowid(context, &context.sql, "contacts", "addr", addr); sth_modified = Modifier::Created; + info!(context, "added contact id={} addr={}", row_id, addr); } else { error!(context, "Cannot add contact."); } @@ -486,7 +487,7 @@ impl Contact { params![ self_addr, DC_CONTACT_ID_LAST_SPECIAL as i32, - 0x100, + Origin::IncomingReplyTo, &s3str_like_cmd, &s3str_like_cmd, if flag_verified_only { 0 } else { 1 }, diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 0d98d1a7c..475533baf 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -61,8 +61,6 @@ pub fn dc_receive_imf( ensure!(mime_parser.has_headers(), "No Headers Found"); // the function returns the number of created messages in the database - let mut incoming = true; - let mut incoming_origin = Origin::Unknown; let mut to_id = 0u32; let mut chat_id = 0; let mut hidden = false; @@ -102,28 +100,14 @@ pub fn dc_receive_imf( sent_timestamp = mailparse::dateparse(value).unwrap_or_default(); } - // Make sure, to_ids starts with the first To:-address (Cc: is added in the loop below pass) - if let Some(field) = mime_parser.get(HeaderDef::To) { - dc_add_or_lookup_contacts_by_address_list( - context, - &field, - if !incoming { - Origin::OutgoingTo - } else if incoming_origin.is_verified() { - Origin::IncomingTo - } else { - Origin::IncomingUnknownTo - }, - &mut to_ids, - )?; - } - // get From: (it can be an address list!) and check if it is known (for known From:'s we add // the other To:/Cc: in the 3rd pass) // or if From: is equal to SELF (in this case, it is any outgoing messages, // we do not check Return-Path any more as this is unreliable, see issue #150) let mut from_id = 0; let mut from_id_blocked = false; + let mut incoming = true; + let mut incoming_origin = Origin::Unknown; if let Some(field_from) = mime_parser.get(HeaderDef::From_) { let mut from_ids = ContactIds::new(); @@ -155,6 +139,22 @@ pub fn dc_receive_imf( } } + // Make sure, to_ids starts with the first To:-address (Cc: is added in the loop below pass) + if let Some(field) = mime_parser.get(HeaderDef::To) { + dc_add_or_lookup_contacts_by_address_list( + context, + &field, + if !incoming { + Origin::OutgoingTo + } else if incoming_origin.is_verified() { + Origin::IncomingTo + } else { + Origin::IncomingUnknownTo + }, + &mut to_ids, + )?; + } + // Add parts let rfc724_mid = match mime_parser.get_rfc724_mid() {