]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add has_symbol function to rspamd expressions
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 18 Jun 2019 11:50:45 +0000 (12:50 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 18 Jun 2019 11:50:45 +0000 (12:50 +0100)
src/libmime/mime_expressions.c

index 7a0c27f1bc96541010a9cf1d97b01a3f34b270b6..d7622376c484fa763b234e6a6c5fe521b08ffd5a 100644 (file)
@@ -84,6 +84,9 @@ static gboolean rspamd_is_empty_body (struct rspamd_task *task,
 static gboolean rspamd_has_flag_expr (struct rspamd_task *task,
                                                                          GArray * args,
                                                                          void *unused);
+static gboolean rspamd_has_symbol_expr (struct rspamd_task *task,
+                                                                         GArray * args,
+                                                                         void *unused);
 
 static rspamd_expression_atom_t * rspamd_mime_expr_parse (const gchar *line, gsize len,
                rspamd_mempool_t *pool, gpointer ud, GError **err);
@@ -157,6 +160,7 @@ static struct _fl {
                {"has_flag", rspamd_has_flag_expr, NULL},
                {"has_html_tag", rspamd_has_html_tag, NULL},
                {"has_only_html_part", rspamd_has_only_html_part, NULL},
+               {"has_symbol", rspamd_has_symbol_expr, NULL},
                {"header_exists", rspamd_header_exists, NULL},
                {"is_empty_body", rspamd_is_empty_body, NULL},
                {"is_html_balanced", rspamd_is_html_balanced, NULL},
@@ -2278,4 +2282,33 @@ rspamd_has_flag_expr (struct rspamd_task *task,
        }
 
        return result;
+}
+
+static gboolean
+rspamd_has_symbol_expr (struct rspamd_task *task,
+                                         GArray * args,
+                                         void *unused)
+{
+       struct expression_argument *sym_arg;
+       const gchar *symbol_str;
+
+       if (args == NULL) {
+               msg_warn_task ("no parameters to function");
+               return FALSE;
+       }
+
+       sym_arg = &g_array_index (args, struct expression_argument, 0);
+
+       if (sym_arg->type != EXPRESSION_ARGUMENT_NORMAL) {
+               msg_warn_task ("invalid parameter to function");
+               return FALSE;
+       }
+
+       symbol_str = (const gchar *)sym_arg->data;
+
+       if (rspamd_task_find_symbol_result (task, symbol_str)) {
+               return TRUE;
+       }
+
+       return FALSE;
 }
\ No newline at end of file