PDA

View Full Version : Processing Filter scripts just not working, sometimes


m23
06-04-2005, 11:03 AM
I am working on writing an email filter in Perl, and I keep having problems: a script works just fine on the command line but does not work when used as a filter. For example, a very simple script (test.pl):

#!/usr/bin/perl

while($line = <>){print $line;}

Shouldn't this just print out the email, essentially doing nothing to it? As a processing filter, this doesn't work. From the command line it's fine:

perl spam.pl < email.txt

I get the contents of email.txt printed to the screen. But when set as a processing filter via Command 'N Control, I never get my email. It doesn't get bounced, either, and there's nothing in my /logs_email/filter.log file. The file is empty.

Also, I thought maybe it's just me, but the futurequest example script doesn't work either. You would think an example script would work ;) In the original example, the first line was #!/usr/local/bin/perl and I changed it to #!/usr/bin/perl but didn't make any difference.

#!/usr/bin/perl

# name of file where text for footer

# tag is stored
$filename = "tag.txt";

# read the original email message from

# STDIN one line at a time and
# print each line to STDOUT

while () { print; }

# open the file with the contents

# for the tag

open(TAGFILE, "<$filename") or die "Could not open tag.txt";

# read in the contents of the tag

# file a line at a time and

# print each line to STDOUT

while () { print; }
close(TAGFILE);

I have written scripts to do work, but sometimes they do sometimes they don't. I feel like I'm missing something really obvious.

m23
06-04-2005, 12:07 PM
Ok, a futurequest example python script doesn't work either. Something is definitely wrong. Works from the command line, but not as an email filter. When I choose any custom email filter, I no longer get email. I can't see how I could possibly do anything incorrect: in Command 'N' Control, if I enter an incorrect path to the script, I get an error. Since I don't get an error in Command 'N' Control when choosing the script and choosing type Processing, that means that another futurequest example script is not working for me.

When I remove the email filter, I start getting email again.

Could I have done something eariler in test scripts that would cause any subsequest filter to not work? By the way, here is futurequest Python example script I tested.

#!/usr/bin/python2

# copy and paste this script and
# save as addheader.py

import sys

while 1:
# read stdin one line at a time
line = sys.stdin.readline()

# if no more input, or end of headers
# exit the loop
if not line or line == '\n':
break

# if there is a non-blank line of input
# write it to stdout
sys.stdout.write(line)

# print the custom header
print 'X-comment: This is my custom header'

# print a blank line to separate the headers
# from the email message body, per RFCs
print

# for data past the end of the original
# mail headers
while 1:
line = sys.stdin.readline()
if not line:
break
sys.stdout.write(line)

kitchin
06-04-2005, 12:17 PM
Hi, what are the permissions for that first Perl file? I tested it and it works for me.

For the second Perl example, "while()" should be "while(<>)" but that's probably a forum thing.
The example script is here, just to make this easier to follow:
http://www.aota.net/Email_Extras/eScripts.php4

m23
06-05-2005, 07:52 PM
It was the permissions on the log file at /logs_email/filter.log. Apparently, the filters don't work if the log file's permissions are not 640. I had it set as 644. Sheila figured this out and the problem is resolved. Custom filters are running again.

About the Perl example I cited as not working, I do believe it needs to be fixed. There are two examples of the same script. There is a static HTML page with one example that you cited, but there is another dynamic page with a second example, which I cited.

Here is a link to the example Perl script that does not work http://service.futurequest.net/index.php?_a=knowledgebase&_j=questiondetails&_i=98&nav=+%26gt%3B+%3Ca+href%3D%27index.php%3F_a%3Dknowledgebase%26_j% 3Dsubcat%26_i%3D33%27%3ESpam%2FEmail+Filters%3C%2Fa%3E

sheila
06-05-2005, 08:14 PM
First of all, we want to thank you for pointing out the error. I will assign this to the appropriate staff member for corrections.

Let me explain how that error comes to be in the Knowledgebase...

Our "new" Service Desk software sometimes eats "angle brackets" and code contained inside of them.

The original tutorial for that topic, on our "old" tutorials page, is located here:
http://www.aota.net/Email_Extras/eScripts.php4

You can see the script is correctly written there.

Apparently when it was transferred, the fact that some characters that appeared in the original do not also appear in the new version went unnoticed. (The "new version" is the Knowledgebase we generally try to refer clients to nowadays--and the page you were viewing).

It is amazing to me that in all the time since we have had the new "Knowledgebase" tutorials up, no one has noticed this error.

Our apologies for any confusion this error caused, and we will get it fixed up so that we can prevent the same confusion for someone else in the future.

Thanks again, for your help. :smile:

m23
06-05-2005, 10:18 PM
I'm glad I could do something to help. I've received a lot of help lately from you sheila, and from a user, kitchen.

I'm hoping when I'm done this spam filter script will be useful to others. I might rewrite it in python or ruby, might as well compare those to Perl. In any case, I'm hoping this will pay off for the futurequest community. I'm so sick of spam I've decided to be more proactive.