From 89696582ada7f1ef76aec88a4aef7a14ec476e3d Mon Sep 17 00:00:00 2001 From: iequidoo Date: Sat, 18 Feb 2023 22:39:58 -0300 Subject: [PATCH] mimeparser: Handle headers from the signed part of unencrypted signed message This makes DC compatible with "multipart/signed" messages thus allowing switching to them someday from the current "multipart/mixed" unencrypted message format. --- CHANGELOG.md | 1 + src/mimeparser.rs | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39bb421be..3203bd410 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - Updated provider database. - Disable DKIM-Checks again #4076 - Switch from "X.Y.Z" and "py-X.Y.Z" to "vX.Y.Z" tags. #4089 +- mimeparser: handle headers from the signed part of unencrypted signed message #4013 ### Fixes - Start SQL transactions with IMMEDIATE behaviour rather than default DEFERRED one. #4063 diff --git a/src/mimeparser.rs b/src/mimeparser.rs index 075fd192f..50b71b092 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -224,8 +224,32 @@ impl MimeMessage { // Parse hidden headers. let mimetype = mail.ctype.mimetype.parse::()?; + let (part, mimetype) = + if mimetype.type_() == mime::MULTIPART && mimetype.subtype().as_str() == "signed" { + if let Some(part) = mail.subparts.first() { + // We don't remove "subject" from `headers` because currently just signed + // messages are shown as unencrypted anyway. + + MimeMessage::merge_headers( + context, + &mut headers, + &mut recipients, + &mut from, + &mut list_post, + &mut chat_disposition_notification_to, + &part.headers, + ); + (part, part.ctype.mimetype.parse::()?) + } else { + // If it's a partially fetched message, there are no subparts. + (&mail, mimetype) + } + } else { + // Currently we do not sign unencrypted messages by default. + (&mail, mimetype) + }; if mimetype.type_() == mime::MULTIPART && mimetype.subtype().as_str() == "mixed" { - if let Some(part) = mail.subparts.first() { + if let Some(part) = part.subparts.first() { for field in &part.headers { let key = field.get_key().to_lowercase();