mres = rspamd_create_metric_result (task, DEFAULT_METRIC);
if (mres != NULL) {
- mres->score = mres->metric->actions[METRIC_ACTION_REJECT].score;
+ mres->score = rspamd_task_get_required_score (task, mres);
mres->action = METRIC_ACTION_REJECT;
}
is_spam = (action < METRIC_ACTION_GREYLIST);
obj = ucl_object_typed_new (UCL_OBJECT);
- ucl_object_insert_key (obj, ucl_object_frombool (is_spam),
- "is_spam", 0, false);
- ucl_object_insert_key (obj, ucl_object_frombool (RSPAMD_TASK_IS_SKIPPED (task)),
- "is_skipped", 0, false);
+ ucl_object_insert_key (obj,
+ ucl_object_frombool (is_spam),
+ "is_spam", 0, false);
+ ucl_object_insert_key (obj,
+ ucl_object_frombool (RSPAMD_TASK_IS_SKIPPED (task)),
+ "is_skipped", 0, false);
ucl_object_insert_key (obj, ucl_object_fromdouble (mres->score),
- "score", 0, false);
- ucl_object_insert_key (obj, ucl_object_fromdouble (mres->actions_limits[METRIC_ACTION_REJECT]),
- "required_score", 0, false);
+ "score", 0, false);
+ ucl_object_insert_key (obj,
+ ucl_object_fromdouble (rspamd_task_get_required_score (task, mres)),
+ "required_score", 0, false);
ucl_object_insert_key (obj,
- ucl_object_fromstring (rspamd_action_to_str (action)),
- "action", 0, false);
+ ucl_object_fromstring (rspamd_action_to_str (action)),
+ "action", 0, false);
if (action == METRIC_ACTION_REWRITE_SUBJECT) {
subject = make_rewritten_subject (m, task);
ucl_object_insert_key (obj, ucl_object_fromstring (subject),
- "subject", 0, false);
+ "subject", 0, false);
}
/* Now handle symbols */
g_hash_table_iter_init (&hiter, mres->symbols);
}
ls->score = mres->score;
- ls->required_score = mres->actions_limits[METRIC_ACTION_REJECT];
+ ls->required_score = rspamd_task_get_required_score (task,
+ mres);
ls->nresults = g_hash_table_size (mres->symbols);
g_hash_table_iter_init (&it, mres->symbols);
else {
row->score = metric_res->score;
row->action = rspamd_check_action_metric (task, metric_res);
- row->required_score = metric_res->actions_limits[METRIC_ACTION_REJECT];
+ row->required_score = rspamd_task_get_required_score (task, metric_res);
cbdata.pos = row->symbols;
cbdata.remain = sizeof (row->symbols);
g_hash_table_foreach (metric_res->symbols,
res = g_hash_table_lookup (task->results, metric->name);
if (res) {
-
- ms = res->actions_limits[METRIC_ACTION_REJECT];
+ ms = rspamd_task_get_required_score (task, res);
if (!isnan (ms) && cp->lim < ms) {
cp->rs = res;
break;
case RSPAMD_LOG_SCORES:
res.len = rspamd_snprintf (scorebuf, sizeof (scorebuf), "%.2f/%.2f",
- mres->score, mres->actions_limits[METRIC_ACTION_REJECT]);
+ mres->score, rspamd_task_get_required_score (task, mres));
res.begin = scorebuf;
break;
case RSPAMD_LOG_SYMBOLS:
rspamd_fstring_free (logbuf);
}
+
+gdouble
+rspamd_task_get_required_score (struct rspamd_task *task, struct metric_result *m)
+{
+ guint i;
+
+ if (m == NULL) {
+ m = g_hash_table_lookup (task->results, DEFAULT_METRIC);
+
+ if (m == NULL) {
+ return NAN;
+ }
+ }
+
+ for (i = METRIC_ACTION_REJECT; i < METRIC_ACTION_MAX; i ++) {
+ if (!isnan (m->actions_limits[i])) {
+ return m->actions_limits[i];
+ }
+ }
+
+ return NAN;
+}
const gchar *classifier,
GError **err);
+/**
+ * Returns required score for a message (usually reject score)
+ * @param task
+ * @param m
+ * @return
+ */
+struct metric_result;
+gdouble rspamd_task_get_required_score (struct rspamd_task *task,
+ struct metric_result *m);
+
/**
* Write log line about the specified task if needed
*/
mres->action = rspamd_check_action_metric (task, mres);
}
- if (mres->action == METRIC_ACTION_REJECT) {
+ if (mres->score > rspamd_task_get_required_score (task, mres)) {
task->flags |= RSPAMD_TASK_FLAG_LEARN_SPAM;
ret = TRUE;
{
struct rspamd_task *task = lua_check_task (L, 1);
const gchar *metric_name;
+ gdouble rs;
struct metric_result *metric_res;
metric_name = luaL_checkstring (L, 2);
g_hash_table_lookup (task->results, metric_name)) != NULL) {
lua_newtable (L);
lua_pushnumber (L, metric_res->score);
+ rs = rspamd_task_get_required_score (task, metric_res);
lua_rawseti (L, -2, 1);
- lua_pushnumber (L,
- metric_res->metric->actions[METRIC_ACTION_REJECT].score);
+ lua_pushnumber (L, rs);
lua_rawseti (L, -2, 2);
- lua_pushnumber (L,
- metric_res->metric->actions[METRIC_ACTION_REJECT].score);
+ lua_pushnumber (L, rs);
lua_rawseti (L, -2, 3);
}
else {