]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow to discard messages instead of rejection
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 5 Jul 2017 07:31:17 +0000 (08:31 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 5 Jul 2017 07:31:17 +0000 (08:31 +0100)
Issue: #1723

src/libserver/milter.c
src/libserver/milter.h
src/rspamd_proxy.c

index dad7c5afaca273d406068af601e343455f4f0948..4f235c2aae09ef004c474ad27f13ac27f786be37 100644 (file)
@@ -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 *
index 8550ecc9778f9a8046542398d846a9a2b25fec9a..2a07cef99006bd792ceea11a28c6b48441e0258a 100644 (file)
@@ -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
index 4228ebef0eed7bc0df5b90b8125d1f23f19f4266..efb7e957be4a8f01122e9a19dbaea1b163c690bb 100644 (file)
@@ -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 ();