procmail: Rewriting the Subject

A common problem with posting to newsgroups is that unless you have a very good spam filter, or you use a disposable email address, you will get spam. Guaranteed.

One way to deal with this problem is to use procmail, a “mail processing and SmartList mailing list suite”.

I use the following recipe for filtering all email sent to newsgroup at ellingsworth dot org; that is the address I use to post to newsgroups, from which I NORMALLY do not expect a reply, except maybe from email harvesters/spammers. (Note: I could have inserted the word SPAM into the email address and filtered on that, but since I started using that email address before I started using any spam filters, I decided to stick with it.) It is possible, though, that someone will reply back to me via this email address, to which I might like to respond (newsgroup etiquette aside).

Anway, here is the filter with comments:

#BEGIN FILTER

# VERBOSE tells Procmail to log everything
VERBOSE=on

#SENDMAIL tells where our SENDMAIL app is: whereis sendmail
SENDMAIL=/usr/bin/sendmail

#MAILDIR tells where our mail directory is
MAILDIR=$HOME/mail

#PMDIR: home of our log file
PMDIR=$HOME/.procmail

#LOGFILE: the name of our logfile
LOGFILE=$PMDIR/log

#SUBJECT: our variable with the original subject, for writing the new subject
SUBJECT=`formail -zxSubject:`

#THE HEART OF IT ALL: THE FILTER

## NEWSGROUPSPAM
:0 f
*^(TO|CC).*newsgroup@ellingsworth\.org
| /usr/bin/formail -I “Subject: (SPAM!)$SUBJECT”

#END OF FILTER

That’s it.

If you want to learn how to use Procmail, you can always start with the man pages ( man procmail ).
Not exactly the easiest way to begin, so you can start with this mini-faq by Prof. Timo Salmi.

Also, some folks have started a Procmail documentation project at sourceforge http://pm-doc.sourceforge.net/ – definitely worth checking out if you want to use it more extensively.

Thanks for reading. Share on Google+Tweet about this on TwitterShare on FacebookEmail this to someone