From: Vsevolod Stakhov Date: Wed, 5 Jul 2017 07:31:17 +0000 (+0100) Subject: [Feature] Allow to discard messages instead of rejection X-Git-Tag: 1.6.2~24 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2a243ba4f114f07b17f3181e5de74f0349a363fe;p=rspamd.git [Feature] Allow to discard messages instead of rejection Issue: #1723 --- diff --git a/src/libserver/milter.c b/src/libserver/milter.c index dad7c5afa..4f235c2aa 100644 --- a/src/libserver/milter.c +++ b/src/libserver/milter.c @@ -49,6 +49,7 @@ struct rspamd_milter_context { gchar *spam_header; void *sessions_cache; + gboolean discard_on_reject; }; static struct rspamd_milter_context *milter_ctx = NULL; @@ -1565,18 +1566,23 @@ rspamd_milter_send_task_results (struct rspamd_milter_session *session, switch (action) { case METRIC_ACTION_REJECT: - rcode = rspamd_fstring_new_init (RSPAMD_MILTER_RCODE_REJECT, - sizeof (RSPAMD_MILTER_RCODE_REJECT) - 1); - xcode = rspamd_fstring_new_init (RSPAMD_MILTER_XCODE_REJECT, - sizeof (RSPAMD_MILTER_XCODE_REJECT) - 1); - - if (!reply) { - reply = rspamd_fstring_new_init (RSPAMD_MILTER_REJECT_MESSAGE, - sizeof (RSPAMD_MILTER_REJECT_MESSAGE) - 1); + if (milter_ctx->discard_on_reject) { + rspamd_milter_send_action (session, RSPAMD_MILTER_DISCARD); } + else { + rcode = rspamd_fstring_new_init (RSPAMD_MILTER_RCODE_REJECT, + sizeof (RSPAMD_MILTER_RCODE_REJECT) - 1); + xcode = rspamd_fstring_new_init (RSPAMD_MILTER_XCODE_REJECT, + sizeof (RSPAMD_MILTER_XCODE_REJECT) - 1); + + if (!reply) { + reply = rspamd_fstring_new_init (RSPAMD_MILTER_REJECT_MESSAGE, + sizeof (RSPAMD_MILTER_REJECT_MESSAGE) - 1); + } - rspamd_milter_set_reply (session, rcode, xcode, reply); - rspamd_milter_send_action (session, RSPAMD_MILTER_REJECT); + rspamd_milter_set_reply (session, rcode, xcode, reply); + rspamd_milter_send_action (session, RSPAMD_MILTER_REJECT); + } break; case METRIC_ACTION_SOFT_REJECT: rcode = rspamd_fstring_new_init (RSPAMD_MILTER_RCODE_TEMPFAIL, @@ -1638,7 +1644,8 @@ cleanup: } void -rspamd_milter_init_library (const gchar *spam_header, void *sessions_cache) +rspamd_milter_init_library (const gchar *spam_header, void *sessions_cache, + gboolean discard_on_reject) { if (milter_ctx) { g_free (milter_ctx->spam_header); @@ -1655,6 +1662,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; } rspamd_mempool_t * diff --git a/src/libserver/milter.h b/src/libserver/milter.h index 8550ecc97..2a07cef99 100644 --- a/src/libserver/milter.h +++ b/src/libserver/milter.h @@ -149,7 +149,7 @@ 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); + void *sessions_cache, gboolean discard_on_reject); /** * Returns pool for a session diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c index 4228ebef0..efb7e957b 100644 --- a/src/rspamd_proxy.c +++ b/src/rspamd_proxy.c @@ -131,6 +131,8 @@ struct rspamd_proxy_ctx { gboolean has_self_scan; /* It is not HTTP but milter proxy */ gboolean milter; + /* Discard messages instead of rejecting them */ + gboolean discard_on_reject; /* Milter spam header */ gchar *spam_header; /* Sessions cache */ @@ -789,6 +791,14 @@ init_rspamd_proxy (struct rspamd_config *cfg) G_STRUCT_OFFSET (struct rspamd_proxy_ctx, milter), 0, "Accept milter connections, not HTTP"); + rspamd_rcl_register_worker_option (cfg, + type, + "discard_on_reject", + rspamd_rcl_parse_struct_boolean, + ctx, + G_STRUCT_OFFSET (struct rspamd_proxy_ctx, discard_on_reject), + 0, + "Tell MTA to discard rejected messages silently"); rspamd_rcl_register_worker_option (cfg, type, "spam_header", @@ -2063,7 +2073,8 @@ start_rspamd_proxy (struct rspamd_worker *worker) { ctx->ev_base); } - rspamd_milter_init_library (ctx->spam_header, ctx->sessions_cache); + rspamd_milter_init_library (ctx->spam_header, ctx->sessions_cache, + ctx->discard_on_reject); event_base_loop (ctx->ev_base, 0); rspamd_worker_block_signals ();