mimeparser: assume all Thunderbird users prefer encryption

Co-Authored-By: missytake <missytake@systemli.org>
This commit is contained in:
link2xt
2022-11-23 23:09:03 +00:00
parent a76b018900
commit b341cfd4d9
5 changed files with 128 additions and 3 deletions

View File

@@ -5,7 +5,7 @@ use std::collections::HashSet;
use anyhow::{Context as _, Result};
use mailparse::ParsedMail;
use crate::aheader::Aheader;
use crate::aheader::{Aheader, EncryptPreference};
use crate::authres;
use crate::authres::handle_authres;
use crate::contact::addr_cmp;
@@ -60,11 +60,18 @@ pub(crate) async fn prepare_decryption(
mail: &ParsedMail<'_>,
from: &str,
message_time: i64,
is_thunderbird: bool,
) -> Result<DecryptionInfo> {
let autocrypt_header = Aheader::from_headers(from, &mail.headers)
let mut autocrypt_header = Aheader::from_headers(from, &mail.headers)
.ok_or_log_msg(context, "Failed to parse Autocrypt header")
.flatten();
if is_thunderbird {
if let Some(autocrypt_header) = &mut autocrypt_header {
autocrypt_header.prefer_encrypt = EncryptPreference::Mutual;
}
}
let dkim_results = handle_authres(context, mail, from, message_time).await?;
let peerstate = get_autocrypt_peerstate(

View File

@@ -216,9 +216,16 @@ impl MimeMessage {
headers.remove("secure-join-fingerprint");
headers.remove("chat-verified");
let is_thunderbird = if let Some(user_agent) = headers.get("user-agent") {
info!(context, "Detected thunderbird");
user_agent.contains("Thunderbird")
} else {
false
};
let from = from.context("No from in message")?;
let mut decryption_info =
prepare_decryption(context, &mail, &from.addr, message_time).await?;
prepare_decryption(context, &mail, &from.addr, message_time, is_thunderbird).await?;
// Memory location for a possible decrypted message.
let mut mail_raw = Vec::new();

View File

@@ -2277,6 +2277,7 @@ mod tests {
use super::*;
use crate::aheader::EncryptPreference;
use crate::chat::get_chat_contacts;
use crate::chat::{get_chat_msgs, ChatItem, ChatVisibility};
use crate::chatlist::Chatlist;
@@ -5299,4 +5300,20 @@ Reply from different address
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_thunderbird_autocrypt() -> Result<()> {
let t = TestContext::new_bob().await;
t.set_config(Config::ShowEmails, Some("2")).await?;
let raw = include_bytes!("../test-data/message/thunderbird_with_autocrypt.eml");
receive_imf(&t, raw, false).await?;
let peerstate = Peerstate::from_addr(&t, "alice@example.org")
.await?
.unwrap();
assert_eq!(peerstate.prefer_encrypt, EncryptPreference::Mutual);
Ok(())
}
}