Using .procmail to test "To:" field

software development

#1

Hello,

Someone’s been using my domain to send (tons of!) spam, and so far I’ve been creating rule after rule using the DreamHost interface.

It’s getting kinda silly, though, so I want to create a .procmail filter that kills all email not sent to one of these addresses:

charles@mydomain.com
from-@mydomain.com
charles+
@mydomain.com

The “*” in the last two is a wildcard, since I use them for spam tracking. For example, I would give foobar.com an address of charles+foobar.com@mydomain.com. If I ever get spam to charles+foobar.com@mydomain.com, I know where it came from.

I know nothing about .procmail or regular expressions, but I’m happy to have a go. I’m posting this in case someone wouldn’t mind giving the newbie some pointers (beyond the KBase article on .procmail, which I’ve read and kinda understand).

Many thanks for any help!

– Charles Wiltgen


#2

Just for kicks, here’s the (incorrect, I’m sure) first try:

/dev/null
DEFAULT=$HOME/Maildir/
MAILDIR=$HOME/Maildir
PMDIR=$HOME/.procmail
LOGFILE=$PMDIR/log
SHELL=/bin/sh

:0

  • ! ^TO_charles@wiltgen.net|
    ! ^TO_from-(+.)@wiltgen.net|
    ! ^TO_charles+(+.)@wiltgen.net
    /dev/null

#3

Also, is there only one .procmailrc for all of my accounts? Do I then have to set up pass-throughs for those addresses?


#4

You can only setup procmail recipes (beyond what you can do from the panel) on ftp / shell users, and it’s not global - it’s per-account.

Btw, I’d suggest reading the procmailex and procmailrc man pages regarding “TO” and “TO_” - these are special cases in procmail, and can work both for and against you.