summaryrefslogtreecommitdiffstats
path: root/rspamc.pl.in
diff options
context:
space:
mode:
authorcebka@lenovo-laptop <cebka@lenovo-laptop>2010-03-04 20:56:47 +0300
committercebka@lenovo-laptop <cebka@lenovo-laptop>2010-03-04 20:56:47 +0300
commita1b42701ad0a678dc0453a41babd54edd96abeb1 (patch)
tree712fa0bc1ccbd968679a3e5149ffae041e03ec93 /rspamc.pl.in
parent9097fc043e38a27241381e383b97e00254fbf711 (diff)
downloadrspamd-a1b42701ad0a678dc0453a41babd54edd96abeb1.tar.gz
rspamd-a1b42701ad0a678dc0453a41babd54edd96abeb1.zip
* Make new Mail::Rspamd::Client working
Diffstat (limited to 'rspamc.pl.in')
-rwxr-xr-xrspamc.pl.in72
1 files changed, 69 insertions, 3 deletions
diff --git a/rspamc.pl.in b/rspamc.pl.in
index a8f410ba8..ba00d5a5c 100755
--- a/rspamc.pl.in
+++ b/rspamc.pl.in
@@ -9,7 +9,7 @@
use Socket qw(:DEFAULT :crlf);
use Getopt::Std;
-use Data::Dumper;
+use Term::Cap;
use Mail::Rspamd::Client;
my %cfg = (
@@ -25,6 +25,8 @@ my %cfg = (
'imap_search' => 'ALL',
);
+my $terminal;
+
$main::VERSION = '@RSPAMD_VERSION@';
sub HELP_MESSAGE {
@@ -133,6 +135,50 @@ sub parse_config {
}
+sub print_control_result {
+ my ($host, $res) = @_;
+
+ $terminal->Tputs( 'md', 1, *STDOUT );
+ print "Results for host $host:\n\n";
+ $terminal->Tputs( 'me', 1, *STDOUT );
+ if ($res->{error_code} == 0) {
+ print "$res->{error}\n";
+ }
+ else {
+ print "Error occured: $res->{error_code}:\n$res->{error}\n";
+ }
+}
+
+sub print_rspamc_result {
+ my ($host, $res) = @_;
+
+ $terminal->Tputs( 'md', 1, *STDOUT );
+ print "Results for host $host:\n\n";
+ $terminal->Tputs( 'me', 1, *STDOUT );
+
+ if (defined($res->{error})) {
+ print "Error occured: $res->{error}\n\n";
+ }
+ else {
+ while (my ($metric, $result) = each (%{ $res })) {
+ $terminal->Tputs( 'md', 1, *STDOUT );
+ print "$metric: ";
+ $terminal->Tputs( 'me', 1, *STDOUT );
+ print "$result->{isspam}, [ $result->{score} / $result->{threshold} ]\n";
+
+ $terminal->Tputs( 'md', 1, *STDOUT );
+ print "Symbols: ";
+ $terminal->Tputs( 'me', 1, *STDOUT );
+ print join("; ", @{ $result->{symbols} }) . "\n";
+ print "Urls: " . join(", ", @{ $result->{urls} }) . "\n";
+ foreach my $msg (@{ $result->{messages} }) {
+ print "Message: $msg\n";
+ }
+ print "\n\n";
+ }
+ }
+}
+
############################# Main part ###########################################
my %args;
@@ -210,6 +256,8 @@ if (defined ($args{H})) {
my $rspamd = Mail::Rspamd::Client->new(\%cfg);
+$terminal = Tgetent Term::Cap { TERM => undef, OSPEED => 9600 };
+
if (!defined ($path[0]) || ! $cfg{'require_input'}) {
my $input;
if ($cfg{'require_input'}) {
@@ -219,9 +267,27 @@ if (!defined ($path[0]) || ! $cfg{'require_input'}) {
}
my $res = $rspamd->do_all_cmd ($input);
- print Dumper($res);
+ while (my ($host, $result) = each (%{ $res })) {
+ if ($cfg{control}) {
+ print_control_result ($host, $result);
+ }
+ else {
+ print_rspamc_result ($host, $result);
+ }
+ }
}
else {
my $res = $rspamd->process_path (@path);
- print Dumper($res);
+
+ while (my ($item, $result) = each (%{ $res })) {
+ print "Results for item $item:\n";
+ while (my ($host, $r) = each (%{ $result })) {
+ if ($cfg{control}) {
+ print_control_result ($host, $r);
+ }
+ else {
+ print_rspamc_result ($host, $r);
+ }
+ }
+ }
}