mirror of
https://github.com/chatmail/core.git
synced 2026-10-26 06:48:01 +03:00
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:
+1
-1
@@ -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) => {
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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--
|
||||
Reference in New Issue
Block a user