mirror of
https://github.com/chatmail/core.git
synced 2026-05-14 20:36:30 +03:00
WIP: feat: add option to process unencrypted messages
This commit is contained in:
@@ -12,7 +12,7 @@ use crate::{
|
||||
message::{MessageState, MessengerMessage},
|
||||
receive_imf::receive_imf,
|
||||
securejoin::QrInvite,
|
||||
test_utils::{TestContext, TestContextManager},
|
||||
test_utils::{self, TestContext, TestContextManager},
|
||||
tools::time,
|
||||
};
|
||||
|
||||
@@ -1503,31 +1503,23 @@ Some reply
|
||||
// Test that WantsMdn parameter is not set on outgoing messages.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_outgoing_wants_mdn() -> Result<()> {
|
||||
let alice = TestContext::new_alice().await;
|
||||
let bob = TestContext::new_bob().await;
|
||||
let mut tcm = TestContextManager::new();
|
||||
let alice = &tcm.alice().await;
|
||||
let alice2 = &tcm.alice().await;
|
||||
let bob = &tcm.bob().await;
|
||||
|
||||
let raw = br"Date: Thu, 28 Jan 2021 00:26:57 +0000
|
||||
Chat-Version: 1.0\n\
|
||||
Message-ID: <foobarbaz@example.org>
|
||||
To: Bob <bob@example.org>
|
||||
From: Alice <alice@example.org>
|
||||
Subject: subject
|
||||
Chat-Disposition-Notification-To: alice@example.org
|
||||
|
||||
Message.
|
||||
";
|
||||
let chat_id = alice.create_chat(bob).await.id;
|
||||
let sent = alice.send_text(chat_id, "Message.").await;
|
||||
|
||||
// Bob receives message.
|
||||
receive_imf(&bob, raw, false).await?;
|
||||
let msg = bob.get_last_msg().await;
|
||||
let bob_msg = bob.recv_msg(&sent).await;
|
||||
// Message is incoming.
|
||||
assert!(msg.param.get_bool(Param::WantsMdn).unwrap());
|
||||
assert!(bob_msg.param.get_bool(Param::WantsMdn).unwrap());
|
||||
|
||||
// Alice receives copy-to-self.
|
||||
receive_imf(&alice, raw, false).await?;
|
||||
let msg = alice.get_last_msg().await;
|
||||
let alice2_msg = alice2.recv_msg(&sent).await;
|
||||
// Message is outgoing, don't send read receipt to self.
|
||||
assert!(msg.param.get_bool(Param::WantsMdn).is_none());
|
||||
assert!(alice2_msg.param.get_bool(Param::WantsMdn).is_none());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1604,7 +1596,9 @@ async fn test_ignore_read_receipt_to_self() -> Result<()> {
|
||||
/// recognize it as MDN nevertheless to avoid displaying it in the chat as normal message.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_ms_exchange_mdn() -> Result<()> {
|
||||
let t = TestContext::new_alice().await;
|
||||
let mut tcm = TestContextManager::new();
|
||||
let t = tcm.alice().await;
|
||||
t.set_config(Config::ProcessUnencrypted, Some("1")).await?;
|
||||
|
||||
let original =
|
||||
include_bytes!("../../test-data/message/ms_exchange_report_original_message.eml");
|
||||
@@ -2048,6 +2042,8 @@ async fn test_multiple_autocrypt_hdrs() -> Result<()> {
|
||||
async fn test_receive_signed_only() -> Result<()> {
|
||||
let mut tcm = TestContextManager::new();
|
||||
let bob = &tcm.bob().await;
|
||||
bob.set_config(Config::ProcessUnencrypted, Some("1"))
|
||||
.await?;
|
||||
|
||||
let imf_raw = include_bytes!("../../test-data/message/unencrypted_signed_simple.eml");
|
||||
let msg = receive_imf(bob, imf_raw, false).await?.unwrap();
|
||||
@@ -2088,19 +2084,24 @@ async fn test_huge_image_becomes_file() -> Result<()> {
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_4k_image_stays_image() -> Result<()> {
|
||||
let t = TestContext::new_alice().await;
|
||||
let msg_id = receive_imf(
|
||||
&t,
|
||||
let mut tcm = TestContextManager::new();
|
||||
let alice = &tcm.alice().await;
|
||||
let bob = &tcm.bob().await;
|
||||
let encrypted_msg = test_utils::encrypt_raw_message(
|
||||
bob,
|
||||
&[alice],
|
||||
include_bytes!("../../test-data/message/image_4k.eml"),
|
||||
false,
|
||||
)
|
||||
.await?
|
||||
.unwrap()
|
||||
.msg_ids[0];
|
||||
let msg = Message::load_from_db(&t.ctx, msg_id).await.unwrap();
|
||||
.await?;
|
||||
|
||||
let msg_id = receive_imf(alice, encrypted_msg.as_bytes(), false)
|
||||
.await?
|
||||
.unwrap()
|
||||
.msg_ids[0];
|
||||
let msg = Message::load_from_db(alice, msg_id).await.unwrap();
|
||||
// 4K image should be treated as image:
|
||||
assert_eq!(msg.viewtype, Viewtype::Image);
|
||||
assert!(msg.get_file(&t).is_some());
|
||||
assert!(msg.get_file(alice).is_some());
|
||||
assert_eq!(msg.get_filename().unwrap(), "4k_image.png");
|
||||
assert_eq!(msg.get_filemime().unwrap(), "image/png");
|
||||
assert_eq!(msg.param.get_int(Param::Width).unwrap_or_default(), 3840);
|
||||
|
||||
Reference in New Issue
Block a user