Subject: Re: elm and procmail backup recipes

From: [email-masked] (David W. Tamkin)
Date: Wed, 12 Apr 1995 11:44:22 -0500 (CDT)

Richard Brankin was considering this:

| I've been using some of the procmail examples amongst my own recipes,
| including the backup idea...
|                           # backup msgs (if not from digests/mailing
|                           # lists since can recover them) in case we mess up
| :0 c:
| * !^FROM_MAILER
| $MAILDIR/backup
|                           # only save the last 32 msgs though
| :0 ic
| | cd $MAILDIR/backup && rm -f dummy `ls -t msg.* | sed -e 1,32d`
| 
| I usually use elm, so would prefer to have backup as a file instead of
| directory in the above recipes. However, I'm only interested in saving
| the last 'n' received messages.  Assume backup already has 'n' messages
| and the 'n+1'-th arrives. Anybody have a better suggestion than the
| following (unimplemented) one to replace the second recipe above? 
| 
| :0 ic
| | (cd $MAILDIR; 
|    lockfile backup.lock;
|    awk '$0 ~ /^From / {++found}; {if (found>=2) print}' <backup >backup.1;
|    mv backup.1 backup;
|    rm -f backup.lock)

Well, I'd just put backup.lock as the name of a local lockfile on the flag
line rather than call both lockfile and rm, and you'll need backslashes for
those continuation lines (though not the outer parentheses).

Would you consider a backup folder that keeps messages in reverse order
(latest first, oldest survivor last)?  Then here's an idea:

:0
* conditions
{
 keep=32 # easier to edit here, Stebbens-style, than below

 :0c: # just in case until we get this worked out ideally
 safekeeping

 LOCKFILE=backup.lock

 :0fw
 | cat - backup | formail -${keep} -s && rm backup

 :0r
 backup
}

Perhaps the last two could be changed to

 :0fw
 | cat - backup | formail -${keep} -s

 :0ar
 | cat > backup

David W. Tamkin  Box 3284  Skokie, Illinois  60076-6284
[email-masked]    MCI Mail: 426-1818   +1 312 714 5610

---

From: Adam Shostack <[email-masked]>
Date: Wed, 12 Apr 1995 14:17:48 -0400 (EDT)

I find that saving the last 3 days worth of messages works
well for me; I use cron and a simple recipie.  Changing the number of
days saved is pretty simple.  One day I might even change it to use
a real for loop.  :)

:0 c:
.safe

cron invokes this just before midnight:

#!/bin/sh
DIR=/usr3/adam/Mail/inbound/
/bin/mv -f ${DIR}/.safe.1  ${DIR}/.safe.2
/bin/mv -f ${DIR}/.safe.0  ${DIR}/.safe.1
/bin/mv -f ${DIR}/.safe    ${DIR}/.safe.0
exit 0

-- 
"It is seldom that liberty of any kind is lost all at once."
						       -Hume