]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix parsing of cte in expressions
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Mar 2017 11:38:05 +0000 (11:38 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Mar 2017 11:49:17 +0000 (11:49 +0000)
rules/regexp/headers.lua
src/libmime/message.h
src/libmime/mime_expressions.c
src/libmime/mime_parser.c

index 30ccd5d0f2ffb1a03ce502297c7f3cacd6389d39..f58feeaf848f1b7e358d4a49310043e99bfcccfa 100644 (file)
@@ -107,7 +107,8 @@ reconf['R_RCVD_SPAMBOTS'] = {
 
 -- Charset is missing in message
 reconf['R_MISSING_CHARSET'] = {
-  re = string.format('content_type_is_type(text) & !content_type_has_param(charset) & !%s', r_cte_7bit),
+  re = string.format('content_type_is_type(text) & !content_type_has_param(charset) & !%s',
+    r_cte_7bit),
   score = 2.5,
   description = 'Charset is missing in a message',
   group = 'header'
index 6004d1759ae2d78046ee49d862c57e745addf505..03e0e8345d038c402fbf11ebec823209549c9d12 100644 (file)
@@ -163,4 +163,19 @@ GPtrArray *rspamd_message_get_header_from_hash (GHashTable *htb,
                const gchar *field,
                gboolean strong);
 
+
+/**
+ * Converts string to cte
+ * @param str
+ * @return
+ */
+enum rspamd_cte rspamd_cte_from_string (const gchar *str);
+
+/**
+ * Converts cte to string
+ * @param ct
+ * @return
+ */
+const gchar* rspamd_cte_to_string (enum rspamd_cte ct);
+
 #endif
index 8a567245925270997e76b7ecf2d91dc1ec8d2a70..71b8d4bdc399a318181a11da3111e71bc16d21ab 100644 (file)
@@ -1252,11 +1252,10 @@ rspamd_compare_transfer_encoding (struct rspamd_task * task,
        GArray * args,
        void *unused)
 {
-       GPtrArray *headerlist;
        struct expression_argument *arg;
        guint i;
-       struct rspamd_mime_header *rh;
-       static const char *hname = "Content-Transfer-Encoding";
+       struct rspamd_mime_part *part;
+       enum rspamd_cte cte;
 
        if (args == NULL) {
                msg_warn_task ("no parameters to function");
@@ -1269,39 +1268,16 @@ rspamd_compare_transfer_encoding (struct rspamd_task * task,
                return FALSE;
        }
 
-       headerlist = rspamd_message_get_header_array (task, hname, FALSE);
+       cte = rspamd_cte_from_string (arg->data);
 
-       if (headerlist) {
-               for (i = 0; i < headerlist->len; i ++) {
-                       rh = g_ptr_array_index (headerlist, i);
-
-                       if (rh->decoded == NULL) {
-                               continue;
-                       }
-
-                       if (g_ascii_strcasecmp (rh->decoded, arg->data) == 0) {
-                               return TRUE;
-                       }
-               }
+       if (cte == RSPAMD_CTE_UNKNOWN) {
+               msg_warn_task ("unknown cte: %s", arg->data);
+               return FALSE;
        }
 
-       /*
-        * In fact, we need to check 'Content-Transfer-Encoding' for each part
-        * as gmime has 'strange' assumptions
-        */
-       headerlist = rspamd_message_get_mime_header_array (task,
-                       arg->data,
-                       FALSE);
-
-       if (headerlist) {
-               for (i = 0; i < headerlist->len; i ++) {
-                       rh = g_ptr_array_index (headerlist, i);
-
-                       if (rh->decoded == NULL) {
-                               continue;
-                       }
-
-                       if (g_ascii_strcasecmp (rh->decoded, arg->data) == 0) {
+       PTR_ARRAY_FOREACH (task->parts, i, part) {
+               if (IS_CT_TEXT (part->ct)) {
+                       if (part->cte == cte) {
                                return TRUE;
                        }
                }
index b169832874beda65518f04e27669853f4161e329..a9bb0748ae225138ac71b4f5db11965af32fe610 100644 (file)
@@ -81,7 +81,7 @@ rspamd_mime_parser_quark (void)
        return g_quark_from_static_string ("mime-parser");
 }
 
-static const gchar*
+const gchar*
 rspamd_cte_to_string (enum rspamd_cte ct)
 {
        const gchar *ret = "unknown";
@@ -106,6 +106,29 @@ rspamd_cte_to_string (enum rspamd_cte ct)
        return ret;
 }
 
+enum rspamd_cte
+rspamd_cte_from_string (const gchar *str)
+{
+       enum rspamd_cte ret = RSPAMD_CTE_UNKNOWN;
+
+       g_assert (str != NULL);
+
+       if (strcmp (str, "7bit") == 0) {
+               ret = RSPAMD_CTE_7BIT;
+       }
+       else if (strcmp (str, "8bit") == 0) {
+               ret = RSPAMD_CTE_8BIT;
+       }
+       else if (strcmp (str, "quoted-printable") == 0) {
+               ret = RSPAMD_CTE_QP;
+       }
+       else if (strcmp (str, "base64") == 0) {
+               ret = RSPAMD_CTE_B64;
+       }
+
+       return ret;
+}
+
 static void
 rspamd_mime_parser_init_lib (void)
 {