help with my perl code

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2003
Posts: 106
Reputation: spikes is an unknown quantity at this point 
Solved Threads: 1
spikes's Avatar
spikes spikes is offline Offline
Junior Poster

help with my perl code

 
0
  #1
Feb 12th, 2004
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
Attached Files
File Type: txt mimedefang-filter.txt (18.8 KB, 3 views)
Reply With Quote Quick reply to this message  
Join Date: Jan 2004
Posts: 150
Reputation: WEATHER CHANNEL will become famous soon enough WEATHER CHANNEL will become famous soon enough 
Solved Threads: 1
WEATHER CHANNEL's Avatar
WEATHER CHANNEL WEATHER CHANNEL is offline Offline
Banned

Re: help with my perl code

 
0
  #2
Feb 29th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 113
Reputation: liliafan is on a distinguished road 
Solved Threads: 2
liliafan's Avatar
liliafan liliafan is offline Offline
Junior Poster

Re: help with my perl code

 
0
  #3
Apr 29th, 2004
Originally Posted by spikes
sub filter_begin ()
I can't find anywhere in your script where this is being called, therefore it wouldn't do anything.

  1. # Subject check
  2. my($msgSubject);
  3. my($hfile) = "HEADERS";
  4. while(<HEADERS>) {
  5. chomp;
  6. $line = $_;
  7. $idx = index($line, "Subject: ");
  8. if (idx == 0){
  9. $msgSubject = substr($line, 9);
  10. }
  11. }

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
Application development, webhosting, and much more: www.webcentric-hosting.com
Reply With Quote Quick reply to this message  
Join Date: Jul 2003
Posts: 106
Reputation: spikes is an unknown quantity at this point 
Solved Threads: 1
spikes's Avatar
spikes spikes is offline Offline
Junior Poster

Re: help with my perl code

 
0
  #4
Apr 30th, 2004
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
"it's not to old to do cool stuff, it's just to old to do it with graphics"
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Perl
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC