From: Mikhail Galanin Date: Fri, 27 Jul 2018 15:57:32 +0000 (+0100) Subject: [Fix] Detect empty text part as text, not HTML X-Git-Tag: 1.7.9~30^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6a1a93fffccd1344c87b33d7baacf9d25b5ba97b;p=rspamd.git [Fix] Detect empty text part as text, not HTML Issue: #2367 --- 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, "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 +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: +Subject: Test Subject +To: Me +Content-Type: text/plain; charset="UTF-8" + +