@@ -849,12 +849,6 @@ rspamd_message_process_text_part_maybe (struct rspamd_task *task, | |||
rspamd_add_passthrough_result (task, action, | |||
RSPAMD_PASSTHROUGH_CRITICAL, | |||
score, "Gtube pattern", "GTUBE", 0); | |||
if (ucl_object_lookup (task->messages, "smtp_message") == NULL) { | |||
ucl_object_replace_key (task->messages, | |||
ucl_object_fromstring ("Gtube pattern"), | |||
"smtp_message", 0, false); | |||
} | |||
} | |||
rspamd_task_insert_result (task, GTUBE_SYMBOL, 0, NULL); |
@@ -669,12 +669,13 @@ rspamd_task_add_result_option (struct rspamd_task *task, | |||
} | |||
struct rspamd_action* | |||
rspamd_check_action_metric (struct rspamd_task *task) | |||
rspamd_check_action_metric (struct rspamd_task *task, | |||
struct rspamd_passthrough_result **ppr) | |||
{ | |||
struct rspamd_action_result *action_lim, | |||
*noaction = NULL; | |||
struct rspamd_action *selected_action = NULL, *least_action = NULL; | |||
struct rspamd_passthrough_result *pr; | |||
struct rspamd_passthrough_result *pr, *sel_pr = NULL; | |||
double max_score = -(G_MAXDOUBLE), sc; | |||
int i; | |||
struct rspamd_scan_result *mres = task->result; | |||
@@ -696,6 +697,10 @@ rspamd_check_action_metric (struct rspamd_task *task) | |||
} | |||
} | |||
if (ppr) { | |||
*ppr = pr; | |||
} | |||
return selected_action; | |||
} | |||
else { | |||
@@ -721,10 +726,12 @@ rspamd_check_action_metric (struct rspamd_task *task) | |||
else { | |||
sc = selected_action->threshold; | |||
max_score = sc; | |||
sel_pr = pr; | |||
} | |||
} | |||
else { | |||
max_score = sc; | |||
sel_pr = pr; | |||
} | |||
} | |||
} | |||
@@ -767,17 +774,31 @@ rspamd_check_action_metric (struct rspamd_task *task) | |||
selected_action->action_type != METRIC_ACTION_DISCARD) { | |||
/* Override score based action with least action */ | |||
selected_action = least_action; | |||
if (ppr) { | |||
*ppr = sel_pr; | |||
} | |||
} | |||
} | |||
else { | |||
/* Adjust score if needed */ | |||
mres->score = MAX (max_score, mres->score); | |||
if (max_score > mres->score) { | |||
if (ppr) { | |||
*ppr = sel_pr; | |||
} | |||
mres->score = max_score; | |||
} | |||
} | |||
} | |||
return selected_action; | |||
} | |||
if (ppr) { | |||
*ppr = sel_pr; | |||
} | |||
return noaction->action; | |||
} | |||
@@ -52,6 +52,7 @@ struct rspamd_symbol_result { | |||
#define RSPAMD_PASSTHROUGH_CRITICAL 3 | |||
#define RSPAMD_PASSTHROUGH_LEAST (1u << 0u) | |||
#define RSPAMD_PASSTHROUGH_NO_SMTP_MESSAGE (1u << 0u) | |||
struct rspamd_passthrough_result { | |||
struct rspamd_action *action; | |||
@@ -183,7 +184,8 @@ double rspamd_factor_consolidation_func (struct rspamd_task *task, | |||
* @param task | |||
* @return | |||
*/ | |||
struct rspamd_action *rspamd_check_action_metric (struct rspamd_task *task); | |||
struct rspamd_action *rspamd_check_action_metric (struct rspamd_task *task, | |||
struct rspamd_passthrough_result **ppr); | |||
#ifdef __cplusplus | |||
} |
@@ -1167,8 +1167,9 @@ rspamd_scan_result_ucl (struct rspamd_task *task, | |||
struct rspamd_action *action; | |||
ucl_object_t *obj = NULL, *sobj; | |||
const gchar *subject; | |||
struct rspamd_passthrough_result *pr = NULL; | |||
action = rspamd_check_action_metric (task); | |||
action = rspamd_check_action_metric (task, &pr); | |||
is_spam = !(action->flags & RSPAMD_ACTION_HAM); | |||
if (task->cmd == CMD_CHECK) { | |||
@@ -1181,6 +1182,16 @@ rspamd_scan_result_ucl (struct rspamd_task *task, | |||
obj = top; | |||
} | |||
if (pr && pr->message && !(pr->flags & RSPAMD_PASSTHROUGH_NO_SMTP_MESSAGE)) { | |||
/* Add smtp message if it does not exists: see #3269 for details */ | |||
if (ucl_object_lookup (task->messages, "smtp_message") == NULL) { | |||
ucl_object_insert_key (task->messages, | |||
ucl_object_fromstring_common (pr->message, 0, UCL_STRING_RAW), | |||
"smtp_message", 0, | |||
false); | |||
} | |||
} | |||
ucl_object_insert_key (obj, | |||
ucl_object_frombool (RSPAMD_TASK_IS_SKIPPED (task)), | |||
"is_skipped", 0, false); | |||
@@ -1734,13 +1745,13 @@ rspamd_protocol_http_reply (struct rspamd_http_message *msg, | |||
end: | |||
if (!(task->flags & RSPAMD_TASK_FLAG_NO_STAT)) { | |||
/* Update stat for default metric */ | |||
msg_debug_protocol ("skip stats update due to no_stat flag"); | |||
metric_res = task->result; | |||
if (metric_res != NULL) { | |||
action = rspamd_check_action_metric (task); | |||
action = rspamd_check_action_metric (task, NULL); | |||
/* TODO: handle custom actions in stats */ | |||
if (action->action_type == METRIC_ACTION_SOFT_REJECT && | |||
(task->flags & RSPAMD_TASK_FLAG_GREYLISTED)) { |
@@ -160,7 +160,7 @@ rspamd_roll_history_update (struct roll_history *history, | |||
} | |||
else { | |||
row->score = metric_res->score; | |||
action = rspamd_check_action_metric (task); | |||
action = rspamd_check_action_metric (task, NULL); | |||
row->action = action->action_type; | |||
row->required_score = rspamd_task_get_required_score (task, metric_res); | |||
cbdata.pos = row->symbols; |
@@ -1076,7 +1076,7 @@ rspamd_task_log_metric_res (struct rspamd_task *task, | |||
khiter_t k; | |||
mres = task->result; | |||
act = rspamd_check_action_metric (task); | |||
act = rspamd_check_action_metric (task, NULL); | |||
if (mres != NULL) { | |||
switch (lf->type) { | |||
@@ -1875,7 +1875,7 @@ rspamd_task_timeout (EV_P_ ev_timer *w, int revents) | |||
if (task->cfg->soft_reject_on_timeout) { | |||
struct rspamd_action *action, *soft_reject; | |||
action = rspamd_check_action_metric (task); | |||
action = rspamd_check_action_metric (task, NULL); | |||
if (action->action_type != METRIC_ACTION_REJECT) { | |||
soft_reject = rspamd_config_get_action_by_type (task->cfg, | |||
@@ -1887,12 +1887,6 @@ rspamd_task_timeout (EV_P_ ev_timer *w, int revents) | |||
"timeout processing message", | |||
"task timeout", | |||
0); | |||
ucl_object_replace_key (task->messages, | |||
ucl_object_fromstring_common ("timeout processing message", | |||
0, UCL_STRING_RAW), | |||
"smtp_message", 0, | |||
false); | |||
} | |||
} | |||
@@ -1910,7 +1904,7 @@ rspamd_task_timeout (EV_P_ ev_timer *w, int revents) | |||
if (task->cfg->soft_reject_on_timeout) { | |||
struct rspamd_action *action, *soft_reject; | |||
action = rspamd_check_action_metric (task); | |||
action = rspamd_check_action_metric (task, NULL); | |||
if (action->action_type != METRIC_ACTION_REJECT) { | |||
soft_reject = rspamd_config_get_action_by_type (task->cfg, | |||
@@ -1922,12 +1916,6 @@ rspamd_task_timeout (EV_P_ ev_timer *w, int revents) | |||
"timeout post-processing message", | |||
"task timeout", | |||
0); | |||
ucl_object_replace_key (task->messages, | |||
ucl_object_fromstring_common ("timeout post-processing message", | |||
0, UCL_STRING_RAW), | |||
"smtp_message", 0, | |||
false); | |||
} | |||
} | |||
@@ -2116,6 +2116,9 @@ lua_task_set_pre_result (lua_State * L) | |||
if (strstr (fl_str, "least") != NULL) { | |||
flags |= RSPAMD_PASSTHROUGH_LEAST; | |||
} | |||
else if (strstr (fl_str, "no_smtp_message") != NULL) { | |||
flags |= RSPAMD_PASSTHROUGH_NO_SMTP_MESSAGE; | |||
} | |||
} | |||
@@ -5853,7 +5856,7 @@ lua_task_get_metric_result (lua_State *L) | |||
lua_pushnumber (L, metric_res->score); | |||
lua_settable (L, -3); | |||
action = rspamd_check_action_metric (task); | |||
action = rspamd_check_action_metric (task, NULL); | |||
if (action) { | |||
lua_pushstring (L, "action"); | |||
@@ -5924,7 +5927,7 @@ lua_task_get_metric_action (lua_State *L) | |||
struct rspamd_action *action; | |||
if (task) { | |||
action = rspamd_check_action_metric (task); | |||
action = rspamd_check_action_metric (task, NULL); | |||
lua_pushstring (L, action->name); | |||
} | |||
else { |