My Procmail Tips

Testing Procmail

You can test procmail in a number of ways. The way I found easiest was just to simply send an email I was testing against to stdin for procmail

$procmail < email

The danger here is that you are running and testing your scripts on a live system, and hence if something is wrong with your recipes, bye-bye messages.

If you want to be really safe though, you add a safety catch recipe, as your first rule:

:0c
/some/backup/dir

Mark Maildir Message as Read

Not actually my own tip. Taken from David W. Tamkin's Post on the Procmail Mailing List.

The only problem is… it doesn't work. At least not for me.

I finally got the code working by messing around a bit with it.

Be careful of the /dev/null. If you don't use this definition exactly right you run the risk of deleting all your incoming messages. I recommend testing your script locally before running it on a valuable system.
DROPPRIVS=yes
:0fw
| /usr/bin/spamassassin
:0
* ^X-Spam-Status: Yes
{
  # where i want the message to go
  foldername=$HOME/Maildir/.zzSpam

  #create a carbon copy of the message and store it
  #as a non-delivery action, this allow the script to
  #continue processing see procmailrc(5)
  :0c
  $foldername/ # stores in $foldername/new/

  #find out the name of the file we just stored the mail as
  :0
  * LASTFOLDER ?? /\/[^/]+$
  { tail=$MATCH }

  #move the mail to the cur (i.e. read) folder and set satus flags
  TRAP="mv $LASTFOLDER $foldername/cur/$tail:2,S"

  #We still have the original message hanging around
  #so delete it.
  #checking again, so that worst case, if i messed up earlier
  #only spam messages will be deleted.
  :0
  * ^X-Spam-Status: Yes
  /dev/null

  HOST
}

projects/linux/my_procmail_tips.txt · Last modified: 2008/05/22 14:29 by martinsgill
Firefox 3 Mandriva Linux National Secular Society Humanism Lib Dems