]> source.dussan.org Git - rspamd.git/commitdiff
* Add ability to pass all filters by using flag -p in case of rspamc or adding header...
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 26 Apr 2010 13:50:13 +0000 (17:50 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 26 Apr 2010 13:50:13 +0000 (17:50 +0400)
perl/lib/Mail/Rspamd/Client.pm
rspamc.pl.in
src/filter.c
src/main.h
src/protocol.c

index 5945680f1cc832cee8c76c44b123f46f264705b0..529a2bf9b7c7edd503ae88655372780492982c8c 100644 (file)
@@ -94,6 +94,9 @@ sub new {
        else {
                $self->{weight} = 1;
        }
+       if ($args->{pass_all}) {
+               $self->{pass_all} = 1;
+       }
        if ($args->{imap_search}) {
                $self->{imap_search} = $args->{imap_search};
        }
@@ -868,6 +871,7 @@ sub _do_rspamc_command {
        syswrite $remote, "From: $self->{from}$EOL" if ($self->{from});
        syswrite $remote, "IP: $self->{ip}$EOL" if ($self->{ip});
        syswrite $remote, "Subject: $self->{subject}$EOL" if ($self->{subject});
+       syswrite $remote, "Pass: all$EOL" if ($self->{pass_all});
        if (ref $self->{rcpt} eq "ARRAY") {
                foreach ($self->{rcpt}) {
                        syswrite $remote, "Rcpt: $_ $EOL";
index 1cf6dd45aed4181a9357a64890f2b47d3a0ce4c2..ae8470a2e61f3ff28e47728826da0d63ffec09ee 100755 (executable)
@@ -44,6 +44,7 @@ Additional options:
 -w         define weight for fuzzy operations
 -S         define search string for IMAP operations
 -i         emulate that message was send from specified IP
+-p         pass message throught all filters
 
 Notes:
 imap format: imap:user:<username>:password:[<password>]:host:<hostname>:mbox:<mboxname>
@@ -191,7 +192,7 @@ my %args;
 
 HELP_MESSAGE() unless scalar @ARGV >= 1;
 
-getopt('c:h:P:s:d:w:S:H:i:', \%args);
+getopt('pc:h:P:s:d:w:S:H:i:', \%args);
 
 my $cmd = shift;
 my @path = shift;
@@ -254,6 +255,9 @@ if (defined ($args{w})) {
 if (defined ($args{i})) {
        $cfg{'ip'} = $args{i};
 }
+if (exists ($args{p})) {
+       $cfg{'pass_all'} = 1;
+}
 
 if ($cmd =~ /SYMBOLS|SCAN|PROCESS|CHECK|REPORT_IFSPAM|REPORT|URLS|EMAILS|LEARN|FUZZY_ADD|FUZZY_DEL|WEIGHTS/i) {
        $cfg{'require_input'} = 1;
index a300820da9323d3196b11f61624951e2cfdefa56..e2d6d80b8a71df8ec0b5aa762f8f945636096a52 100644 (file)
@@ -286,7 +286,9 @@ continue_process_filters (struct worker_task *task)
                                return 0;
                        }
                        else if (check_metric_is_spam (task, metric)) {
-                               break;
+                               if (!task->pass_all_filters) {
+                                       break;
+                               }
                        }
                }
                cur = g_list_next (cur);
@@ -337,7 +339,9 @@ process_filters (struct worker_task *task)
                                return 0;
                        }
                        else if (check_metric_is_spam (task, metric)) {
-                               break;
+                               if (!task->pass_all_filters) {
+                                       break;
+                               }
                        }
                }
                cur = g_list_next (cur);
index 028954c71111ebc07a67b2a8286d9544b0fa759c..04b45b8d5c4f4e4e5aa176e84db52d066a6d9def 100644 (file)
@@ -213,6 +213,7 @@ struct worker_task {
        struct timespec ts;                                                                                     /**< time of connection                                                         */
        struct rspamd_view *view;                                                                       /**< matching view                                                                      */
        gboolean view_checked;
+       gboolean pass_all_filters;                                                                      /**< pass task throught every rule                                      */
        uint32_t parser_recursion;                                                                      /**< for avoiding recursion stack overflow                      */
 };
 
index 8da0f174dab606b99d99afe7ae45193863d03d77..e7dc86e9aa76e8aaea05a345efb46073593ad21e 100644 (file)
@@ -84,6 +84,7 @@
 #define QUEUE_ID_HEADER "Queue-ID"
 #define ERROR_HEADER "Error"
 #define USER_HEADER "User"
+#define PASS_HEADER "Pass"
 #define DELIVER_TO_HEADER "Deliver-To"
 
 static GList                   *custom_commands = NULL;
@@ -200,7 +201,7 @@ parse_command (struct worker_task *task, f_str_t * line)
                break;
        }
 
-       if (strncasecmp (line->begin, RSPAMC_GREETING, sizeof (RSPAMC_GREETING) - 1) == 0) {
+       if (g_ascii_strncasecmp (line->begin, RSPAMC_GREETING, sizeof (RSPAMC_GREETING) - 1) == 0) {
                task->proto = RSPAMC_PROTO;
                task->proto_ver = RSPAMC_PROTO_1_0;
                if (*(line->begin + sizeof (RSPAMC_GREETING) - 1) == '/') {
@@ -211,7 +212,7 @@ parse_command (struct worker_task *task, f_str_t * line)
                        }
                }
        }
-       else if (strncasecmp (line->begin, SPAMC_GREETING, sizeof (SPAMC_GREETING) - 1) == 0) {
+       else if (g_ascii_strncasecmp (line->begin, SPAMC_GREETING, sizeof (SPAMC_GREETING) - 1) == 0) {
                task->proto = SPAMC_PROTO;
        }
        else {
@@ -262,7 +263,7 @@ parse_header (struct worker_task *task, f_str_t * line)
        case 'c':
        case 'C':
                /* content-length */
-               if (strncasecmp (headern, CONTENT_LENGTH_HEADER, sizeof (CONTENT_LENGTH_HEADER) - 1) == 0) {
+               if (g_ascii_strncasecmp (headern, CONTENT_LENGTH_HEADER, sizeof (CONTENT_LENGTH_HEADER) - 1) == 0) {
                        if (task->content_length == 0) {
                                tmp = memory_pool_fstrdup (task->task_pool, line);
                                task->content_length = strtoul (tmp, &err, 10);
@@ -277,7 +278,7 @@ parse_header (struct worker_task *task, f_str_t * line)
        case 'd':
        case 'D':
                /* Deliver-To */
-               if (strncasecmp (headern, DELIVER_TO_HEADER, sizeof (DELIVER_TO_HEADER) - 1) == 0) {
+               if (g_ascii_strncasecmp (headern, DELIVER_TO_HEADER, sizeof (DELIVER_TO_HEADER) - 1) == 0) {
                        task->deliver_to = memory_pool_fstrdup (task->task_pool, line);
                        debug_task ("read deliver-to header, value: %s", task->deliver_to);
                }
@@ -289,7 +290,7 @@ parse_header (struct worker_task *task, f_str_t * line)
        case 'h':
        case 'H':
                /* helo */
-               if (strncasecmp (headern, HELO_HEADER, sizeof (HELO_HEADER) - 1) == 0) {
+               if (g_ascii_strncasecmp (headern, HELO_HEADER, sizeof (HELO_HEADER) - 1) == 0) {
                        task->helo = memory_pool_fstrdup (task->task_pool, line);
                        debug_task ("read helo header, value: %s", task->helo);
                }
@@ -301,7 +302,7 @@ parse_header (struct worker_task *task, f_str_t * line)
        case 'f':
        case 'F':
                /* from */
-               if (strncasecmp (headern, FROM_HEADER, sizeof (FROM_HEADER) - 1) == 0) {
+               if (g_ascii_strncasecmp (headern, FROM_HEADER, sizeof (FROM_HEADER) - 1) == 0) {
                        task->from = memory_pool_fstrdup (task->task_pool, line);
                        debug_task ("read from header, value: %s", task->from);
                }
@@ -313,7 +314,7 @@ parse_header (struct worker_task *task, f_str_t * line)
        case 'q':
        case 'Q':
                /* Queue id */
-               if (strncasecmp (headern, QUEUE_ID_HEADER, sizeof (QUEUE_ID_HEADER) - 1) == 0) {
+               if (g_ascii_strncasecmp (headern, QUEUE_ID_HEADER, sizeof (QUEUE_ID_HEADER) - 1) == 0) {
                        task->queue_id = memory_pool_fstrdup (task->task_pool, line);
                        debug_task ("read queue_id header, value: %s", task->queue_id);
                }
@@ -325,12 +326,12 @@ parse_header (struct worker_task *task, f_str_t * line)
        case 'r':
        case 'R':
                /* rcpt */
-               if (strncasecmp (headern, RCPT_HEADER, sizeof (RCPT_HEADER) - 1) == 0) {
+               if (g_ascii_strncasecmp (headern, RCPT_HEADER, sizeof (RCPT_HEADER) - 1) == 0) {
                        tmp = memory_pool_fstrdup (task->task_pool, line);
                        task->rcpt = g_list_prepend (task->rcpt, tmp);
                        debug_task ("read rcpt header, value: %s", tmp);
                }
-               else if (strncasecmp (headern, NRCPT_HEADER, sizeof (NRCPT_HEADER) - 1) == 0) {
+               else if (g_ascii_strncasecmp (headern, NRCPT_HEADER, sizeof (NRCPT_HEADER) - 1) == 0) {
                        tmp = memory_pool_fstrdup (task->task_pool, line);
                        task->nrcpt = strtoul (tmp, &err, 10);
                        debug_task ("read rcpt header, value: %d", (int)task->nrcpt);
@@ -343,7 +344,7 @@ parse_header (struct worker_task *task, f_str_t * line)
        case 'i':
        case 'I':
                /* ip_addr */
-               if (strncasecmp (headern, IP_ADDR_HEADER, sizeof (IP_ADDR_HEADER) - 1) == 0) {
+               if (g_ascii_strncasecmp (headern, IP_ADDR_HEADER, sizeof (IP_ADDR_HEADER) - 1) == 0) {
                        tmp = memory_pool_fstrdup (task->task_pool, line);
                        if (!inet_aton (tmp, &task->from_addr)) {
                                msg_info ("bad ip header: '%s'", tmp);
@@ -356,9 +357,19 @@ parse_header (struct worker_task *task, f_str_t * line)
                        return -1;
                }
                break;
+       case 'p':
+       case 'P':
+               /* Pass header */
+               if (g_ascii_strncasecmp (headern, PASS_HEADER, sizeof (PASS_HEADER) - 1) == 0) {
+                       if (line->len == sizeof ("all") - 1 && g_ascii_strncasecmp (line->begin, "all", sizeof ("all") - 1) == 0) {
+                               task->pass_all_filters = TRUE;
+                               msg_info ("pass all filters");
+                       } 
+               }
+               break;
        case 's':
        case 'S':
-               if (strncasecmp (headern, SUBJECT_HEADER, sizeof (SUBJECT_HEADER) - 1) == 0) {
+               if (g_ascii_strncasecmp (headern, SUBJECT_HEADER, sizeof (SUBJECT_HEADER) - 1) == 0) {
                        task->subject = memory_pool_fstrdup (task->task_pool, line);
                }
                else {
@@ -367,7 +378,7 @@ parse_header (struct worker_task *task, f_str_t * line)
                break;
        case 'u':
        case 'U':
-               if (strncasecmp (headern, USER_HEADER, sizeof (USER_HEADER) - 1) == 0) {
+               if (g_ascii_strncasecmp (headern, USER_HEADER, sizeof (USER_HEADER) - 1) == 0) {
                        /* XXX: use this header somehow */
                        task->user = memory_pool_fstrdup (task->task_pool, line);
                }