[Gllug] Procmail

Richard Cohen richard at vmlinuz.org
Sat Jul 7 17:20:59 UTC 2001


On Sat, 7 Jul 2001, Martin Stevens wrote:

> On Sat, Jul 07, 2001 at 05:48:59PM +0100, Richard Cohen wrote:
> > On Sat, 7 Jul 2001, Martin Stevens wrote:
> >
> > > Hi,
> > >
> > > I've finally got around to setting up procmail, but I have a stack of
> > > mail in my mbox, can anyone tell me a recipie to retroactively run
> > > procmail on my mbox to sort the mail according to the rules I've
> > > set-up in procmail.
> >
> > >From the procmail man page (try reading before posting?):
>
> I did, and found this as well, however it doesn't look like it will do
> what I want it to, I use mutt and I have about 2000 mails that have been
> moved to /home/budgester/mbox, therefore are no longer in the system
> spool. As for shell scripting I'm still learning and the bit in the script
> below sending stuff to /dev/null scared the willy's out of me.

If you want to work it out yourself, look away now :-)
I've explained the script below.

> Back to ploughing through the reams of docs that is man procmail.

Have you read Nancy McGough's Procmail stuff?  Easier to digest than the man
pages...
http://www.ii.com/internet/robots/procmail/ - particularly
http://www.ii.com/internet/robots/procmail/qs/

> >               #!/bin/sh
This is a shell script.
> >               ORGMAIL=/var/spool/mail/$LOGNAME
The mailbox you want to take mail from.
> >               if cd $HOME &&
Can we enter your home directory...
> >                test -s $ORGMAIL &&
And is the mailbox a non-empty file...
> >                lockfile -r0 -l1024 .newmail.lock 2>/dev/null
And can we lock a temporary mailbox file?
> >               then
> >                 trap "rm -f .newmail.lock" 1 2 3 13 15
If we die, unlock the copy of the mailbox.
> >                 umask 077
Make sure that files we create aren't accessible by anyone but us.
> >                 lockfile -l1024 -ml
Lock the mailbox.
> >                 cat $ORGMAIL >>.newmail &&
Copy the original mailbox to .newmail ...
> >                  cat /dev/null >$ORGMAIL
And blank out the original mailbox if we succeeded in copying it.
> >                 lockfile -mu
Unlock the mailbox.
> >                 formail -s procmail <.newmail &&
Process the copy of the mailbox - split it into individual mails and run
each one through procmail.
> >                  rm -f .newmail
Delete the copy of the mailbox.
> >                 rm -f .newmail.lock
Delete the lock on the temporary file.
> >               fi
> >               exit 0
fin
> > Adapt to your own circumstances...
>
> I'm gonna try and understand what this script actually does before I run it.

Hope this helps - if you read this far :-)

Cheers
Richard



-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list