diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-04-11 16:04:19 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-04-11 16:04:19 +0100 |
commit | c9d2110ba0dd0f7e5d2e9d7a2914ba193336130c (patch) | |
tree | 804014235cb61f8162025acf5db1bbb891d06a3d | |
parent | cdfdd7590f2d3e8b5a53b8b417d03e2f7cc2f0e3 (diff) | |
download | rspamd-c9d2110ba0dd0f7e5d2e9d7a2914ba193336130c.tar.gz rspamd-c9d2110ba0dd0f7e5d2e9d7a2914ba193336130c.zip |
[Feature] Implement SA compatible body regexps
-rw-r--r-- | src/libserver/re_cache.c | 46 | ||||
-rw-r--r-- | src/libserver/re_cache.h | 1 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c index beb420a73..2e3a2ff65 100644 --- a/src/libserver/re_cache.c +++ b/src/libserver/re_cache.c @@ -723,6 +723,7 @@ rspamd_re_cache_exec_re (struct rspamd_task *task, guint *lenvec; gboolean raw = FALSE; struct mime_text_part *part; + struct mime_part *mime_part; struct rspamd_url *url; struct rspamd_re_cache *cache = rt->cache; gpointer k, v; @@ -920,6 +921,45 @@ rspamd_re_cache_exec_re (struct rspamd_task *task, debug_task ("checking rawbody regexp: %s -> %d", rspamd_regexp_get_pattern (re), ret); break; + case RSPAMD_RE_SABODY: + /* + * For SA body we get all parts and extract headers + body from them + * + */ + if (task->parts->len > 0) { + scvec = g_malloc (sizeof (*scvec) * task->parts->len * 2); + lenvec = g_malloc (sizeof (*lenvec) * task->parts->len * 2); + + for (i = 0; i < task->parts->len; i++) { + mime_part = g_ptr_array_index (task->parts, i); + + if (mime_part->raw_headers_str) { + scvec[i * 2] = (guchar *)mime_part->raw_headers_str; + lenvec[i * 2] = strlen (mime_part->raw_headers_str); + } + else { + scvec[i * 2] = (guchar *)""; + lenvec[i * 2] = 0; + } + + if (mime_part->content) { + scvec[i * 2 + 1] = (guchar *)mime_part->content->data; + lenvec[i * 2 + 1] = mime_part->content->len; + } + else { + scvec[i * 2 + 1] = (guchar *)""; + lenvec[i * 2 + 1] = 0; + } + } + + ret = rspamd_re_cache_process_regexp_data (rt, re, + task->task_pool, scvec, lenvec, task->parts->len * 2, TRUE); + debug_task ("checking sa body regexp: %s -> %d", + rspamd_regexp_get_pattern (re), ret); + g_free (scvec); + g_free (lenvec); + } + break; case RSPAMD_RE_MAX: msg_err_task ("regexp of class invalid has been called: %s", rspamd_regexp_get_pattern (re)); @@ -1057,6 +1097,9 @@ rspamd_re_cache_type_to_string (enum rspamd_re_type type) case RSPAMD_RE_URL: ret = "url"; break; + case RSPAMD_RE_SABODY: + ret = "sa body"; + break; case RSPAMD_RE_MAX: ret = "invalid class"; break; @@ -1095,6 +1138,9 @@ rspamd_re_cache_type_from_string (const char *str) else if (strcmp (str, "mimeheader") == 0) { ret = RSPAMD_RE_MIMEHEADER; } + else if (strcmp (str, "sabody") == 0) { + ret = RSPAMD_RE_SABODY; + } } return ret; diff --git a/src/libserver/re_cache.h b/src/libserver/re_cache.h index 262899037..e211834e5 100644 --- a/src/libserver/re_cache.h +++ b/src/libserver/re_cache.h @@ -33,6 +33,7 @@ enum rspamd_re_type { RSPAMD_RE_RAWMIME, RSPAMD_RE_URL, RSPAMD_RE_BODY, + RSPAMD_RE_SABODY, RSPAMD_RE_MAX }; |