diff --git a/src/mimeparser.rs b/src/mimeparser.rs index 32bacab83..434ab9fd7 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -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) => { diff --git a/src/mimeparser/mimeparser_tests.rs b/src/mimeparser/mimeparser_tests.rs index fbe5b58a8..16c2bbf16 100644 --- a/src/mimeparser/mimeparser_tests.rs +++ b/src/mimeparser/mimeparser_tests.rs @@ -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(()) +} diff --git a/test-data/message/html_html_mime.eml b/test-data/message/html_html_mime.eml new file mode 100644 index 000000000..5b1179eee --- /dev/null +++ b/test-data/message/html_html_mime.eml @@ -0,0 +1,31 @@ +From: Bob +Subject: Message with invalid HTML mime types +To: alice@example.org +Message-ID: +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--