Help - Search - Members - Calendar
Full Version: reporter.pl - it needs a modification
SpamCop Discussion > Discussions & Observations > SpamCop Reporting Help
william_
Hi,

I use reporter.pl http://www.spamcop.net/reporter.pl.
Does anyone have an amount of perl knowledge so that they can fix my modifications:

CODE
#!/usr/bin/perl

open(SENDMAIL, "|/usr/sbin/sendmail -oi -t") || die "Cannot open sendmail output";

print SENDMAIL  <<"ENDENDEND";
From: root\@mydomain.com
To: testaddress\@mydomain.com
Subject: report spam
MIME-Version: 1.0
Content-Type: message/rfc822

ENDENDEND

# check whether the ISP has sent the reply to a junkmail address, and then just cancel
my $string = "spamcop";  #added
while (defined($_ = <STDIN>)) {
        my $result = index($_, $string); #added
        if ($result == -1){ #added
                close (SENDMAIL); #added
                exit #added
        } #added
        print SENDMAIL;
}
close (SENDMAIL);


The scri_pt above does not work correctly.
if the lines with #added are removed then it works perfectly.
The aim of the crude changes was to modifiy the behaviour of the scri_pt so that it checked for the presence of the word spamcop and then just abort sending that email.

Thinking about it it would be nicer to forward the email to a different location upon finding mention of spamcop.
rconner

You didn't say what doesn't work correctly about the program, but I'm guessing that it doesn't cancel the sending of messages when the spam attachment contains "spamcop" as you want it to do.

I don't think this scri_pt was meant to be used to do what you are trying to do. Once you open the pipe to sendmail and begin sending it stuff, you can't back out -- even if you stop in the middle it is going to try to send what you've already given it.

One could modify this program to collect all the spam data in a local variable and then test it before writing it to sendmail, but I think it might be simpler to run a grep command on your spam before handing it to this scri_pt. If the grep detects the forbidden word, then you can simply decline to send it using this scri_pt. You should be able to do this with a simple shell scri_pt, or perhaps with pipes.

-- rick

william_
you are quite right Rick, i'll try some of your ideas.
william_
Here is a working modification:
reporterv2.pl
CODE
#!/usr/bin/perl

my $spamcop_email="--------------\@spam.spamcop.net";
my $admin_email="anaddress\@mydomain.com";

# for testing :
# my $spamcop_email="address1\@mydomain.com";
# my $admin_email="address2\@mydomain.com";

my $destination="";

my $search_string = 'spamcop';
my $junk_email = "";
while (defined($_ = <STDIN>)) {
        $junk_mail = $junk_mail.$_;
}
my $result = index($junk_mail, $search_string);
if ($result == -1){
        $destination=$spamcop_email;
} else {
        $destination=$admin_email;
}

my $message =<<"ENDENDEND";
From: adminaddress\@mydomain.com
To: $destination
Subject: report spam
MIME-Version: 1.0
Content-Type: message/rfc822

$junk_mail

ENDENDEND

open(SENDMAIL, "|/usr/sbin/sendmail -oi -t") || die "Cannot open sendmail output";
print SENDMAIL $message;
close (SENDMAIL);

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.