More complex filtering

Nesting
Nesting is a relatively new procmail feature that makes your .procmailrc easier to follow and allows for more complex rule processing.

Let's use our previous example of ACM membership mail. Here's what we did before.

# forward a copy of all ACM membership mail to our buddy at the other uni
# then filter it to my acm mailbox

:0c
* ^X-loop: membership@acm.uiuc.edu
!friend@other.uni.edu

# notice that we don't have to specify a condition for the next rule

:0a
acm
This could be rewritten with nesting as
:0
* ^X-loop: membership@acm.uiuc.edu
{
	:0c
	!friend@other.uni.edu

	:0
	acm
}
This does the same thing but is a lot more readable. You can have multiple levels of nesting as well but we won't cover that.
| - piping to programs and spawing programs
I get a lot of mail so I like to keep track of exactly how much. I wrote a small perl script that increments a counter in my home directory every time it's run. I then run the program at the top of my .procmailrc every time I get a piece of mail.

# let's count exactly how many letters go through this account

# we use a new flag this time. "i" means to ignore output errors.
# since we're actually piping each piece of mail through my program I would normally
# get an error since my program doesn't actually take any input. i will keep
# the annoying messages out of my .maillog. It's really a cheap hack.

:0ci
| $HOME/bin/mailcount.pl
If I received mail on my home computer I could have it play a sound when it got ACM membership mail and then save an extra copy before putting it into my inbox.

:0c
* ^X-loop: membership@acm.uiuc.edu
{
	:0ci
	|/usr/local/bin/soundplayer /usr/local/lib/acmrocks.au

	:0
	acm
}
Once you get the hang of it, the possibilities are endless.
Back: Matching on Regular Expressions Top Next: formail

j g r o s s @ s t i m p y . n e t