aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2010-04-26 17:50:13 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2010-04-26 17:50:13 +0400
commit971bad45c44cf430bde13faede56699ba0381e83 (patch)
treed82e66c29b32430ea39729bc3fa8e478ddd14e50
parent5b9251914c25fa6559e5680f03d7efddad9af736 (diff)
downloadrspamd-971bad45c44cf430bde13faede56699ba0381e83.tar.gz
rspamd-971bad45c44cf430bde13faede56699ba0381e83.zip
* Add ability to pass all filters by using flag -p in case of rspamc or adding header Pass: all in rspamc protocol
-rw-r--r--perl/lib/Mail/Rspamd/Client.pm4
-rwxr-xr-xrspamc.pl.in6
-rw-r--r--src/filter.c8
-rw-r--r--src/main.h1
-rw-r--r--src/protocol.c35
5 files changed, 39 insertions, 15 deletions
diff --git a/perl/lib/Mail/Rspamd/Client.pm b/perl/lib/Mail/Rspamd/Client.pm
index 5945680f1..529a2bf9b 100644
--- a/perl/lib/Mail/Rspamd/Client.pm
+++ b/perl/lib/Mail/Rspamd/Client.pm
@@ -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";
diff --git a/rspamc.pl.in b/rspamc.pl.in
index 1cf6dd45a..ae8470a2e 100755
--- a/rspamc.pl.in
+++ b/rspamc.pl.in
@@ -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;
diff --git a/src/filter.c b/src/filter.c
index a300820da..e2d6d80b8 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -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);
diff --git a/src/main.h b/src/main.h
index 028954c71..04b45b8d5 100644
--- a/src/main.h
+++ b/src/main.h
@@ -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 */
};
diff --git a/src/protocol.c b/src/protocol.c
index 8da0f174d..e7dc86e9a 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -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);
}