Skip to content

Commit 3fa1ec9

Browse files
committed
fix: use protected Date header when available
1 parent 7f55613 commit 3fa1ec9

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

Diff for: src/mimeparser.rs

+13-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,
@@ -345,6 +345,18 @@ impl MimeMessage {
345345
}
346346

347347
decrypted_msg = Some(msg);
348+
349+
if let Some(protected_timestamp_sent) = decrypted_mail
350+
.headers
351+
.get_header_value(HeaderDef::Date)
352+
.and_then(|v| mailparse::dateparse(&v).ok())
353+
{
354+
timestamp_sent = min(
355+
protected_timestamp_sent,
356+
timestamp_rcvd + constants::TIMESTAMP_SENT_TOLERANCE,
357+
)
358+
}
359+
348360
if let Some(protected_aheader_value) = decrypted_mail
349361
.headers
350362
.get_header_value(HeaderDef::Autocrypt)

Diff for: 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 encrypted but not signed 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)