Skip to content

Commit a2eec89

Browse files
committed
feat: Ignore unprotected headers if Content-Type has "hp" parameter (#7130)
This is a part of implementation of https://www.rfc-editor.org/rfc/rfc9788 "Header Protection for Cryptographically Protected Email".
1 parent 7f05914 commit a2eec89

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/mimeparser.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl MimeMessage {
272272
&mut from,
273273
&mut list_post,
274274
&mut chat_disposition_notification_to,
275-
&mail.headers,
275+
&mail,
276276
);
277277
headers.retain(|k, _| {
278278
!is_hidden(k) || {
@@ -300,7 +300,7 @@ impl MimeMessage {
300300
&mut from,
301301
&mut list_post,
302302
&mut chat_disposition_notification_to,
303-
&part.headers,
303+
part,
304304
);
305305
(part, part.ctype.mimetype.parse::<Mime>()?)
306306
} else {
@@ -530,7 +530,7 @@ impl MimeMessage {
530530
&mut inner_from,
531531
&mut list_post,
532532
&mut chat_disposition_notification_to,
533-
&mail.headers,
533+
mail,
534534
);
535535

536536
if !signatures.is_empty() {
@@ -1634,10 +1634,16 @@ impl MimeMessage {
16341634
from: &mut Option<SingleInfo>,
16351635
list_post: &mut Option<String>,
16361636
chat_disposition_notification_to: &mut Option<SingleInfo>,
1637-
fields: &[mailparse::MailHeader<'_>],
1637+
part: &mailparse::ParsedMail,
16381638
) {
1639+
let fields = &part.headers;
1640+
// See https://www.rfc-editor.org/rfc/rfc9788.html "Header Protection for Cryptographically
1641+
// Protected Email". We don't check if `part` is a root of the Cryptographic Payload because
1642+
// this function is only called with nonempty `headers` for such parts.
1643+
let has_header_protection = part.ctype.params.contains_key("hp");
1644+
16391645
headers.retain(|k, _| {
1640-
!is_protected(k) || {
1646+
!(has_header_protection || is_protected(k)) || {
16411647
headers_removed.insert(k.to_string());
16421648
false
16431649
}
@@ -2088,7 +2094,8 @@ pub(crate) fn parse_message_id(ids: &str) -> Result<String> {
20882094
}
20892095

20902096
/// Returns whether the outer header value must be ignored if the message contains a signed (and
2091-
/// optionally encrypted) part.
2097+
/// optionally encrypted) part. This is independent from the modern Header Protection defined in
2098+
/// <https://www.rfc-editor.org/rfc/rfc9788.html>.
20922099
///
20932100
/// NB: There are known cases when Subject and List-ID only appear in the outer headers of
20942101
/// signed-only messages. Such messages are shown as unencrypted anyway.

0 commit comments

Comments
 (0)