]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Add a special logic for text part with no text extraction
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 16 Aug 2021 10:19:40 +0000 (11:19 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 16 Aug 2021 10:24:20 +0000 (11:24 +0100)
lualib/lua_magic/types.lua
src/libmime/message.c
src/libmime/message.h

index f082a53e5177a3d8c04d0c8e69c75c68549bbf0c..09c93effcc3e67e73b2025cc97225ffd16c2a860 100644 (file)
@@ -287,6 +287,7 @@ local types = {
   xml = {
     ct = 'application/xml',
     type = 'text',
+    no_text = true,
   },
   txt = {
     type = 'text',
@@ -302,16 +303,19 @@ local types = {
     type = 'text',
     ct = 'text/csv',
     av_check = false,
+    no_text = true,
   },
   ics = {
     type = 'text',
     ct = 'text/calendar',
     av_check = false,
+    no_text = true,
   },
   vcf = {
     type = 'text',
     ct = 'text/vcard',
     av_check = false,
+    no_text = true,
   },
   eml = {
     type = 'message',
index d788844a3fec42f1eb3b114ea88ea1f3f6f90c51..e6fc5be94789614364c2faaee23573cc9243c0c2 100644 (file)
@@ -1446,6 +1446,19 @@ rspamd_message_process (struct rspamd_task *task)
                                                part->detected_type = rspamd_mempool_strdup (task->task_pool,
                                                                lua_tostring (L, -1));
                                        }
+
+                                       lua_pop (L, 1);
+
+                                       lua_pushstring (L, "no_text");
+                                       lua_gettable (L, -2);
+
+                                       if (lua_isboolean (L, -1)) {
+                                               if (!!lua_toboolean (L, -1)) {
+                                                       part->flags |= RSPAMD_MIME_PART_NO_TEXT_EXTRACTION;
+                                               }
+                                       }
+
+                                       lua_pop (L, 1);
                                }
                        }
 
@@ -1479,7 +1492,8 @@ rspamd_message_process (struct rspamd_task *task)
                rspamd_images_process_mime_part_maybe (task, part);
 
                /* Still no content detected, try text heuristic */
-               if (part->part_type == RSPAMD_MIME_PART_UNDEFINED) {
+               if (part->part_type == RSPAMD_MIME_PART_UNDEFINED &&
+                               !(part->flags & RSPAMD_MIME_PART_NO_TEXT_EXTRACTION)) {
                        rspamd_message_process_text_part_maybe (task, part);
                }
        }
index 4549c056de9122ebabb3be623366c533c6fb3fec..25bf70f77cd2a9af136578cc63debc878379e05a 100644 (file)
@@ -31,9 +31,10 @@ struct rspamd_image;
 struct rspamd_archive;
 
 enum rspamd_mime_part_flags {
-       RSPAMD_MIME_PART_ATTACHEMENT = (1 << 1),
-       RSPAMD_MIME_PART_BAD_CTE = (1 << 4),
-       RSPAMD_MIME_PART_MISSING_CTE = (1 << 5),
+       RSPAMD_MIME_PART_ATTACHEMENT = (1u << 1u),
+       RSPAMD_MIME_PART_BAD_CTE = (1u << 4u),
+       RSPAMD_MIME_PART_MISSING_CTE = (1u << 5u),
+       RSPAMD_MIME_PART_NO_TEXT_EXTRACTION = (1u << 6u),
 };
 
 enum rspamd_mime_part_type {