Skip to content

Commit c9c5d94

Browse files
authored
fix: Prefer encrypted List-Id header (#6983)
If there is an encrypted List-Id header, it should be preferred over an unencrypted List-Id header. Part of #6884
1 parent aad8f69 commit c9c5d94

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/chat/chat_tests.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::ephemeral::Timer;
55
use crate::headerdef::HeaderDef;
66
use crate::imex::{ImexMode, has_backup, imex};
77
use crate::message::{MessengerMessage, delete_msgs};
8+
use crate::mimeparser;
89
use crate::receive_imf::receive_imf;
910
use crate::test_utils::{
1011
AVATAR_64x64_BYTES, AVATAR_64x64_DEDUPLICATED, TestContext, TestContextManager,
@@ -2889,6 +2890,52 @@ async fn test_block_broadcast() -> Result<()> {
28892890
Ok(())
28902891
}
28912892

2893+
/// Tests that a List-Id header in the encrypted part
2894+
/// overrides a List-Id header in the unencrypted part,
2895+
/// and that the List-Id isn't visible in the unencrypted part.
2896+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
2897+
async fn test_broadcast_channel_protected_listid() -> Result<()> {
2898+
let mut tcm = TestContextManager::new();
2899+
let alice = &tcm.alice().await;
2900+
let bob = &tcm.bob().await;
2901+
let alice_bob_contact_id = alice.add_or_lookup_contact_id(bob).await;
2902+
2903+
tcm.section("Create a broadcast channel with Bob, and send a message");
2904+
let alice_chat_id = create_broadcast(alice, "My Channel".to_string()).await?;
2905+
add_contact_to_chat(alice, alice_chat_id, alice_bob_contact_id).await?;
2906+
let mut sent = alice.send_text(alice_chat_id, "Hi somebody").await;
2907+
2908+
assert!(!sent.payload.contains("List-ID"));
2909+
// Do the counter check that the Message-Id header is present:
2910+
assert!(sent.payload.contains("Message-ID"));
2911+
2912+
// Check that Delta Chat ignores an injected List-ID header:
2913+
let new_payload = sent.payload.replace(
2914+
"Date: ",
2915+
"List-ID: some wrong listid that would make things fail\nDate: ",
2916+
);
2917+
assert_ne!(&sent.payload, &new_payload);
2918+
sent.payload = new_payload;
2919+
2920+
let alice_list_id = Chat::load_from_db(alice, sent.load_from_db().await.chat_id)
2921+
.await?
2922+
.grpid;
2923+
2924+
let parsed = mimeparser::MimeMessage::from_bytes(bob, sent.payload.as_bytes(), None).await?;
2925+
assert_eq!(
2926+
parsed.get_mailinglist_header().unwrap(),
2927+
format!("My Channel <{}>", alice_list_id)
2928+
);
2929+
2930+
let rcvd = bob.recv_msg(&sent).await;
2931+
assert_eq!(
2932+
Chat::load_from_db(bob, rcvd.chat_id).await?.grpid,
2933+
alice_list_id
2934+
);
2935+
2936+
Ok(())
2937+
}
2938+
28922939
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
28932940
async fn test_create_for_contact_with_blocked() -> Result<()> {
28942941
let t = TestContext::new().await;

src/mimeparser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,6 +2007,7 @@ fn is_known(key: &str) -> bool {
20072007
| "references"
20082008
| "subject"
20092009
| "secure-join"
2010+
| "list-id"
20102011
)
20112012
}
20122013

0 commit comments

Comments
 (0)