diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-11-23 20:02:32 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-11-23 20:02:32 +0000 |
commit | 929a9746c963fba0b3c59f35a06f9100d0fac13a (patch) | |
tree | 4cf28274fd84578a8f3dda21972b289102990af5 /src | |
parent | feb910e287c215d5a1b6a03856ad2a1cbd36a394 (diff) | |
download | rspamd-929a9746c963fba0b3c59f35a06f9100d0fac13a.tar.gz rspamd-929a9746c963fba0b3c59f35a06f9100d0fac13a.zip |
[Feature] Allow to quarantine rejected messages using milter interface
Diffstat (limited to 'src')
-rw-r--r-- | src/libserver/milter.c | 14 | ||||
-rw-r--r-- | src/libserver/milter.h | 6 | ||||
-rw-r--r-- | src/libserver/milter_internal.h | 5 | ||||
-rw-r--r-- | src/rspamd_proxy.c | 12 |
4 files changed, 32 insertions, 5 deletions
diff --git a/src/libserver/milter.c b/src/libserver/milter.c index f2ced4f0f..7874a9dbc 100644 --- a/src/libserver/milter.c +++ b/src/libserver/milter.c @@ -50,6 +50,7 @@ struct rspamd_milter_context { gchar *spam_header; void *sessions_cache; gboolean discard_on_reject; + gboolean quarantine_on_reject; }; static struct rspamd_milter_context *milter_ctx = NULL; @@ -1072,6 +1073,7 @@ rspamd_milter_handle_socket (gint fd, const struct timeval *tv, priv->state = RSPAMD_MILTER_READ_MORE; priv->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "milter"); priv->discard_on_reject = milter_ctx->discard_on_reject; + priv->quarantine_on_reject = milter_ctx->quarantine_on_reject; if (pool) { /* Copy tag */ @@ -1567,8 +1569,13 @@ rspamd_milter_process_milter_block (struct rspamd_milter_session *session, priv->discard_on_reject = TRUE; msg_info_milter ("discard message instead of rejection"); } + else if (strcmp (ucl_object_tostring (elt), "quarantine") == 0) { + priv->quarantine_on_reject = TRUE; + msg_info_milter ("quarantine message instead of rejection"); + } else { priv->discard_on_reject = FALSE; + priv->quarantine_on_reject = FALSE; } } @@ -1713,6 +1720,10 @@ rspamd_milter_send_task_results (struct rspamd_milter_session *session, if (priv->discard_on_reject) { rspamd_milter_send_action (session, RSPAMD_MILTER_DISCARD); } + else if (priv->quarantine_on_reject) { + /* TODO: need to add quarantine message */ + rspamd_milter_send_action (session, RSPAMD_MILTER_QUARANTINE); + } else { rcode = rspamd_fstring_new_init (RSPAMD_MILTER_RCODE_REJECT, sizeof (RSPAMD_MILTER_RCODE_REJECT) - 1); @@ -1789,7 +1800,7 @@ cleanup: void rspamd_milter_init_library (const gchar *spam_header, void *sessions_cache, - gboolean discard_on_reject) + gboolean discard_on_reject, gboolean quarantine_on_reject) { if (milter_ctx) { g_free (milter_ctx->spam_header); @@ -1807,6 +1818,7 @@ rspamd_milter_init_library (const gchar *spam_header, void *sessions_cache, milter_ctx->sessions_cache = sessions_cache; milter_ctx->discard_on_reject = discard_on_reject; + milter_ctx->quarantine_on_reject = quarantine_on_reject; } rspamd_mempool_t * diff --git a/src/libserver/milter.h b/src/libserver/milter.h index 8769a8230..eae99eff2 100644 --- a/src/libserver/milter.h +++ b/src/libserver/milter.h @@ -36,7 +36,8 @@ enum rspamd_milter_reply { RSPAMD_MILTER_TEMPFAIL = 't', RSPAMD_MILTER_REPLYCODE = 'y', RSPAMD_MILTER_OPTNEG = 'O', - RSPAMD_MILTER_PROGRESS = 'p' + RSPAMD_MILTER_PROGRESS = 'p', + RSPAMD_MILTER_QUARANTINE = 'q', }; struct rspamd_email_address; @@ -151,7 +152,8 @@ void rspamd_milter_send_task_results (struct rspamd_milter_session *session, * @param spam_header spam header name (must NOT be NULL) */ void rspamd_milter_init_library (const gchar *spam_header, - void *sessions_cache, gboolean discard_on_reject); + void *sessions_cache, gboolean discard_on_reject, + gboolean quarantine_on_reject); /** * Returns pool for a session diff --git a/src/libserver/milter_internal.h b/src/libserver/milter_internal.h index 9087bdbfb..6473ed147 100644 --- a/src/libserver/milter_internal.h +++ b/src/libserver/milter_internal.h @@ -67,6 +67,7 @@ struct rspamd_milter_private { enum rspamd_milter_io_state state; int fd; gboolean discard_on_reject; + gboolean quarantine_on_reject; gboolean no_action; }; @@ -124,10 +125,12 @@ enum rspamd_milter_io_cmd { #define RSPAMD_MILTER_FLAG_ADDRCPT (1L<<2) /* filter may add recipients */ #define RSPAMD_MILTER_FLAG_DELRCPT (1L<<3) /* filter may delete recipients */ #define RSPAMD_MILTER_FLAG_CHGHDRS (1L<<4) /* filter may change/delete headers */ +#define RSPAMD_MILTER_FLAG_QUARANTINE (1L<<5) /* filter may request quarantine */ #define RSPAMD_MILTER_ACTIONS_MASK \ (RSPAMD_MILTER_FLAG_ADDHDRS | RSPAMD_MILTER_FLAG_ADDRCPT | \ - RSPAMD_MILTER_FLAG_DELRCPT | RSPAMD_MILTER_FLAG_CHGHDRS) + RSPAMD_MILTER_FLAG_DELRCPT | RSPAMD_MILTER_FLAG_CHGHDRS | \ + RSPAMD_MILTER_FLAG_QUARANTINE) enum rspamd_milter_connect_proto { RSPAMD_MILTER_CONN_UNKNOWN = 'U', diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c index 6223d32ef..5b2206be4 100644 --- a/src/rspamd_proxy.c +++ b/src/rspamd_proxy.c @@ -138,6 +138,8 @@ struct rspamd_proxy_ctx { gboolean milter; /* Discard messages instead of rejecting them */ gboolean discard_on_reject; + /* Quarantine messages instead of rejecting them */ + gboolean quarantine_on_reject; /* Milter spam header */ gchar *spam_header; /* Sessions cache */ @@ -812,6 +814,14 @@ init_rspamd_proxy (struct rspamd_config *cfg) "Tell MTA to discard rejected messages silently"); rspamd_rcl_register_worker_option (cfg, type, + "quarantine_on_reject", + rspamd_rcl_parse_struct_boolean, + ctx, + G_STRUCT_OFFSET (struct rspamd_proxy_ctx, quarantine_on_reject), + 0, + "Tell MTA to quarantine rejected messages"); + rspamd_rcl_register_worker_option (cfg, + type, "spam_header", rspamd_rcl_parse_struct_string, ctx, @@ -2115,7 +2125,7 @@ start_rspamd_proxy (struct rspamd_worker *worker) { } rspamd_milter_init_library (ctx->spam_header, ctx->sessions_cache, - ctx->discard_on_reject); + ctx->discard_on_reject, ctx->quarantine_on_reject); rspamd_lua_run_postloads (ctx->cfg->lua_state, ctx->cfg, ctx->ev_base, worker); |