Subject: Re: Killing old messages in a folder

From: Roman Czyborra <[email-masked]>
Date: Tue, 25 Jan 94 12:51:36 GMT

On January 20, Jonathan Bradshaw wrote:

> I know this has been asked before but, since I'm not sure how to get
> the archives of this list I'll ask it and maybe someone can tell me
> where to find the information on the simplest way of doing one of
> two things:

> (a) Putting a limit on a folder so it only keeps the last 100
>     messages that are in it

Duck soup!

	:0 w:folder.lock
	| cat - folder | formail -100 -s > folder+ && mv folder+ folder

The cat - folder operation reverses the message order, though.
If you still use a formail older than v2.92p9 you'd need a cat after
the -s option that is a waste of resources.

> (b) Putting a date limit so old messages are removed from the folder

Comparing dates is a bit more complicated.  There is a tiny tool
called em (expire mail) written by [email-masked].
I could also send you a GAWK script to do it.

Anyway, what you probably want is to keep a limit on the quota of your
folder. The following code fragment requires GNU AWK as it is supposed
to munch the entire folder in one bite:

	:
	> 10000
	/dev/null

	AWK='BEGIN { RS = "\001"; OFS = FS = "\n\nFrom " }
	{
		for (message = 1; message <= NF; ++ message) {
			size += length ($ message)
			if (size > 100000) NF = message - 1
		}
		print
	}'

	:0 w:folder.lock
	| cat - folder | gawk "$AWK" > folder+ && mv folder+ folder

How's that?