diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-01-26 14:22:37 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-01-26 14:22:37 +0000 |
commit | f7200dd41947e09e42d6528b16b659532c3c7b5a (patch) | |
tree | 3e4ddb152914b29c0129264fda03c5c7aaef85b7 /src/libserver/milter.c | |
parent | 2ac0fbea2763ff9913c7924495c39869ddad924b (diff) | |
download | rspamd-f7200dd41947e09e42d6528b16b659532c3c7b5a.tar.gz rspamd-f7200dd41947e09e42d6528b16b659532c3c7b5a.zip |
[Minor] Milter: Add support of quarantine and discard actions
Diffstat (limited to 'src/libserver/milter.c')
-rw-r--r-- | src/libserver/milter.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/libserver/milter.c b/src/libserver/milter.c index 16d6252e9..b871c2347 100644 --- a/src/libserver/milter.c +++ b/src/libserver/milter.c @@ -25,6 +25,7 @@ #include "libutil/http.h" #include "libutil/http_private.h" #include "libserver/protocol_internal.h" +#include "libserver/cfg_file_private.h" #include "libmime/filter.h" #include "libserver/worker_util.h" #include "utlist.h" @@ -1557,7 +1558,7 @@ rspamd_milter_remove_header_safe (struct rspamd_milter_session *session, */ static gboolean rspamd_milter_process_milter_block (struct rspamd_milter_session *session, - const ucl_object_t *obj, gint action) + const ucl_object_t *obj, struct rspamd_action *action) { const ucl_object_t *elt, *cur, *cur_elt; ucl_object_iter_t it; @@ -1731,7 +1732,7 @@ rspamd_milter_process_milter_block (struct rspamd_milter_session *session, } } - if (action == METRIC_ACTION_ADD_HEADER) { + if (action->action_type == METRIC_ACTION_ADD_HEADER) { elt = ucl_object_lookup (obj, "spam_header"); if (elt) { @@ -1783,7 +1784,7 @@ rspamd_milter_send_task_results (struct rspamd_milter_session *session, const ucl_object_t *elt; struct rspamd_milter_private *priv = session->priv; const gchar *str_action; - gint action = METRIC_ACTION_REJECT; + struct rspamd_action *action; rspamd_fstring_t *xcode = NULL, *rcode = NULL, *reply = NULL; GString *hname, *hvalue; gboolean processed = FALSE; @@ -1805,7 +1806,14 @@ rspamd_milter_send_task_results (struct rspamd_milter_session *session, } str_action = ucl_object_tostring (elt); - rspamd_action_from_str (str_action, &action); + action = rspamd_config_get_action (milter_ctx->cfg, str_action); + + if (action == NULL) { + msg_err_milter ("action %s has not been registered", str_action); + rspamd_milter_send_action (session, RSPAMD_MILTER_TEMPFAIL); + + goto cleanup; + } elt = ucl_object_lookup (results, "messages"); if (elt) { @@ -1860,7 +1868,7 @@ rspamd_milter_send_task_results (struct rspamd_milter_session *session, goto cleanup; } - switch (action) { + switch (action->action_type) { case METRIC_ACTION_REJECT: if (priv->discard_on_reject) { rspamd_milter_send_action (session, RSPAMD_MILTER_DISCARD); @@ -1939,6 +1947,17 @@ rspamd_milter_send_task_results (struct rspamd_milter_session *session, rspamd_milter_send_action (session, RSPAMD_MILTER_ACCEPT); break; + case METRIC_ACTION_MILTER_QUARANTINE: + /* TODO: be more flexible about SMTP messages */ + rspamd_milter_send_action (session, RSPAMD_MILTER_QUARANTINE, + RSPAMD_MILTER_QUARANTINE_MESSAGE); + + /* Quarantine also requires accept action, all hail Sendmail */ + rspamd_milter_send_action (session, RSPAMD_MILTER_ACCEPT); + break; + case METRIC_ACTION_MILTER_DISCARD: + rspamd_milter_send_action (session, RSPAMD_MILTER_DISCARD); + break; case METRIC_ACTION_GREYLIST: case METRIC_ACTION_NOACTION: default: |