]> source.dussan.org Git - rspamd.git/commitdiff
* Do not really check messages that should be skipped
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 19 Oct 2009 16:35:27 +0000 (20:35 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 19 Oct 2009 16:35:27 +0000 (20:35 +0400)
* Add Skip state for such messages (not False and not True)

src/filter.c
src/main.h
src/protocol.c
src/view.c
src/view.h

index fefdd968cdb42651ee6b8ea3a8816c16be184032..fc23d81b902bd7bbe73d08b4b63fb2b2ee277635 100644 (file)
@@ -35,6 +35,7 @@
 #include "util.h"
 #include "expressions.h"
 #include "settings.h"
+#include "view.h"
 #include "classifiers/classifiers.h"
 #include "tokenizers/tokenizers.h"
 
@@ -311,8 +312,17 @@ process_filters (struct worker_task *task)
                task->save.saved = 0;
                return continue_process_filters (task);
        }
+       /* Check skip */
+       if (check_skip (task->cfg->views, task)) {
+               task->is_skipped = TRUE;
+               task->state = WRITE_REPLY;
+               msg_info ("process_filters: disable check for message id <%s>, view wants spam", task->message_id);
+               return 1;
+       }
        /* Check want spam setting */
        if (check_want_spam (task)) {
+               task->is_skipped = TRUE;
+               task->state = WRITE_REPLY;
                msg_info ("process_filters: disable check for message id <%s>, user wants spam", task->message_id);
                return 1;
        }
@@ -527,6 +537,8 @@ classifiers_callback (gpointer value, void *arg)
        f_str_t                         c;
 
        cur = g_list_first (task->text_parts);
+       ctx = cl->classifier->init_func (task->task_pool, cl);
+
        if ((tokens = g_hash_table_lookup (data->tokens, cl->tokenizer)) == NULL) {
                while (cur != NULL) {
                        text_part = (struct mime_text_part *)cur->data;
@@ -550,7 +562,6 @@ classifiers_callback (gpointer value, void *arg)
                return;
        }
 
-       ctx = cl->classifier->init_func (task->task_pool, cl);
        cl->classifier->classify_func (ctx, task->worker->srv->statfile_pool, tokens, task);
 
        /* Autolearning */
@@ -572,7 +583,10 @@ void
 process_statfiles (struct worker_task *task)
 {
        struct statfile_callback_data   cd;
-
+       
+       if (task->is_skipped) {
+               return;
+       }
        cd.task = task;
        cd.tokens = g_hash_table_new (g_direct_hash, g_direct_equal);
 
index 00b2d22bc82d3c11417c70f01b080bf35a04e9b1..35ea627bea985220ad70d6a0e5af72b7b1587b34 100644 (file)
@@ -174,6 +174,7 @@ struct worker_task {
        struct custom_command *custom_cmd;                                                      /**< custom command if any                                                      */      
        int sock;                                                                                                       /**< socket descriptor                                                          */
     gboolean is_mime;                                           /**< if this task is mime task                      */
+    gboolean is_skipped;                                        /**< whether message was skipped by configuration   */
        char *helo;                                                                                                     /**< helo header value                                                          */
        char *from;                                                                                                     /**< from header value                                                          */
        char *queue_id;                                                                                         /**< queue id if specified                                                      */
index cb69666321b229ae71363e6797ca1991c48fb9e7..3758de8a2ba4153012b3a96944792bf3dd3b7e83 100644 (file)
@@ -540,13 +540,23 @@ show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data
                }
                else {
                        if (strcmp (task->proto_ver, RSPAMC_PROTO_1_1) == 0) {
-                               r = snprintf (outbuf, sizeof (outbuf), "Metric: default; False; 0 / %.2f / %.2f" CRLF, ms, rs);
+                if (!task->is_skipped) {
+                                   r = snprintf (outbuf, sizeof (outbuf), "Metric: default; False; 0 / %.2f / %.2f" CRLF, ms, rs);
+                }
+                else {
+                                   r = snprintf (outbuf, sizeof (outbuf), "Metric: default; Skip; 0 / %.2f / %.2f" CRLF, ms, rs);
+                }
                        }
                        else {
                                r = snprintf (outbuf, sizeof (outbuf), "Metric: default; False; 0 / %.2f" CRLF, ms);
                        }
                }
-               cd->log_offset += snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: F: [0/%.2f/%.2f] [", "default", ms, rs);
+        if (!task->is_skipped) {
+                   cd->log_offset += snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: F: [0/%.2f/%.2f] [", "default", ms, rs);
+        }
+        else {
+                   cd->log_offset += snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: S: [0/%.2f/%.2f] [", "default", ms, rs);
+        }
        }
        else {
                if (!check_metric_settings (task, metric_res->metric, &ms, &rs)) {
@@ -561,16 +571,29 @@ show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data
                }
                else {
                        if (strcmp (task->proto_ver, RSPAMC_PROTO_1_1) == 0) {
-                               r = snprintf (outbuf, sizeof (outbuf), "Metric: %s; %s; %.2f / %.2f / %.2f" CRLF, 
+                if (!task->is_skipped) {
+                                   r = snprintf (outbuf, sizeof (outbuf), "Metric: %s; %s; %.2f / %.2f / %.2f" CRLF, 
                                                (char *)metric_name, (is_spam) ? "True" : "False", metric_res->score, ms, rs);
+                }
+                else {
+                                   r = snprintf (outbuf, sizeof (outbuf), "Metric: %s; Skip; %.2f / %.2f / %.2f" CRLF, 
+                                               (char *)metric_name, metric_res->score, ms, rs);
+                }
                        }
                        else {
                                r = snprintf (outbuf, sizeof (outbuf), "Metric: %s; %s; %.2f / %.2f" CRLF, 
                                                (char *)metric_name, (is_spam) ? "True" : "False", metric_res->score, ms);
                        }
                }
-               cd->log_offset += snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: %s: [%.2f/%.2f/%.2f] [", 
+        if (!task->is_skipped) {
+                   cd->log_offset += snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: %s: [%.2f/%.2f/%.2f] [", 
                                (char *)metric_name, is_spam ? "T" : "F", metric_res->score, ms, rs);
+        }
+        else {
+                   cd->log_offset += snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "(%s: %s: [%.2f/%.2f/%.2f] [", 
+                               (char *)metric_name, "S", metric_res->score, ms, rs);
+        
+        }
        }
        if (task->cmd == CMD_PROCESS) {
 #ifndef GMIME24
index 393882049ad461167b7fc138a1a0ecc7721010e8..0f9aefcf7085eed432134ff5ca85f86d6600b8c2 100644 (file)
@@ -163,6 +163,10 @@ match_view_symbol (struct rspamd_view *v, const char *symbol)
        GList                          *cur;
        struct rspamd_regexp           *re;
 
+       /* Special case */
+       if (symbol == NULL) {
+               return TRUE;
+       }
        /* First try to lookup in hashtable */
        if (g_hash_table_lookup (v->symbols_hash, symbol) != NULL) {
                return TRUE;
@@ -218,3 +222,12 @@ check_view (GList * views, const char *symbol, struct worker_task * task)
 
        return FALSE;
 }
+
+gboolean
+check_skip (GList * views, struct worker_task * task)
+{
+       if (check_view (views, NULL, task) == FALSE) {
+               return TRUE;
+       }
+       return FALSE;
+}
index 91a5d6277c3085a46c749b304088fee8c578b7bc..9114c639358bac36eaab339066c3f95da6b3d523 100644 (file)
@@ -25,5 +25,6 @@ gboolean add_view_ip (struct rspamd_view *view, char *line);
 gboolean add_view_symbols (struct rspamd_view *view, char *line);
 
 gboolean check_view (GList *views, const char *symbol, struct worker_task *task);
+gboolean check_skip (GList *views, struct worker_task *task);
 
 #endif