Hi All,
I'm haveing some problems with my perl code. the script is for a mail filtering program called mimedefang, the code is the main filter.

the fist bit of code is used to filter out mail based on the subject line.

sub filter_begin () {
my($msgSubject, $hfile) = @_;


# ALWAYS drop messages with suspicious chars in headers
if ($SuspiciousCharsInHeaders) {
md_graphdefang_log('suspicious_chars');
action_quarantine_entire_message("Message quarantined because of suspicious characters in headers");
# Do NOT allow message to reach recipient(s)
return action_discard();
}


# Subject check
my($msgSubject);
my($hfile) = "HEADERS";
while(<HEADERS>) {
chomp;
$line = $_;
$idx = index($line, "Subject: ");
if (idx == 0){
$msgSubject = substr($line, 9);
}
}


if (($msgSubject =~ /RE: [A-Z] {2,},(?: [A-Z]+!?)+/) ||
($msgSubject =~ /\bparis hilton\b/ )) {


#Bounce the mail!
action_bounce("Forbiden subject matter - Rejected");
}

this next bit is used to move any mail tagged as spam to an admin/spam folder on the server, following this is the code used to append a header to say that the virus scan was performed and no virus was found.

# If SpamAssassin found SPAM, append report.  We do it as a separate
# attachment of type text/plain
sub filter_end ($) {
my($entity) = @_;


if ($message_is_spam) {
# Add a header with original recipients, just for info
action_add_header("X-Orig-Rcpts", join(", ", @Recipients));


# Remove original recipients
foreach $recip (@Recipients) {
delete_recipient($recip);
}


# Send to spam address
add_recipient('admin@andi.com');
}


#virus checked header
if ($FoundVirus) {
action_add_header("X-virus_checked", "$FoundVirus");
}

the problem that i have is that the code is in place but is not doing anything at the moment. i am not a perl coder and am only guessing at the code. if you can see anything missing or undecleard or just have suggestions they will be welcome.

attached (i hope) is the acctual perl script fillter, so you can see where these bits fit in.

thanks for looking,

spikes

Scripts "Seperate l00zer SYSOP's from the UBER SYSOP's " .
Some will say that, Oreilly books on PERL are hard to read, but I disagree. PERL will just take time to learn period. I remeber the first Oreilly book I picked up was the Camel book, worth every penny ($40.00 US Dollar) I might add.
www.Perl.Oreilly.com
(add in) report SP@M to UCE@FTC.gov
But over all I would say your trying to reinvent the wheel aka a simple script.
Sign up for Em@ils. @WWC www.worldwidecreations.com/freescripts.htm
Goodluck with the C&P code hope it works out.

sub filter_begin ()

I can't find anywhere in your script where this is being called, therefore it wouldn't do anything.

# Subject check
    my($msgSubject);
    my($hfile) = "HEADERS";
    while(<HEADERS>) {
        chomp;
        $line = $_;
        $idx = index($line, "Subject: ");
        if (idx == 0){
                $msgSubject = substr($line, 9);
        }
    }

You are assigning the value "HEADERS" to $hfile, so:
print $hfile;

would print HEADERS.

If you are trying to read the value of a file, I would suggest passing it as an array, and doing:

foreach $line (@file) {

instead of

while(<HEADERS>) {

Either that or open the file in the function:

open(HEADERS,"filename.txt");

while(<HEADERS>) {

Or pass the file handle to the function:

filter_begin("subject", *HEADERS);

sub filter_begin {
my ($blah, $handle) = @_;

while(<$handle>) {

Sorry if this isn't very clear I haven't been awake long.

HTH
Ben

thanks for the advice, i have found that the headers value is ready defined in the program and i dont have to do anything with it apart from call it.
since the first post in this thread i have got eveything up and running, so as much as i am no closer to really understanding perl, i'll say that this thread is closed and resolved.

cheers

spikes

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.