mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 17:06:35 +03:00
fix: Save mime headers for messages not signed with a known key (#4557)
If a message is unsigned or signed with an unknown key, `MimeMessage::was_encrypted()` returns false. So, it mustn't be checked when deciding whether to look into `MimeMessage::decoded_data`. Looking through git history one can see that it's just a wrong check left in the code for historical reasons.
This commit is contained in:
@@ -29,14 +29,30 @@ pub fn try_decrypt(
|
|||||||
private_keyring: &Keyring<SignedSecretKey>,
|
private_keyring: &Keyring<SignedSecretKey>,
|
||||||
public_keyring_for_validate: &Keyring<SignedPublicKey>,
|
public_keyring_for_validate: &Keyring<SignedPublicKey>,
|
||||||
) -> Result<Option<(Vec<u8>, HashSet<Fingerprint>)>> {
|
) -> Result<Option<(Vec<u8>, HashSet<Fingerprint>)>> {
|
||||||
let encrypted_data_part = match get_autocrypt_mime(mail)
|
let encrypted_data_part = match {
|
||||||
.or_else(|| get_mixed_up_mime(mail))
|
let mime = get_autocrypt_mime(mail);
|
||||||
.or_else(|| get_attachment_mime(mail))
|
if mime.is_some() {
|
||||||
{
|
info!(context, "Detected Autocrypt-mime message.");
|
||||||
|
}
|
||||||
|
mime
|
||||||
|
}
|
||||||
|
.or_else(|| {
|
||||||
|
let mime = get_mixed_up_mime(mail);
|
||||||
|
if mime.is_some() {
|
||||||
|
info!(context, "Detected mixed-up mime message.");
|
||||||
|
}
|
||||||
|
mime
|
||||||
|
})
|
||||||
|
.or_else(|| {
|
||||||
|
let mime = get_attachment_mime(mail);
|
||||||
|
if mime.is_some() {
|
||||||
|
info!(context, "Detected attached Autocrypt-mime message.");
|
||||||
|
}
|
||||||
|
mime
|
||||||
|
}) {
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
Some(res) => res,
|
Some(res) => res,
|
||||||
};
|
};
|
||||||
info!(context, "Detected Autocrypt-mime message");
|
|
||||||
|
|
||||||
decrypt_part(
|
decrypt_part(
|
||||||
encrypted_data_part,
|
encrypted_data_part,
|
||||||
@@ -403,4 +419,18 @@ mod tests {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn test_mixed_up_mime_long() -> Result<()> {
|
||||||
|
// Long "mixed-up" mail as received when sending an encrypted message using Delta Chat
|
||||||
|
// Desktop via MS Exchange (actually made with TB though).
|
||||||
|
let mixed_up_mime = include_bytes!("../test-data/message/mixed-up-long.eml");
|
||||||
|
let bob = TestContext::new_bob().await;
|
||||||
|
receive_imf(&bob, mixed_up_mime, false).await?;
|
||||||
|
let msg = bob.get_last_msg().await;
|
||||||
|
assert!(!msg.get_text().is_empty());
|
||||||
|
assert!(msg.has_html());
|
||||||
|
assert!(msg.id.get_html(&bob).await?.unwrap().len() > 40000);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1068,7 +1068,7 @@ async fn add_parts(
|
|||||||
let mut save_mime_modified = mime_parser.is_mime_modified;
|
let mut save_mime_modified = mime_parser.is_mime_modified;
|
||||||
|
|
||||||
let mime_headers = if save_mime_headers || save_mime_modified {
|
let mime_headers = if save_mime_headers || save_mime_modified {
|
||||||
let headers = if mime_parser.was_encrypted() && !mime_parser.decoded_data.is_empty() {
|
let headers = if !mime_parser.decoded_data.is_empty() {
|
||||||
mime_parser.decoded_data.clone()
|
mime_parser.decoded_data.clone()
|
||||||
} else {
|
} else {
|
||||||
imf_raw.to_vec()
|
imf_raw.to_vec()
|
||||||
|
|||||||
1436
test-data/message/mixed-up-long.eml
Normal file
1436
test-data/message/mixed-up-long.eml
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user