WIP: feat: add option to process unencrypted messages

This commit is contained in:
link2xt
2026-05-07 07:10:17 +02:00
parent 37abfa2c1c
commit f1652d4dd6
32 changed files with 1173 additions and 829 deletions

View File

@@ -111,6 +111,9 @@ async fn test_unencrypted_quote_encrypted_message() -> Result<()> {
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;
alice
.set_config_bool(Config::ProcessUnencrypted, true)
.await?;
tcm.section("Bob sends encrypted message to Alice");
let alice_chat = alice.create_chat(bob).await;
@@ -139,23 +142,14 @@ async fn test_unencrypted_quote_encrypted_message() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_get_chat_id() {
// Alice receives a message that pops up as a contact request
let alice = TestContext::new_alice().await;
receive_imf(
&alice,
b"From: Bob <bob@example.com>\n\
To: alice@example.org\n\
Chat-Version: 1.0\n\
Message-ID: <123@example.com>\n\
Date: Fri, 29 Jan 2021 21:37:55 +0000\n\
\n\
hello\n",
false,
)
.await
.unwrap();
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;
let chat_id = bob.create_chat_id(alice).await;
let sent = bob.send_text(chat_id, "hello").await;
let msg = alice.recv_msg(&sent).await;
// check chat-id of this message
let msg = alice.get_last_msg().await;
assert!(!msg.get_chat_id().is_special());
assert_eq!(msg.get_text(), "hello".to_string());
}
@@ -465,7 +459,11 @@ async fn test_get_state() -> Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_is_bot() -> Result<()> {
let alice = TestContext::new_alice().await;
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
alice
.set_config(Config::ProcessUnencrypted, Some("1"))
.await?;
// Alice receives an auto-generated non-chat message.
//
@@ -473,7 +471,7 @@ async fn test_is_bot() -> Result<()> {
// in which case the message should be marked as bot-generated,
// but the contact should not.
receive_imf(
&alice,
alice,
b"From: Claire <claire@example.com>\n\
To: alice@example.org\n\
Message-ID: <789@example.com>\n\
@@ -487,12 +485,12 @@ async fn test_is_bot() -> Result<()> {
let msg = alice.get_last_msg().await;
assert_eq!(msg.get_text(), "hello".to_string());
assert!(msg.is_bot());
let contact = Contact::get_by_id(&alice, msg.from_id).await?;
let contact = Contact::get_by_id(alice, msg.from_id).await?;
assert!(!contact.is_bot());
// Alice receives a message from Bob the bot.
receive_imf(
&alice,
alice,
b"From: Bob <bob@example.com>\n\
To: alice@example.org\n\
Chat-Version: 1.0\n\
@@ -507,12 +505,12 @@ async fn test_is_bot() -> Result<()> {
let msg = alice.get_last_msg().await;
assert_eq!(msg.get_text(), "hello".to_string());
assert!(msg.is_bot());
let contact = Contact::get_by_id(&alice, msg.from_id).await?;
let contact = Contact::get_by_id(alice, msg.from_id).await?;
assert!(contact.is_bot());
// Alice receives a message from Bob who is not the bot anymore.
receive_imf(
&alice,
alice,
b"From: Bob <bob@example.com>\n\
To: alice@example.org\n\
Chat-Version: 1.0\n\
@@ -526,7 +524,7 @@ async fn test_is_bot() -> Result<()> {
let msg = alice.get_last_msg().await;
assert_eq!(msg.get_text(), "hello again".to_string());
assert!(!msg.is_bot());
let contact = Contact::get_by_id(&alice, msg.from_id).await?;
let contact = Contact::get_by_id(alice, msg.from_id).await?;
assert!(!contact.is_bot());
Ok(())