refactor: remove pre_encrypt_mime_hook

It is only used in a single test
and the test is more reliable by having a blob .eml
that will not be accidentally modified
by mimefactory changes.
This commit is contained in:
link2xt
2026-05-26 08:10:51 +00:00
committed by l
parent 627f98915d
commit 480248a168
5 changed files with 78 additions and 46 deletions
+15 -23
View File
@@ -1790,35 +1790,27 @@ async fn test_time_in_future() -> Result<()> {
Ok(())
}
/// Tests receiving a message with RFC 9788 header protection and legacy display element.
///
/// Legacy display elements should not be rendered:
/// <https://www.rfc-editor.org/rfc/rfc9788.html#name-do-not-render-legacy-displa>
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_hp_legacy_display() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;
let mut msg = Message::new_text(
"Subject: Dinner plans\n\
\n\
Let's eat"
.to_string(),
);
msg.set_subject("Dinner plans".to_string());
let chat_id = alice.create_chat(bob).await.id;
alice.set_config_bool(Config::TestHooks, true).await?;
*alice.pre_encrypt_mime_hook.lock() = Some(|_, mut mime| {
for (h, v) in &mut mime.headers {
if h == "Content-Type"
&& let mail_builder::headers::HeaderType::ContentType(ct) = v
{
*ct = ct.clone().attribute("hp-legacy-display", "1");
}
}
mime
});
let sent_msg = alice.send_msg(chat_id, &mut msg).await;
let msg_bob = bob.recv_msg(&sent_msg).await;
let msg_id = receive_imf(
bob,
include_bytes!("../../test-data/message/hp_legacy_display.eml"),
false,
)
.await?
.unwrap()
.msg_ids[0];
let msg_bob = Message::load_from_db(bob, msg_id).await?;
assert_eq!(msg_bob.subject, "Dinner plans");
// Legacy display element is removed from the text/plain body.
assert_eq!(msg_bob.text, "Let's eat");
Ok(())
}