#!/usr/bin/perl -T
##
## razor-report - reports spam to a razor server.
##
## Copyright (c) 1998, Vipul Ved Prakash.  All rights reserved.
## This code is free software; you can redistribute it and/or modify
## it under the same terms as Perl itself.
##
## $Id: razor-report,v 1.10 2001/12/25 09:44:30 vipul Exp $

use lib qw(lib);
use Razor::Agent;
use Razor::Config; 

my $options = Razor::Agent::options('razor-report');
my $config = Razor::Config::findconf ('razor.conf');
my $rc = new Razor::Agent ($config, %$options, (zonetype => 'report'))
    or Razor::Agent->raise_error($Razor::Client::errstr);
my @sigs = $rc->compute_sigs;
my %check = ( sigs => \@sigs );

# background myself 
unless ($options->{foreground}) {
    chdir '/'; fork && exit; POSIX::setsid;
    close 0, 1, 2;
}

my $response = $rc->report (%check);
unless ($response) { 
    $rc->raise_error(); 
}
if (scalar @$response == 1) { 
    if ($response->[0]) { exit 0 } else { exit 1 }
} else { 
    my $counter = 1;
    for (@$response) { 
        if ($_) { 
            print "$counter\n"; 
            $hasspam = 1;
        } else { print "-$counter\n" if $$options{negative} }
        $counter++;
    }
    if ($hasspam) { exit 0 } else { exit 1 }
}
exit 1;


=head1 NAME

razor-report - Razor Reporting Agent

=head1 SYNOPSIS

	cat spamfile | razor-report 

=head1 DESCRIPTION

C<razor-report> is the Razor Reporting Agent which is used for reporting spam
messages to a Razor Catalogue Server. C<razor-report> should be generally
called from a MUA, although there are no restrictions on invoking it from
the command-line. C<razor-report> is a filter, which means that spam messages
should be piped through it. By default, C<razor-report> backgrounds and
detaches itself from the control terminal at start-up.

=head1 USAGE

C<razor-report> takes following arguments: 

=over 4

=item C<-s>

Simulate only.  Don't talk to the server.

=item C<-f>

Stay in foreground.

=item C<-d>

Print debugging information.	

=item C<-H>

Compute and print the SHA hash of the mail contents. And then exit.

=item C<-M | --mbox> 

Accept a mailbox name on the command line and report every mail in the
mailbox against the database. C<razor-report> will print out the serial
number of every mail that was accepted by the Catalogue server. Please use
this option with utmost caution. You don't want to fill up the Catalogue
with non-spam signatures.

 razor-report -M ~/Mail/todays-spam

=item C<-S | --sig>

Accept a list of pre-computed (with C<-H>) signatures on the command line,
instead of computing one from mail content. When called with C<--sig>,
C<razor-report> will not attempt to read from STDIN. Usage:
 
  razor-report -d -sig a8a3d545adb73f9733675571ffeaf10cba87745b

=item C<-conf=filename>

The path of the config file. By default the path is ~/razor.conf, an
alternate path can be specified with this option. See razor.conf(5)
manpage for various configuration options.

=item C<-h>

Print a usage message and exit.

=item C<-v>

Print the version number and exit.

=back

=head1 INTEGRATION WITH MUTT

Add the following line to C<mutt.conf>

     macro index S "|/usr/bin/razor-report"

Then press S on the spam message in C<mutt> to report it with
C<razor-report>. Since C<razor-report> forks, the control will return
immediately.

=head1 SETTING UP A TROLLBOX 

By replying to spammers from an address that you don't use for legit
communications, you can build I<troll addresses> that gather spam. When
you reply to spammers they usually add the "From" address in your reply to
their mailing lists. Eventually this address will start getting spammed.
Other ways of building troll boxes is to post to USENET from troll
addresses, or embed them in your webpages. Mail destined to these
addresses should be directly fed to C<razor-report> via procmail(1) or a
similar mail processor.

If C<foo-spam@bar.com> is your troll address, you would use the following
procmail recipe to automatically report spam:

    :0 W
    * ^To: foo-spam@bar.com
    | /usr/bin/razor-report

Troll boxes are also useful for reporting spam from machines where
C<razor-report> is not available. Simply bounce the message to your troll
address and it will be reported via C<razor-report>.

The following macro can be used to bounce a spam to a troll box from
C<mutt> by pressing the `S' key.

    macro index S "b foo-spam@bar.com^Myd"

where a literal C<^M> is typed as C<Ctrl-V + Ctrl-M>.

=head1 AUTHOR

Vipul Ved Prakash, E<lt>mail@vipul.netE<gt>

=cut

=head1 SEE ALSO

razor.conf(5), razor-check(1), razor-discover(1)

=head1 LICENSE 

This is free software, distributed under the ARTISTIC license.


