]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Add extra heuristic for text parts
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 27 Nov 2018 15:20:55 +0000 (15:20 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 27 Nov 2018 15:20:55 +0000 (15:20 +0000)
src/libmime/message.c

index 46f528ba7ac94d484288c70e5d7b0456b45e665e..35ea5bb25f705c3ec9f275819f946125419bb9f7 100644 (file)
@@ -731,7 +731,36 @@ rspamd_message_process_text_part_maybe (struct rspamd_task *task,
                                found_html = TRUE;
                        }
                        else {
-                               found_txt = TRUE;
+                               /* We need to be extra careful with some stupid things here */
+
+                               html_tok.begin = "plain";
+                               html_tok.len = 5;
+
+                               if (rspamd_ftok_cmp (&mime_part->ct->subtype, &html_tok) == 0) {
+                                       found_txt = TRUE;
+                               }
+                               else {
+                                       if (mime_part->cd && mime_part->cd->filename.len > 4) {
+                                               const gchar *pos = mime_part->cd->filename.begin +
+                                                                                  mime_part->cd->filename.len -
+                                                                                  sizeof (".txt") + 1;
+                                               if (rspamd_lc_cmp (pos, ".txt", sizeof ("txt") - 1) == 0) {
+                                                       found_txt = TRUE;
+                                               }
+                                               else {
+                                                       msg_info_task ("found mime part with incorrect content-type: %T/%T, "
+                                                                                  "filename: %T",
+                                                                       &mime_part->ct->type,
+                                                                       &mime_part->ct->subtype,
+                                                                       &mime_part->cd->filename);
+                                                       mime_part->ct->flags |= RSPAMD_CONTENT_TYPE_BROKEN;
+                                               }
+                                       }
+                                       else {
+                                               /* For something like Content-Type: text */
+                                               found_txt = TRUE;
+                                       }
+                               }
                        }
 
                        if (found_html) {