diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 0dd1dece3..b633d9112 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -1655,19 +1655,22 @@ async fn apply_group_changes( }; // Whether to allow any changes to the member list at all. - let allow_member_list_changes = - if chat::is_contact_in_chat(context, chat_id, ContactId::SELF).await? || self_added { - // Reject old group changes. - chat_id - .update_timestamp(context, Param::MemberListTimestamp, sent_timestamp) - .await? - } else { - // Member list changes are not allowed if we're not in the group - // and are not explicitly added. - // This message comes from a Delta Chat that restored an old backup - // or the message is a MUA reply to an old message. - false - }; + let allow_member_list_changes = if chat::is_contact_in_chat(context, chat_id, ContactId::SELF) + .await? + || self_added + || !mime_parser.has_chat_version() + { + // Reject old group changes. + chat_id + .update_timestamp(context, Param::MemberListTimestamp, sent_timestamp) + .await? + } else { + // Member list changes are not allowed if we're not in the group + // and are not explicitly added. + // This message comes from a Delta Chat that restored an old backup + // or the message is a MUA reply to an old message. + false + }; // Whether to rebuild the member list from scratch. let recreate_member_list = if allow_member_list_changes { diff --git a/src/receive_imf/tests.rs b/src/receive_imf/tests.rs index 5036b1a24..75f973274 100644 --- a/src/receive_imf/tests.rs +++ b/src/receive_imf/tests.rs @@ -3560,3 +3560,52 @@ async fn test_mua_can_add() -> Result<()> { ); Ok(()) } + +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_mua_can_readd() -> Result<()> { + let alice = TestContext::new_alice().await; + + // Alice creates chat with 3 contacts. + let msg = receive_imf( + &alice, + b"Subject: =?utf-8?q?Message_from_alice=40example=2Eorg?=\r\n\ + From: alice@example.org\r\n\ + To: , , \r\n\ + Date: Mon, 12 Dec 2022 14:30:39 +0000\r\n\ + Message-ID: \r\n\ + Chat-Version: 1.0\r\n\ + \r\n\ + Hi!\r\n", + false, + ) + .await? + .unwrap(); + let alice_chat = Chat::load_from_db(&alice, msg.chat_id).await?; + assert_eq!(alice_chat.typ, Chattype::Group); + assert!(is_contact_in_chat(&alice, alice_chat.id, ContactId::SELF).await?); + + // And leaves it. + remove_contact_from_chat(&alice, alice_chat.id, ContactId::SELF).await?; + let alice_chat = Chat::load_from_db(&alice, alice_chat.id).await?; + assert!(!is_contact_in_chat(&alice, alice_chat.id, ContactId::SELF).await?); + + // Bob uses a classical MUA to answer, adding Alice back. + receive_imf( + &alice, + b"Subject: Re: Message from alice\r\n\ + From: \r\n\ + To: , , \r\n\ + Date: Mon, 12 Dec 2022 14:32:39 +0000\r\n\ + Message-ID: \r\n\ + In-Reply-To: \r\n\ + \r\n\ + Hi back!\r\n", + false, + ) + .await? + .unwrap(); + + let alice_chat = Chat::load_from_db(&alice, alice_chat.id).await?; + assert!(is_contact_in_chat(&alice, alice_chat.id, ContactId::SELF).await?); + Ok(()) +}