procmail
[Top] [All Lists]

Re: keeping only the most recent

2000-06-24 13:04:47
Lee Howard <faxguy(_at_)server(_dot_)deanox(_dot_)com> writes:

I'd like a recipe that overwrites the old mail with the new for each mail
that has the same subject line (different clients' subjects differ slightly).

I do something sort of similar but I want to keep some number of the
most recent for diagnostics if necessary.  A way to do that is
outlined in the man promail* pages  (I forgot which one exactly) But
it is contained in a script to generate backups of your mail.

Mine  works by running a shell script against the accumulated mail. 

First I have procmail write the messages to $MAILDIR/dirname in one file per
message format (mh format) by doing this

# -*-Shell-script-*-
PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
SHELL=/bin/sh
MAILDIR=$HOME/spool
##LOGABSTRACT=NO
##INCLUDERC=procvars
VERBOSE=NO
LOGFILE=$HOME/.procmail.log

 :0 
 * ^Subject:.*$KEYWORD
 dirname/.

Showing a few promailrc vars to give the idea but what does the work
is `dirname/.'  The slash dot causes each message to be given a
numeric name under $MAILDIR/dirname/

Using a keyword in the subject that will uniquely identify these mails
as the ones we are after.

So you end up with ` ls $MAILDIR/dirname/ 1 2 3 4 5 6 7 ...100  each
number is single message.

I do it this way only for making the removal script simple.  So it
doesn't have to scan spool style files.

Now we are accumlating messages in the above setup so we need a way
to get rid of the old ones but keep a specific number of new ones for
possible diagnostics.

I just run this script by hand whenever I think of it but it can be
hooked up to cron of course.

cat /bin/trim-bs
^^^^^8<snip
#!/bin/sh
rm `ls -t /path/to/dirname/[0-9]* | sed -e 1,12d` 2> /dev/null
^^^^^^^8<snip

This simple little script works really well.

It throws up a listing of the directory in chronological order.  Sed
chops off the first 12  of the list so they don't get deleted, this all
means that the most recent twelve remain and all else is deleted
silently.  I always have the 12 most recent this way.

The /dev/null part is for the case when the script is run and there
aren't yet 12 messages.  It complains but only /dev/null listens.

For what I'm doing.. and it is not the same as your usage, 12 has
turned out to be about right, adjust to taste.




_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>