943,393 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Marked Solved
  • Views: 5412
  • Perl RSS
Feb 12th, 2004
0

help with my perl code

Expand Post »
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, 23 views)
Similar Threads
Reputation Points: 11
Solved Threads: 2
Junior Poster
spikes is offline Offline
106 posts
since Jul 2003
Feb 29th, 2004
0

Re: help with my perl code

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.
Reputation Points: 46
Solved Threads: 1
Banned
WEATHER CHANNEL is offline Offline
150 posts
since Jan 2004
Apr 29th, 2004
0

Re: help with my perl code

Quote 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.

Perl Syntax (Toggle Plain Text)
  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
Reputation Points: 66
Solved Threads: 3
Junior Poster
liliafan is offline Offline
117 posts
since Apr 2004
Apr 30th, 2004
0

Re: help with my perl code

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
Reputation Points: 11
Solved Threads: 2
Junior Poster
spikes is offline Offline
106 posts
since Jul 2003

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: FormMail.pl
Next Thread in Perl Forum Timeline: Beginning Perl





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC