]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Detect empty text part as text, not HTML 2380/head
authorMikhail Galanin <mgalanin@mimecast.com>
Fri, 27 Jul 2018 15:57:32 +0000 (16:57 +0100)
committerMikhail Galanin <mgalanin@mimecast.com>
Fri, 27 Jul 2018 15:57:32 +0000 (16:57 +0100)
Issue: #2367

src/libmime/message.c
test/functional/cases/105_mimetypes.robot
test/functional/messages/empty-plain-text.eml [new file with mode: 0644]

index 6208f6424bc2286414bb4cd65739122b06408eaa..76f63ed1a72a3ea4751a02314ee1a0711e9b1fea 100644 (file)
@@ -675,16 +675,21 @@ rspamd_message_process_text_part (struct rspamd_task *task,
                        RSPAMD_FTOK_ASSIGN (&html_tok, "<!DOCTYPE html");
                        RSPAMD_FTOK_ASSIGN (&xhtml_tok, "<html");
 
-                       if (rspamd_lc_cmp (mime_part->parsed_data.begin, html_tok.begin,
-                                       MIN (html_tok.len, mime_part->parsed_data.len)) == 0 ||
-                                       rspamd_lc_cmp (mime_part->parsed_data.begin, xhtml_tok.begin,
-                                                       MIN (xhtml_tok.len, mime_part->parsed_data.len)) == 0) {
-                               msg_info_task ("found html part pretending to be text/plain part");
+                       if (mime_part->parsed_data.len >= xhtml_tok.len &&
+                                       rspamd_lc_cmp (mime_part->parsed_data.begin, xhtml_tok.begin, xhtml_tok.len)) {
+                               found_html = TRUE;
+                       }
+                       else if (mime_part->parsed_data.len >= html_tok.len &&
+                                       rspamd_lc_cmp (mime_part->parsed_data.begin, html_tok.begin, html_tok.len)) {
                                found_html = TRUE;
                        }
                        else {
                                found_txt = TRUE;
                        }
+
+                       if (found_html) {
+                               msg_info_task ("found html part pretending to be text/plain part");
+                       }
                }
        }
        else {
index 895255194787c566d23b41a4be2f9f23bec36f00..3c1a039304790268666d86c1ba651369b26ae193 100644 (file)
@@ -45,6 +45,10 @@ Multipart Archive Extension
   ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/f.zip.001.eml
   Should Not Contain  ${result.stdout}  MIME_ARCHIVE_IN_ARCHIVE
 
+Empty text part should not be treat as html
+  ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/empty-plain-text.eml
+  Should Not Contain  ${result.stdout}  FORGED_OUTLOOK_HTML
+
 *** Keywords ***
 MIMETypes Setup
   ${PLUGIN_CONFIG} =  Get File  ${TESTDIR}/configs/mime_types.conf
diff --git a/test/functional/messages/empty-plain-text.eml b/test/functional/messages/empty-plain-text.eml
new file mode 100644 (file)
index 0000000..2c4fa3e
--- /dev/null
@@ -0,0 +1,14 @@
+Return-Path: test@test.com
+From: TEST <test@test.com>
+MIME-Version: 1.0
+X-Priority: 1 (Highest)
+X-MSMail-Priority: High
+X-Mailer: Microsoft Outlook 16.0
+Importance: High
+Date: Mon, 23 Jul 2018 16:24:13 +0200
+Message-ID: <d9946a191e0c97733a86424c48e65eca@test.com>
+Subject: Test Subject
+To: Me <me@me.me>
+Content-Type: text/plain; charset="UTF-8"
+
+