From: Vsevolod Stakhov Date: Thu, 11 Jun 2009 15:51:24 +0000 (+0400) Subject: * Add function "raw_header_exists" for finding headers that are not parsed by gmime... X-Git-Tag: 0.2.7~124 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c9d11a65b5c801a27f154091aebe86cbd08fd319;p=rspamd.git * Add function "raw_header_exists" for finding headers that are not parsed by gmime (Mime-Version for example) --- diff --git a/CMakeLists.txt b/CMakeLists.txt index c41477181..88b649a4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ PROJECT(rspamd C) SET(RSPAMD_VERSION_MAJOR 0) SET(RSPAMD_VERSION_MINOR 1) -SET(RSPAMD_VERSION_PATCH 6) +SET(RSPAMD_VERSION_PATCH 7) SET(RSPAMD_VERSION "${RSPAMD_VERSION_MAJOR}.${RSPAMD_VERSION_MINOR}.${RSPAMD_VERSION_PATCH}") SET(RSPAMD_MASTER_SITE_URL "http://cebka.pp.ru/hg/rspamd") diff --git a/src/expressions.c b/src/expressions.c index 05bc12e88..eecf68986 100644 --- a/src/expressions.c +++ b/src/expressions.c @@ -845,7 +845,6 @@ rspamd_header_exists (struct worker_task *task, GList *args) { struct expression_argument *arg; GList *headerlist; - char *c; if (args == NULL || task == NULL) { return FALSE; @@ -862,13 +861,6 @@ rspamd_header_exists (struct worker_task *task, GList *args) g_list_free (headerlist); return TRUE; } - else { - /* Also check in raw headers */ - if ((c = strstr (task->raw_headers, (char *)arg->data)) != NULL && - (c == task->raw_headers || *(c - 1) == '\n')) { - return TRUE; - } - } return FALSE; } diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index fbe36f291..7095c3041 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -68,6 +68,7 @@ static struct regexp_ctx *regexp_module_ctx = NULL; static int regexp_common_filter (struct worker_task *task); static gboolean rspamd_regexp_match_number (struct worker_task *task, GList *args); +static gboolean rspamd_raw_header_exists (struct worker_task *task, GList *args); int regexp_module_init (struct config_file *cfg, struct module_ctx **ctx) @@ -84,6 +85,7 @@ regexp_module_init (struct config_file *cfg, struct module_ctx **ctx) *ctx = (struct module_ctx *)regexp_module_ctx; register_expression_function ("regexp_match_number", rspamd_regexp_match_number); + register_expression_function ("raw_header_exists", rspamd_raw_header_exists); return 0; } @@ -662,3 +664,24 @@ rspamd_regexp_match_number (struct worker_task *task, GList *args) return res >= param_count; } + +static gboolean +rspamd_raw_header_exists (struct worker_task *task, GList *args) +{ + struct expression_argument *arg; + + if (args == NULL || task == NULL) { + return FALSE; + } + + arg = get_function_arg (args->data, task, TRUE); + if (!arg || arg->type == EXPRESSION_ARGUMENT_BOOL) { + msg_warn ("rspamd_raw_header_exists: invalid argument to function is passed"); + return FALSE; + } + if (find_raw_header_pos (task->raw_headers, (char *)arg->data) == NULL) { + return FALSE; + } + + return TRUE; +}