Subject: Re: Formail - Whole messages

From: [email-masked] (Stephen R. van den Berg)
Date: Tue, 25 May 1993 14:15:50 +0200

Leo Gestetner <[email-masked]> wrote:
>I've been reading the man page for formail, and I can't seem to
>find a way to pick a whole message out of a file.
>What I need formail to do is to pick a message out of a file,
>then to return the date on the message, also, I need formail
>to be able to delete the message, if told to.

Extracting a message from a file is possible with formail if you
know how many messages precede it.  The following statement will
skip the first five messages, and extract the Date: field from the sixth
message, feeding it to "cat":

	formail +5 -1 -xDate: -s cat <mbox

What you probably want however, (I think) is something that scans through
a whole mailbox in order to make decisions based upon the age of the messages.
In that case I'd suggest something like:

---------cut here----
#! /bin/sh

umask 077
lockfile mbox.lock
formail -s agetest <mbox >mbox.new
mv mbox.new mbox
rm -f mbox.lock
---------cut here----

Whereas "agetest" is a shell script like:
-----------cut here----------
#! /bin/sh

TMPF=/tmp/age.$$

trap "/bin/rm -f $TMPF; exit 1" 1 2 3 15

DATE=`tee $TMPF | formail -xDate:`

delete=no

case "$DATE" in
  *1992*) delete=yes;;
  *Mon*)  delete=yes;;
  *whatever*) delete=yes;;
esac

test delete = no && cat $TMPF

/bin/rm -f $TMPF
-----------cut here----------

I'm confident you'll be able to mold this to taste :-).

-- 
Sincerely,                                  [email-masked]
           Stephen R. van den Berg (AKA BuGless).    [email-masked]

This sentance contains threee errors.