diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-08-04 10:42:33 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-08-04 10:42:33 +0100 |
commit | af7255bac4318ec96b0b36a57ea87ea893ba7b02 (patch) | |
tree | 293bbc0cb07bf0d7f09ad5ab8f46c282f86305b2 /utils/cgp_rspamd.pl | |
parent | 9fd26f1ff73dd5c3eee81dc17f1cf69445b9ae4c (diff) | |
download | rspamd-af7255bac4318ec96b0b36a57ea87ea893ba7b02.tar.gz rspamd-af7255bac4318ec96b0b36a57ea87ea893ba7b02.zip |
[Fix] Parse CGP envelope data
Diffstat (limited to 'utils/cgp_rspamd.pl')
-rw-r--r-- | utils/cgp_rspamd.pl | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/utils/cgp_rspamd.pl b/utils/cgp_rspamd.pl index f9e0bb4d7..482bbd3bb 100644 --- a/utils/cgp_rspamd.pl +++ b/utils/cgp_rspamd.pl @@ -20,7 +20,6 @@ my $reject_message = "Spam message rejected"; GetOptions( "host=s" => \$rspamd_host, "header=s" => \$header, - "local" => \$local, "reject-message=s" => \$reject_message, "help|?" => \$help, "man" => \$man @@ -100,13 +99,51 @@ sub rspamd_scan { if ($local) { # Use file scan + # XXX: not implemented now due to CGP queue format http_get("http://$rspamd_host/symbols?file=$file", $http_callback); } else { aio_load($file, sub { my ($data) = @_ or return print "* Cannot open $file: $!\n$tag FAILURE\n"; - http_post("http://$rspamd_host/symbols", $data, $http_callback); + # Parse CGP format + $data =~ s/^((?:[^\n]*\n)*?)\n(.*)$/$2/ms; + my @envelope = split /\n/, $1; + chomp(@envelope); + my $from; + my @rcpts; + my $ip; + + foreach my $elt (@envelope) { + if ($elt =~ /^P\s[^<]*(<[^>]*>).*$/) { + $from = $1; + } + elsif ($elt =~ /^R\s[^<]*(<[^>]*>).*$/) { + push @rcpts, $1; + } + elsif ($elt =~ /^S .*\[(.+)\]/) { + $ip = $1; + } + } + + my $headers = {}; + if ($file =~ /\/([^\/.]+)\.msg$/) { + $headers->{'Queue-ID'} = $1; + } + if ($from) { + $headers->{From} = $from; + } + if (scalar(@rcpts) > 0) { + # XXX: Anyevent cannot parse headers with multiple values + foreach (@rcpts) { + $headers->{Rcpt} = $_; + } + } + if ($ip) { + $headers->{IP} = $ip; + } + + http_post("http://$rspamd_host/symbols", $data, headers => $headers, $http_callback); }); } } @@ -154,7 +191,6 @@ cgp_rspamd [options] Options: --host=hostport Rspamd host to connect (localhost:11333 by default) - --local Rspamd runs locally and can access CGP files (false by default) --header Add specific header for a spam message ("X-Spam: yes" by default) --reject-message Rejection message for spam mail ("Spam message rejected" by default) --help brief help message @@ -168,10 +204,6 @@ cgp_rspamd [options] Specifies Rspamd host to use for scanning -=item B<--local> - -Should be used if Rspamd runs on the same machine and can access CGP files - =item B<--header> Specifies the header that should be added when Rspamd action is B<add header> |