PDA

View Full Version : Email filter problem


greengrouper
10-08-2001, 05:56 AM
I'm having problems getting this to work:

I want to filter out 'malicious_spammer@theirdomain.com' from going through an email alias 'ralph@mydomain.com' hosted on RASMUS.

So I create .qmail-ralph and upload it to /big/dom/xmydomain/


|bouncesaying "Message rejected" /usr/bin/env python /big/dom/xcuthilleddy/redir.py
|vdeliver

and redir.py and upload it also to /big/dom/xmydomain/


import sys
import rfc822

headers=rfc822.Message(sys.stdin, 0)
name, email = headers.getaddr("From")
if email == "malicious_spammer@theirdomain.com":
sys.exit(0)
else:
sys.exit(1)


It does not get filtered, at all. What am I doing wrong?

Monty
10-09-2001, 12:20 PM
here's a working example that might help you out that Shelia helped me with

email address being filtered monty@2coolfishing.com

.qmail-monty file


|condredirect nospam@2coolfishing.com /usr/bin/env python /big/dom/xoutdoorsshow/redir.py
|vdeliver



redir.py file



# list all the e-mail addresses in BadFromList that
# if they appear in the FROM field of the e-mail message
# you will want to redirect them. enclose each addy in quotes
# separate them with commas, and put an open bracket before the
# first one and a closing bracket after the last one.
# They can be on separate lines (as shown below) or one a single
# line (if the list is short)

# BadFromList = ["spammy1@domain1.com",
# "spammy2@domain2.com",
# "spammy3@domain3.com"]
BadFromList = [
"ddrbos@mediaone.net",
"kathi720@adelphia.net",
"arbhb@mail.yahoo.co.jp",
"poeceu@msn.com",
"amorc@way.cz",
"gale_h@jkmn.ne",
"pixitup@aol.com",
"alex@fauxfinished.com",
"books4ubbreviation@angelfire.com",
"ljwwaters@aol.com"]

# For any domains from which you wish to redirect any and
# all mail that you receive from that domain, list them
# in the BadDomains list. Same as for BadFromList (separate
# with commas, enclose in quotes, etc...
# If you have no such domains, then replace with an empty set
# of brackets like this:
# BadDomains = []
# BadDomains = ["hotmail.com", "spammer.net"]

BadDomains = [
"register.com",
"bestsourcemedia.cc",
"casino.com",
"etransmail2.com",
"e-fishionado.com",
"BestSourceMedia.cc"]

import sys
import rfc822
import string

headers=rfc822.Message(sys.stdin, 0)
name, email = headers.getaddr("From")
userID, domain = tuple(string.split(email, '@'))
if email in BadFromList:
sys.exit(0)
elif domain in BadDomains:
sys.exit(0)
else:
sys.exit(1)


If you need more help, shoot me an email and I will have a look under the hood. What those files do, is pick out emails on both lists, and shoot them into a black hole email box Terra helped me create.

Mont

=====thanks again to Sheila for those files, I really like not getting so much spam, and the ability to filter entire domains is simply wonderful.

sheila
10-09-2001, 03:20 PM
Greengrouper:

I tested your stuff out a bit today. The python script is fine. I ran it on my home computer and put in some debugging statements and it works exactly as it should. (A style point: personally, I would indent those sys.exit() calls under the if: and else: statments four spaces instead of just one. However, you indentation is consistent, and it still runs.)

There is something about the bouncesaying command that isn't quite right, and I don't know what it is. I tried, a few weeks/month back, to try to implement on one of my email addresses, automatic rejection of anything that didn't have the email address in the To or CC fields. I followed exactly the examples in the man pages on FutureQuest for the iftocc and the bouncesaying commands, but it wouldn't work.

I suspect there is a bug in the bouncesaying command. I also tested your script and your .qmail file on my FutureQuest account. It will send mail through. But when a mail matches the rejection condition, it doesn't reject it. It STILL comes through. Beats me why, because your files are following the documentation exactly.

If any FutureQuest email gurus want to lend a clue, I'd sure be interested. I suppose you might try the condredirect command instead of the bouncesaying command, and see if you get more satisfaction with that?

greengrouper
10-09-2001, 03:25 PM
I actually switched to trying the bounceback after having the same problem getting condredirect to work. Something must be different about the settings on the RASMUS server maybe?

sheila
10-09-2001, 03:31 PM
Well, I'm on NINE, so that theory doesn't wash.

I'm using bouncesaying successfully on two email addresses that I don't want to receive any mail, regardless of who it is from. The .qmail file on those accounts is simply:


|bouncesaying "Rejection message"

And this works. But this is the only way I've been able to get the bouncesaying command to work as advertised in the documentation.

On the other hand, I've used the condredirect quite successfully in a number of cases.

I still think something is wrong with the bouncesaying command in the Qmail installation here at FutureQuest. At least, on NINE. When I was trying to get those non-To/CC emails to auto-bounce about a month ago or so, I didn't feel like I had the time to contact FutureQuest support over it and see why it wasn't working as advertised. But, I'm quite interested to follow it up at this point. The number of spams those accounts are getting it beginning to drive me batty, and any BCC messages are not welcome at those addys.

Greengrouper: What did your .qmail file look like when you used condredirect ?

greengrouper
10-09-2001, 03:40 PM
|condredirect alt@greengrouper.com /usr/bin/env python /big/dom/xcuthilleddy/redir.py
|vdeliver

and I also tried replacing |vdeliver with |/usr/bin/vdeliver

sheila
10-09-2001, 03:45 PM
Originally posted by greengrouper:
|condredirect alt@greengrouper.com /usr/bin/env python /big/dom/xcuthilleddy/redir.py
|vdeliver

and I also tried replacing |vdeliver with |/usr/bin/vdeliver

OK, the theory with the condredirect is a bit different than with bouncesaying.

Is alt@greengrouper.com a good address where you collect mail that you WANT to read? Or is it a bad address, where you want to ditch everything that goes there?

Did you use the exact same redir.py script as you have shown at the beginning of this thread?

greengrouper
10-09-2001, 03:59 PM
alt@greengrouper.com is an address I set up to see if this is working.

sheila
10-09-2001, 04:08 PM
Originally posted by greengrouper:
alt@greengrouper.com is an address I set up to see if this is working.
Fine. But does it represent a good address (email that you want to receive), or a bad address (email that you don't want to receive).

The concept with condredirect, is this:
Suppose email is sent to addy1@yourdomain.com

Under certain conditions, you want the mail sent to addy2@yourdomain.com

If you use condredirect, and the script you are running gives an exit code of 0 (zero), then it will send to the address you specify for addy2@yourdomain.com, if your .qmail file looks like this:


|condredirect addy2@yourdomain.com somescriptyoucallhere.ext
|vdeliver


On the other hand, if the script does not exit 0, suppose it exits 1, then it will not send the mail to addy2@yourdomain.com. Instead it will go to the next line in the .qmail file, the vdeliver command, and deliver it to the original recipient, addy1@yourdomain.com.

More documentation on condredirect here:
http://www.qmail.org/man/man1/condredirect.html

I was just trying to figure out what type of behavior you are expecting from the set up you've shown, before I go messing around with it. (It wasn't clear to me, from the .qmail file you showed.)