diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-10-02 20:23:16 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-10-02 20:23:16 +0400 |
commit | ce482fbf8e2c1b9bf0cdba0ab61bc26985ee8977 (patch) | |
tree | aa9db8b8c40ce43d504750f03f781652c16ea727 /src/settings.c | |
parent | f3ad9c6f1e91c9912dbe730fdec350b5fc908672 (diff) | |
download | rspamd-ce482fbf8e2c1b9bf0cdba0ab61bc26985ee8977.tar.gz rspamd-ce482fbf8e2c1b9bf0cdba0ab61bc26985ee8977.zip |
* Add reject score setting for hard rejecting of mail (by Anton Nekhoroshin)
* Add rspamc protocol 1.1 (3 marks instead of 2)
Diffstat (limited to 'src/settings.c')
-rw-r--r-- | src/settings.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/settings.c b/src/settings.c index a4dca10dd..bcb40505c 100644 --- a/src/settings.c +++ b/src/settings.c @@ -50,6 +50,9 @@ settings_free (gpointer data) if (s->metric_scores) { g_hash_table_destroy (s->metric_scores); } + if (s->reject_scores) { + g_hash_table_destroy (s->reject_scores); + } g_free (s); } @@ -149,6 +152,7 @@ json_fin_cb (memory_pool_t * pool, struct map_cb_data *data) for (i = 0; i < nelts; i++) { cur_settings = g_malloc (sizeof (struct rspamd_settings)); cur_settings->metric_scores = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + cur_settings->reject_scores = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); cur_settings->factors = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); cur_settings->statfile_alias = NULL; cur_settings->want_spam = FALSE; @@ -198,6 +202,21 @@ json_fin_cb (memory_pool_t * pool, struct map_cb_data *data) json_it = json_object_iter_next (cur_nm, json_it); } } + /* Rejects object */ + cur_nm = json_object_get (cur_elt, "rejects"); + if (cur_nm != NULL && json_is_object (cur_nm)) { + json_it = json_object_iter (cur_nm); + while (json_it) { + it_val = json_object_iter_value (json_it); + if (it_val && json_is_number (it_val)) { + score = g_malloc (sizeof (double)); + *score = json_number_value (it_val); + g_hash_table_insert (cur_settings->reject_scores, g_strdup (json_object_iter_key (json_it)), + score); + } + json_it = json_object_iter_next(cur_nm, json_it); + } + } /* Want spam */ cur_nm = json_object_get (cur_elt, "want_spam"); if (cur_nm != NULL) { @@ -284,25 +303,36 @@ check_setting (struct worker_task *task, struct rspamd_settings **user_settings, } gboolean -check_metric_settings (struct worker_task * task, struct metric * metric, double *score) +check_metric_settings (struct worker_task * task, struct metric * metric, double *score, double *rscore) { struct rspamd_settings *us, *ds; - double *sc; + double *sc, *rs; + + *rscore = DEFAULT_REJECT_SCORE; if (check_setting (task, &us, &ds)) { if (us != NULL) { /* First search in user's settings */ + if ((rs = g_hash_table_lookup (us->reject_scores, metric->name)) != NULL) { + *rscore = *rs; + } if ((sc = g_hash_table_lookup (us->metric_scores, metric->name)) != NULL) { *score = *sc; return TRUE; } /* Now check in domain settings */ + if (ds && ((rs = g_hash_table_lookup (ds->reject_scores, metric->name)) != NULL)) { + *rscore = *rs; + } if (ds && (sc = g_hash_table_lookup (ds->metric_scores, metric->name)) != NULL) { *score = *sc; return TRUE; } } else if (ds != NULL) { + if ((rs = g_hash_table_lookup (ds->reject_scores, metric->name)) != NULL) { + *rscore = *rs; + } if ((sc = g_hash_table_lookup (ds->metric_scores, metric->name)) != NULL) { *score = *sc; return TRUE; |