Matthew Saroff asked,
| Does anyone out there have a variant of this that might keep the
| last N messages in a mail folder as opposed to separate files?
[Others have addressed Matthew's further explanation that he wants a single
folder so that Pine can read it by discussing how to make Pine treat a
directory (where each message is a separate file) as a folder. I'm going to
sidestep that approach and respond to the question out of context.]
We did discuss this once upon a time, and I wrote (with input from Stephen
and from some other people) some code for it that ought to be in the list's
archives somewhere.
The most important question first: should new messages be placed at the
beginning or the end of the backup folder? Either way, the code for one is
rather different from the code for the other, so you need to make a choice.
I'll rewrite these from scratch, so these may be buggy:
# to append new messages at end of backup folder
BACKUP=backupfolder # fill in name you like
LOCKFILE=backup.lock # regional lockfile needed
:0c # append new message; regional lockfile is in effect
$BACKUP
MAXBKP=32 # fill in number here if not 32
:0i # Count messages in there now that this one has been saved.
XSTREAM=| formail -I'From x' -zx'From ' -s < $BACKUP
:0 # If there are too many, lop the excess off the top.
* 1^1 XSTREAM ?? x
* $ -$MAXBKP^0
{
EXCESS = $=
TEMPBKP=/tmp/backup.$LOGNAME # or wherever you should put temp storage
OLDSHELL=$SHELL
SHELL=/bin/sh
:0wi
dummyvar=| if formail +${EXCESS}s < $BACKUP > $TEMPBKP ; \
then mv $TEMPBKP $BACKUP ; \
else rm -f $TEMPBKP ; \
fi
SHELL=$OLDSHELL
}
LOCKFILE
# to prepend new messages at top of backup folder
BACKUP=backupfolder # fill in name you like
LOCKFILE=backup.lock # regional lockfile needed
MAXBKP=32 # fill in number here if not 32
:0i # Count messages in there now before this new one is saved.
XSTREAM=| formail -I'From x' -zx'From ' -s < $BACKUP
:0 # If there will be too many after this one, lop the excess off the end.
* 1^1 XSTREAM ?? x
* $ -$MAXBKP^0
* 1^0
{
TEMPBKP=/tmp/backup.$LOGNAME # or wherever you should put temp storage
OLDSHELL=$SHELL
SHELL=/bin/sh
:0wc
| if cat - $BACKUP | formail -${MAXBKP}s > $TEMPBKP ; \
then mv $TEMPBKP $BACKUP ; \
else rm -f $TEMPBKP ; \
fi
SHELL=$OLDSHELL
}
LOCKFILE