From: Vsevolod Stakhov Date: Tue, 18 Jun 2019 11:50:45 +0000 (+0100) Subject: [Minor] Add has_symbol function to rspamd expressions X-Git-Tag: 2.0~762 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7df2c1887ef78a03bab5f54efea054103b8c3755;p=rspamd.git [Minor] Add has_symbol function to rspamd expressions --- diff --git a/src/libmime/mime_expressions.c b/src/libmime/mime_expressions.c index 7a0c27f1b..d7622376c 100644 --- a/src/libmime/mime_expressions.c +++ b/src/libmime/mime_expressions.c @@ -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