From: Vsevolod Stakhov Date: Tue, 24 Mar 2015 13:42:32 +0000 (+0000) Subject: Improve test regexp. X-Git-Tag: 0.9.0~440 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=dada9cf1cc23ef27c3bbff9ded12c8c23d8dbc61;p=rspamd.git Improve test regexp. --- diff --git a/src/libmime/mime_expressions.c b/src/libmime/mime_expressions.c index 1a3179e90..01e3ddeb2 100644 --- a/src/libmime/mime_expressions.c +++ b/src/libmime/mime_expressions.c @@ -645,6 +645,35 @@ err: return NULL; } +static const gchar * +rspamd_mime_regexp_type_to_string (struct rspamd_regexp_atom *re) +{ + const gchar *ret = "unknown"; + + switch (re->type) { + case REGEXP_NONE: + ret = "none"; + break; + case REGEXP_HEADER: + ret = "header"; + break; + case REGEXP_RAW_HEADER: + ret = "raw header"; + break; + case REGEXP_MIME: + ret = "part"; + break; + case REGEXP_MESSAGE: + ret = "message"; + break; + case REGEXP_URL: + ret = "url"; + break; + } + + return ret; +} + static gint rspamd_mime_regexp_element_process (struct rspamd_task *task, struct rspamd_regexp_atom *re, const gchar *data, gsize len, @@ -655,8 +684,8 @@ rspamd_mime_regexp_element_process (struct rspamd_task *task, if ((r = rspamd_task_re_cache_check (task, re->regexp_text)) != RSPAMD_TASK_CACHE_NO_VALUE) { - debug_task ("regexp /%s/ is found in cache, result: %d", - re->regexp_text, r); + debug_task ("%s regexp %s is found in cache, result: %d", + rspamd_mime_regexp_type_to_string (re), re->regexp_text, r); return r; } @@ -679,13 +708,6 @@ rspamd_mime_regexp_element_process (struct rspamd_task *task, } while (rspamd_regexp_search (re->regexp, data, len, &start, &end, raw)) { - if (G_UNLIKELY (re->is_test)) { - msg_info ( - "process test regexp %s for header %s with value '%s' returned TRUE", - re->regexp_text, - re->header, - data); - } r++; if (!re->is_multiple) { @@ -693,6 +715,14 @@ rspamd_mime_regexp_element_process (struct rspamd_task *task, } } + if (G_UNLIKELY (re->is_test)) { + msg_info ( + "process %s test regexp %s returned %d", + rspamd_mime_regexp_type_to_string (re), + re->regexp_text, + r); + } + if (r > 0) { rspamd_task_re_cache_add (task, re->regexp_text, r); }