fix: ignore html/* MIME parts

HTML parts have text/html MIME type.
html/* is not a registered MIME type: https://www.iana.org/assignments/media-types
This commit is contained in:
link2xt
2026-10-24 17:08:12 +00:00
committed by l
parent 4ce056c85c
commit f0be6c387e
3 changed files with 56 additions and 1 deletions
+1 -1
View File
@@ -1364,7 +1364,7 @@ impl MimeMessage {
self.do_add_single_part(part);
return Ok(true);
}
mime::TEXT | mime::HTML => {
mime::TEXT => {
let decoded_data = match mail.get_body() {
Ok(decoded_data) => decoded_data,
Err(err) => {
+24
View File
@@ -2228,3 +2228,27 @@ async fn test_load_shared_secrets_with_legacy_state() -> Result<()> {
Ok(())
}
/// Tests that MIME parts with html/* MIME type are ignored.
///
/// HTML parts should have a text/html MIME type.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_ignore_html_mime_parts() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;
let encrypted_msg = test_utils::encrypt_raw_message(
bob,
&[alice],
include_bytes!("../../test-data/message/html_html_mime.eml"),
)
.await?;
let msg = MimeMessage::from_bytes(alice, encrypted_msg.as_bytes()).await?;
assert_eq!(msg.parts.len(), 1);
assert_eq!(msg.parts[0].typ, Viewtype::Text);
assert_eq!(msg.parts[0].mimetype, Some(mime::TEXT_PLAIN));
assert_eq!(msg.parts[0].msg, "Here is a text part.");
Ok(())
}
+31
View File
@@ -0,0 +1,31 @@
From: Bob <bob@example.net>
Subject: Message with invalid HTML mime types
To: alice@example.org
Message-ID: <html-html-test@localhost>
Date: Thu, 17 Dec 2020 15:38:45 +0100
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="------------MESSAGE_BOUNDARY"
Content-Language: en-US
Chat-Version: 1.0
This is a multi-part message in MIME format.
--------------MESSAGE_BOUNDARY
Content-Type: html/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
This should be ignored.
--------------MESSAGE_BOUNDARY
Content-Type: html/html; charset=utf-8
Content-Transfer-Encoding: 7bit
And this should be ignored too.
--------------MESSAGE_BOUNDARY
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Here is a text part.
--------------MESSAGE_BOUNDARY--