summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Galanin <mgalanin@mimecast.com>2018-07-27 16:57:32 +0100
committerMikhail Galanin <mgalanin@mimecast.com>2018-07-27 16:57:32 +0100
commit6a1a93fffccd1344c87b33d7baacf9d25b5ba97b (patch)
treec85b02f48d78c03390eef08d352a9d400674be8d
parentdb3d0cb4b994558f63a28011a13a9e08d5f6d1d8 (diff)
downloadrspamd-6a1a93fffccd1344c87b33d7baacf9d25b5ba97b.tar.gz
rspamd-6a1a93fffccd1344c87b33d7baacf9d25b5ba97b.zip
[Fix] Detect empty text part as text, not HTML
Issue: #2367
-rw-r--r--src/libmime/message.c15
-rw-r--r--test/functional/cases/105_mimetypes.robot4
-rw-r--r--test/functional/messages/empty-plain-text.eml14
3 files changed, 28 insertions, 5 deletions
diff --git a/src/libmime/message.c b/src/libmime/message.c
index 6208f6424..76f63ed1a 100644
--- a/src/libmime/message.c
+++ b/src/libmime/message.c
@@ -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 {
diff --git a/test/functional/cases/105_mimetypes.robot b/test/functional/cases/105_mimetypes.robot
index 895255194..3c1a03930 100644
--- a/test/functional/cases/105_mimetypes.robot
+++ b/test/functional/cases/105_mimetypes.robot
@@ -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
index 000000000..2c4fa3e90
--- /dev/null
+++ b/test/functional/messages/empty-plain-text.eml
@@ -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"
+
+