----------
From: Kirk Job Sluder[SMTP:csluder(_at_)indiana(_dot_)edu]
Just a quick bit of context: I use a copy of procmail on my
personal account (in $HOME/bin) to filter the mail I get from
multiple mailing lists. The bulk of my work mail is dumped by
default into my system mailbox and then transfered usually at the end
of the day to a "received" folder on my account disk space. The mail
I send is also archived in a "sent" folder.
At the end of the month, I would like to filter work-related mail out
of my "received" and "sent" folders. Can I do this using procmail
and if so, how? If somone could take the time to give a line-by-line
explanation of the example given in the man pages that would help.
I use the manpage example to take mail that's already in my incoming
mail spool and run it through my .procmailrc again after I have
reset my forwarding recipes. It works like a charm so far.
I have appended the manpage script below and will interpolate my
comments inside [....] markers
=================================================================
[normal shell magic]
{1} #!/bin/sh
[this is the location of your system spool, change it
to match it's location as reported by procmail -v]
{2} ORGMAIL=/var/spool/mail/$LOGNAME
[if you can cd to your home directory AND]
{3} if cd $HOME &&
[your mail spool exists AND]
{4} test -s $ORGMAIL &&
[you can create a named lock]
{5} lockfile -r0 -l1024 .newmail.lock 2>/dev/null
then
[trap signals from the shell to release the lock]
{6} trap "rm -f .newmail.lock" 1 2 3 13 15
[set the file creation mask]
{7} umask 077
[lock your mail spool]
{7} lockfile -l1024 -ml
[copy your mail spool to a temp file and if sucessful]
{8} cat $ORGMAIL >>.newmail &&
[space out your mailspool]
{9} cat /dev/null >$ORGMAIL
[release the lock on the mail spool]
{10} lockfile -mu
[use formail to "split" the temp file copy of your mail spool
and feed each message to procmail]
{11} formail -s procmail <.newmail &&
[If that was sucessful, delete the temp copy]
{12} rm -f .newmail
[Now blow-off the lock you obtained at the top of this script]
rm -f .newmail.lock
{13} fi
[Return a nice error code]
{14} exit 0
=================================================================
Some notes:
Make sure that the lockfile executions at line {7} and {10} actually
work as intended. Era pointed out to me that it doesn' always work
on all file systems. Try invoking the lockfile -ml at the command
line and then try to fire up your friendly mailer. If you can't look
at your mail, the command worked.
You can specify a different rc file (rather the .procmailrc default)
on line {11}.
I *imagine* you can point $ORGMAIL (line {2}) at virtually any MBOX
style mail "folder." If you're not actually pointing at the mailspool,
I don't "think" the lockfile -ml and lockfile -mu are needed.
All you have to do is save the script from the manpage and then invoke
it
from the command line or via cron.
I hope I've gotten this right. If not, I'm sure somebody will correct
me.
Simeon