GetOptions(
"host=s" => \$rspamd_host,
"header=s" => \$header,
- "local" => \$local,
"reject-message=s" => \$reject_message,
"help|?" => \$help,
"man" => \$man
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);
});
}
}
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
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>