Skip to content

Commit c07b5c9

Browse files
committed
fix: use protected Date header for signed messages
1 parent 7f55613 commit c07b5c9

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/mimeparser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl MimeMessage {
264264
// messages are shown as unencrypted anyway.
265265

266266
timestamp_sent =
267-
Self::get_timestamp_sent(&mail.headers, timestamp_sent, timestamp_rcvd);
267+
Self::get_timestamp_sent(&part.headers, timestamp_sent, timestamp_rcvd);
268268
MimeMessage::merge_headers(
269269
context,
270270
&mut headers,

src/mimeparser/mimeparser_tests.rs

+29
Original file line numberDiff line numberDiff line change
@@ -1982,3 +1982,32 @@ async fn test_chat_edit_imf_header() -> Result<()> {
19821982

19831983
Ok(())
19841984
}
1985+
1986+
/// Tests that timestamp of signed but not encrypted message is protected.
1987+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
1988+
async fn test_protected_date() -> Result<()> {
1989+
let mut tcm = TestContextManager::new();
1990+
let alice = &tcm.alice().await;
1991+
let bob = &tcm.bob().await;
1992+
1993+
alice.set_config(Config::SignUnencrypted, Some("1")).await?;
1994+
1995+
let alice_chat = alice.create_email_chat(bob).await;
1996+
let alice_msg_id = chat::send_text_msg(alice, alice_chat.id, "Hello!".to_string()).await?;
1997+
let alice_msg = Message::load_from_db(alice, alice_msg_id).await?;
1998+
assert_eq!(alice_msg.get_showpadlock(), false);
1999+
2000+
let mut sent_msg = alice.pop_sent_msg().await;
2001+
sent_msg.payload = sent_msg.payload.replacen(
2002+
"Date:",
2003+
"Date: Wed, 17 Mar 2021 14:30:53 +0100 (CET)\r\nX-Not-Date:",
2004+
1,
2005+
);
2006+
let bob_msg = bob.recv_msg(&sent_msg).await;
2007+
assert_eq!(alice_msg.get_text(), bob_msg.get_text());
2008+
2009+
// Timestamp that the sender has put into the message
2010+
// should always be displayed as is on the receiver.
2011+
assert_eq!(alice_msg.get_timestamp(), bob_msg.get_timestamp());
2012+
Ok(())
2013+
}

0 commit comments

Comments
 (0)