fix: Ignore hidden headers in IMF section

Hidden headers are nonstandard, so they aren't DKIM-signed by e.g. OpenDKIM if they appear in IMF
section.
This commit is contained in:
iequidoo
2025-03-05 19:40:37 -03:00
committed by iequidoo
parent b5acbaa31c
commit c12c4f64c4
6 changed files with 67 additions and 18 deletions

View File

@@ -253,6 +253,7 @@ impl MimeMessage {
&mut chat_disposition_notification_to,
&mail.headers,
);
headers.retain(|k, _| !is_hidden(k));
// Parse hidden headers.
let mimetype = mail.ctype.mimetype.parse::<Mime>()?;
@@ -289,12 +290,7 @@ impl MimeMessage {
let key = field.get_key().to_lowercase();
// For now only avatar headers can be hidden.
if !headers.contains_key(&key)
&& (key == "chat-user-avatar"
|| key == "chat-group-avatar"
|| key == "chat-delete"
|| key == "chat-edit")
{
if !headers.contains_key(&key) && is_hidden(&key) {
headers.insert(key.to_string(), field.get_value());
}
}
@@ -1988,6 +1984,14 @@ fn is_known(key: &str) -> bool {
)
}
/// Returns if the header is hidden and must be ignored in the IMF section.
pub(crate) fn is_hidden(key: &str) -> bool {
matches!(
key,
"chat-user-avatar" | "chat-group-avatar" | "chat-delete" | "chat-edit"
)
}
/// Parsed MIME part.
#[derive(Debug, Default, Clone)]
pub struct Part {