diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2008-12-17 19:23:32 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2008-12-17 19:23:32 +0300 |
commit | 9e9ced325226942bbfb6c4aa307f388044e29b23 (patch) | |
tree | 3d0fe8941bff4fbc2724e792624e182aa5acd5b3 /src/filter.c | |
parent | 87f0454e574154e8deea0493394e914c283b821a (diff) | |
download | rspamd-9e9ced325226942bbfb6c4aa307f388044e29b23.tar.gz rspamd-9e9ced325226942bbfb6c4aa307f388044e29b23.zip |
* Add function for adding rspamd report headers
Diffstat (limited to 'src/filter.c')
-rw-r--r-- | src/filter.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/filter.c b/src/filter.c index 5bf0db27a..64d492e62 100644 --- a/src/filter.c +++ b/src/filter.c @@ -441,6 +441,47 @@ process_statfiles (struct worker_task *task) g_hash_table_destroy (cd.metrics); } +static void +insert_metric_header (gpointer metric_name, gpointer metric_value, gpointer data) +{ + struct worker_task *task = (struct worker_task *)data; + int r = 0; + /* Try to be rfc2822 compatible and avoid long headers with folding */ + char header_name[128], outbuf[1000]; + GList *symbols = NULL, *cur; + struct metric_result *metric_res = (struct metric_result *)metric_value; + + snprintf (header_name, sizeof (header_name), "X-Spam-%s", metric_res->metric->name); + + if (metric_res->score >= metric_res->metric->required_score) { + r += snprintf (outbuf + r, sizeof (outbuf) - r, "yes; %.2f/%.2f; ", metric_res->score, metric_res->metric->required_score); + } + else { + r += snprintf (outbuf + r, sizeof (outbuf) - r, "no; %.2f/%.2f; ", metric_res->score, metric_res->metric->required_score); + } + + symbols = g_hash_table_get_keys (metric_res->symbols); + cur = symbols; + while (cur) { + if (g_list_next (cur) != NULL) { + r += snprintf (outbuf + r, sizeof (outbuf) - r, "%s,", (char *)cur->data); + } + else { + r += snprintf (outbuf + r, sizeof (outbuf) - r, "%s", (char *)cur->data); + } + cur = g_list_next (cur); + } + g_list_free (symbols); + g_mime_message_add_header (task->message, header_name, outbuf); + +} + +void +insert_headers (struct worker_task *task) +{ + g_hash_table_foreach (task->results, insert_metric_header, task); +} + /* * vi:ts=4 */ |