guint priority,
double target_score,
const gchar *message,
- const gchar *module)
+ const gchar *module,
+ guint flags)
{
struct rspamd_metric_result *metric_res;
struct rspamd_passthrough_result *pr;
pr->message = message;
pr->module = module;
pr->target_score = target_score;
+ pr->flags = flags;
DL_APPEND (metric_res->passthrough_result, pr);
DL_SORT (metric_res->passthrough_result, rspamd_pr_sort);
if (!isnan (target_score)) {
- msg_info_task ("<%s>: set pre-result to %s (%.2f): '%s' from %s(%d)",
- task->message_id, action->name, target_score,
+
+ msg_info_task ("<%s>: set pre-result to '%s' %s(%.2f): '%s' from %s(%d)",
+ task->message_id, action->name,
+ flags & RSPAMD_PASSTHROUGH_LEAST ? "*least " : "",
+ target_score,
message, module, priority);
}
-
else {
- msg_info_task ("<%s>: set pre-result to %s (no score): '%s' from %s(%d)",
+ msg_info_task ("<%s>: set pre-result to '%s' %s(no score): '%s' from %s(%d)",
task->message_id, action->name,
+ flags & RSPAMD_PASSTHROUGH_LEAST ? "*least " : "",
message, module, priority);
}
}
double max_score = -(G_MAXDOUBLE), sc;
int i;
struct rspamd_metric_result *mres = task->result;
+ gboolean seen_least = FALSE;
- /* We are not certain about the results during processing */
- if (mres->passthrough_result == NULL) {
- for (i = mres->nactions - 1; i >= 0; i--) {
- action_lim = &mres->actions_limits[i];
- sc = action_lim->cur_limit;
+ if (mres->passthrough_result != NULL) {
+ /* Peek the highest priority result */
+ pr = mres->passthrough_result;
+ sc = pr->target_score;
+ selected_action = pr->action;
- if (action_lim->action->action_type == METRIC_ACTION_NOACTION) {
- noaction = action_lim;
+ if (!(pr->flags & RSPAMD_PASSTHROUGH_LEAST)) {
+ if (!isnan (sc)) {
+ if (pr->action->action_type == METRIC_ACTION_NOACTION) {
+ mres->score = MIN (sc, mres->score);
+ }
+ else {
+ mres->score = sc;
+ }
}
- if (isnan (sc) ||
- (action_lim->action->flags & (RSPAMD_ACTION_NO_THRESHOLD|RSPAMD_ACTION_HAM))) {
- continue;
- }
+ return selected_action;
+ }
+ else {
+ seen_least = true;
+ }
+ }
+ /* We are not certain about the results during processing */
- if (mres->score >= sc && sc > max_score) {
- selected_action = action_lim->action;
- max_score = sc;
- }
+ /*
+ * Select result by score
+ */
+ for (i = mres->nactions - 1; i >= 0; i--) {
+ action_lim = &mres->actions_limits[i];
+ sc = action_lim->cur_limit;
+
+ if (action_lim->action->action_type == METRIC_ACTION_NOACTION) {
+ noaction = action_lim;
}
- if (selected_action == NULL) {
- selected_action = noaction->action;
+ if (isnan (sc) ||
+ (action_lim->action->flags & (RSPAMD_ACTION_NO_THRESHOLD|RSPAMD_ACTION_HAM))) {
+ continue;
}
- }
- else {
- /* Peek the highest priority result */
- pr = mres->passthrough_result;
- sc = pr->target_score;
- selected_action = pr->action;
- if (!isnan (sc)) {
- if (pr->action->action_type == METRIC_ACTION_NOACTION) {
- mres->score = MIN (sc, mres->score);
- }
- else {
- mres->score = sc;
- }
+ if (mres->score >= sc && sc > max_score) {
+ selected_action = action_lim->action;
+ max_score = sc;
}
}
+ if (selected_action == NULL) {
+ selected_action = noaction->action;
+ }
+
if (selected_action) {
+
+ if (seen_least) {
+ mres->score = MIN (sc, mres->score);
+ }
+
return selected_action;
}
- return noaction ? noaction->action : NULL;
+ return noaction->action;
}
struct rspamd_symbol_result*
const gchar *message = NULL, *module = NULL;
gdouble score = NAN;
struct rspamd_action *action;
- guint priority = RSPAMD_PASSTHROUGH_NORMAL;
+ guint priority = RSPAMD_PASSTHROUGH_NORMAL, flags = 0;
if (task != NULL) {
priority = lua_tonumber (L, 6);
}
+ if (lua_type (L, 7) == LUA_TSTRING) {
+ const gchar *fl_str = lua_tostring (L, 7);
+
+ if (strstr (fl_str, "least") != NULL) {
+ flags |= RSPAMD_PASSTHROUGH_LEAST;
+ }
+ }
- rspamd_add_passthrough_result (task, action, priority,
- score, rspamd_mempool_strdup (task->task_pool, message),
- rspamd_mempool_strdup (task->task_pool, module));
+
+ rspamd_add_passthrough_result (task,
+ action,
+ priority,
+ score,
+ rspamd_mempool_strdup (task->task_pool, message),
+ rspamd_mempool_strdup (task->task_pool, module),
+ flags);
/* Don't classify or filter message if pre-filter sets results */
- task->processed_stages |= (RSPAMD_TASK_STAGE_CLASSIFIERS |
- RSPAMD_TASK_STAGE_CLASSIFIERS_PRE |
- RSPAMD_TASK_STAGE_CLASSIFIERS_POST);
- rspamd_symcache_disable_all_symbols (task, task->cfg->cache,
- SYMBOL_TYPE_IDEMPOTENT|SYMBOL_TYPE_IGNORE_PASSTHROUGH|
- SYMBOL_TYPE_POSTFILTER);
+
+ if (!(flags & RSPAMD_PASSTHROUGH_LEAST)) {
+ task->processed_stages |= (RSPAMD_TASK_STAGE_CLASSIFIERS |
+ RSPAMD_TASK_STAGE_CLASSIFIERS_PRE |
+ RSPAMD_TASK_STAGE_CLASSIFIERS_POST);
+ rspamd_symcache_disable_all_symbols (task, task->cfg->cache,
+ SYMBOL_TYPE_IDEMPOTENT | SYMBOL_TYPE_IGNORE_PASSTHROUGH |
+ SYMBOL_TYPE_POSTFILTER);
+ }
}
else {
return luaL_error (L, "invalid arguments");