The FreeBSD Diary

The FreeBSD Diary (TM) Remember
I remember
[ HOME | TOPICS | INDEX | WEB RESOURCES | BOOKS | CONTRIBUTE | SEARCH | FEEDBACK | FAQ | FORUMS ]

Things look quiet here. But I've been doing a lot of blogging at dan.langille.org because I prefer WordPress now. Not all my posts there are FreeBSD related. I am in the midst of migrating The FreeBSD Diary over to WordPress (and you can read about that here). Once the migration is completed, I'll move the FreeBSD posts into the new FreeBSD Diary website.

procmail - a simple example 8 December 2000
Need more help on this topic? Click here
This article has no comments
Show me similar articles
procmail is a tool for manipulating mail.  If you like to sort your incoming mail into various folders/directories, procmail can do that for you.  If you want to cut down on the spam, procmail can help with that.   Basically, if you can write a rule for it, procmail can do it.

I wanted to sort incoming mail for a list archive box.  Mail for one list had to go to one mailbox and from another list for another mailbox.  This seemed pretty easy to do with procmail.

The home page for procmail is http://www.procmail.org/.

Here's a link to procmail in FreshPorts.

And I used some of this FAQ.   But Timo's procmail tips and recipes was very useful once I started creating my procmail rules.

Installation
The first step was to install procmail from the ports.  I followed the instructions found in the FreeBSD handbook for compiling ports from the internet.
cd /usr/ports/mail/procmail
make install

Don't do a make clean until after you grab the examples during the configuration later in this article

Introducing .forward
I'll give you a very simple example.  procmail is often invoked from your .forward file.  .forward resides within your home directory.  It is used by sendmail, and other mail transport agents (MTAs).  .forward, if it exists, is used each time a new message is delivered to that user.  The conventional use of .forward is for redirecting mail.  See man forward for more information.

procmail makes use of .forward to process your mail according to the rules you specify within .procmailrc.

Here is what I put in ~/.forward:

[dan@set:/home/dan] # more .forward 
"|exec /usr/local/bin/procmail || exit 75"

The above is taken from man procmail, in the NOTES section.  Be sure to include the quotes.

procmail rules
Here is the example rule set I'm using.  This example was taken from
/usr/ports/mail/procmail/work/procmail-3.15/examples/1procmailrc

Your procmail version may vary so the above directory may differ on your box.

[root@set:/home/dan] # more .procmailrc
# Please check if all the paths in PATH are reachable, 
# remove the ones that are not.

PATH=$HOME/bin:/usr/bin:/usr/ucb:/bin:/usr/local/bin:.
MAILDIR=$HOME/mail      # You'd better make sure it exists
DEFAULT=$MAILDIR/mbox
LOGFILE=$MAILDIR/from
LOCKFILE=$HOME/.lockmail

:0                    # Anything from Henry
* ^From.*henry
henries               # will go to $MAILDIR/henries
:0                    # anything from cvs-all mailing list
* ^Sender.*owner-cvs-all@FreeBSD.ORG
lists/cvs-all         # will go into my archive

# Anything that has not been delivered by now will go to $DEFAULT
# using LOCKFILE=$DEFAULT$LOCKEXT

Be sure to create the mail directory indicated above:

mkdir ~/mail

That should be about it.  Try it and see.

Testing
Sometimes it can be difficult to test your procmail rules.  You can't always wait for a mail message which meets your test conditions.  Fortunately, there is another way.  Take a message, including the headers, and copy it to a file.   Then pipe the contents of that file to procmail.  I found the testbench as described at Timo's procmail tips and recipes very helpful.
Clean up
Remember to do a make clean!
Recipes 31 December 2000
Gill wrote in with this recipe for mailing lists.  It was actually written by Neil Blakey-Milner.

I am sure you will get hounded with people suggesting thier own procmailscripts, but this one came to me by way of the -questions list and it is the niftiest one i've ever seen and it works perfectly. It is useful for
all of the FreeBSD lists:

# From: Neil Blakey-Milner
# Cc: freebsd-questions@freebsd.org
# Subject: Re: Procmail recipes for fbsd lists

# I use:

:0
* ^Sender:.owner-freebsd-\/[^@]+@FreeBSD.ORG
{
LISTNAME=${MATCH}
:0
* LISTNAME??^\/[^@]+
freebsd-${MATCH}
}

# It can probably be simplified, but it expands as necessary when I
# join new lists, &c.

Chad Ziccardi wrote in with these two URLS:

http://www.ii.com/internet/robots/procmail/qs/
http://www.ii.com/internet/robots/procmail/


Share
Need more help on this topic? Click here
This article has no comments
Show me similar articles