[comp.mail.mh] Here's a way to expire old messages

day@grand.UUCP (Dave Yost) (02/03/88)

I've been using mh since the beginning.
Here are some tips from an old hand.
Early on, Jim Guyton at Rand added this
refinement to the use of mh (with csh):
     alias rmm refile +deleted
and to exponge deleted mail, this:
     set mh=~/Mail
     alias mexp 'cd $mh/deleted; rm *'

More recently, I have instituted automatic
exponging of my deleted messages.  Every
night, +deleted messages not accessed in the
last 10 days are deleted, and the +deleted
folder is packed.  Here is the shell script
that is run every night out of cron (I
control my own /usr/lib/crontab):

======
#!/bin/sh
# exponge from +deleted all messages not accessed in 10 days
# This goes in /usr/lib/crontab
# 30 5 * * * su day -c 'sh /u/day/lib/cron.sh' > /u/day/lib/cron.out 2>&1

/bin/date
PATH=/u/day/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin:/etc:/usr/etc
export PATH
USER=day
export USER
HOME=/u/day
cd $HOME/Mail/deleted
x=`find . -type f -name '[123456789]*' -atime +10 -print`
echo "+rm -f $x"
      rm -f $x
echo "+folder -push +deleted"
      folder -push +deleted
echo "+folder -pack"
      folder -pack
echo "+folder -pop"
      folder -pop
======

This has made mh life a whole lot easier
for me.  I hope others enjoy it.

 --dave yost

bd@HPLABS.HP.COM (bob desinger) (02/04/88)

> echo "+rm -f $x"
>       rm -f $x
> echo "+folder -push +deleted"
>       folder -push +deleted
> echo "+folder -pack"
>       folder -pack
> echo "+folder -pop"
>       folder -pop

This is pretty good, and it lets the system do the hard part of
deciding (intelligently) which messages to prune out.

You can also replace the echo lines with one line of `set -x':

	set -x
	rm -f $x
	folder -push +deleted
	folder -pack
	folder -pop

...to get the same effect (well, nearly the same effect; you'll have a
space between the first "+" and your command with the new way but
not with your original.)  You may also wish to add some `&&' tokens
on two lines:

	set -x
	rm -f $x
	folder -push +deleted &&
	folder -pack &&
	folder -pop

The double ampersand means "if this command succeeds, do the next one;
if this fails, skip the other commands."  (Newlines need not be quoted
after the &&.)  With the old way, if the `folder -push' failed, you'd
pack the current folder; with the new way, the packing will occur only
if you successfully pushed +deleted onto the stack.  If the push
fails, neither the pack nor the pop will happen.  It's a small thing,
though, especially because the erroneous action is not very destructive.

bob desinger

day@UUNET.UU.NET (02/04/88)

Thanks for the tip on the &&s.
I routinely do the echoes instead of
set -x because the latter doesn't show
redirection.

 --dave

jerryp@AMAX.NPAC.SYR.EDU (Jerry Peek) (02/04/88)

> I routinely do the echoes instead of
> set -x because the latter doesn't show
> redirection.

But "set -v" *does* show redirection... at least on our BSD-like Bourne shell.
Have you tried it?

--Jerry Peek
  Northeast Parallel Architectures Center; Syracuse, NY
  jerryp@amax.npac.syr.edu
  (315)423-1722

kevinc@bearcat.lim.tek.COM (Kevin Cosgrove 627-5212) (02/05/88)

Dave Yost's neat trick for expiring old messages through an 'rmm'
alias and compainion script reminded me of a trick I use myself.

I use draft folders, but in doing so I loose the outgoing drafts
each time I send another.  E.g.:  +drafts/1 becomes +drafts/,1 and
the next +drafts/1 overwrites +drafts/,1.  From time to time people
request that I resend a message for some reason.  I've been keeping
an +outbox for just this situation.  My "components" include "Fcc: outbox"
which will place a folder copy there.  In order to keep my +outbox
from filling up forever I added a "search and destroy" line to my ~/.logout
file to clean out old outgoing messages.  Below is the command to
do this.

===========================================================
#! /bin/csh

# remove old outgoing message files, compact outgoing and incoming mail dir's
#
find ~/Mail/outbox -name "[0-9]*" -mtime +5 -exec /bin/rm {} \; |& mail kevinc &
===========================================================

Have fun!
_____________________________________________________________________________

	Kevin Cosgrove           	Tektronix, Inc.
	11K Plug-Ins Project Leader	PO Box 500, M/S 47-092
	LIM Product Test Engineering 	Beaverton, OR  97077
	kevinc@bearcat.LIM.TEK.COM	(503)-627-5212
_____________________________________________________________________________

bd@HPLABS.HP.COM (bob desinger) (02/05/88)

> But "set -v" *does* show redirection... at least on our BSD-like Bourne shell

mrose@gonzo.twg.COM (Marshall Rose) (02/05/88)

What I do in my .logout is call

	packit >& /dev/null &

which is a shell script which puts everything in a file called OUTGOING
in my MH directory.  Once a month I move this into my mail archives directory.

/mtr

#! /bin/sh
: packit used to be called "packf", but "pack" got changed to that
: PATH=:/bin:/usr/bin:/usr/ucb:/usr/uci:/usr/uci/lib/mh; export PATH
F="" M="" N=F

for A in $*
do
    case $A in
	-nov*)	N=F ;;

	-v*)	N=T ;;

	-*)	echo "packit: $A unknown" 1>&2
		exit 1 ;;

	+*|@*)  case $F in
		    "")  F=$A ;;
		    *)	 echo "packit: only one folder at a time" 1>&2
			 exit 1 ;;
		esac ;;

	*)	M="$M $A" ;;
    esac
done

case $F in
    "")  F=+outbox ;;
esac
case $M in
    "")  M=all ;;
esac

prf=/tmp/prf$$ ctx=/tmp/ctx$$
trap "rm -f $prf $ctx" 0 1 2 3 13 15

rm -f $prf
echo "MH-Sequences:" > $prf
cat ${MH-$HOME/.mh_profile} >> $prf
MH="$prf" ; export MH

rm -f $ctx
cp ${MHCONTEXT-`mhpath +`/context} $ctx
MHCONTEXT="$ctx" ; export MHCONTEXT

if mhpath $F all > /dev/null;
    then
	P=`mhpath +`/OUTGOING
	C="packf -file $P $F $M"
	case $N in
	    T)  echo $C ;;
	esac
	if $C;
	then
	    C="rmm $F $M"
	    case $N in
		T)  echo $C ;;
	    esac
	    if $C;
	    then
		exit 0;
	    else
		exit 1;
	    fi
	else
	    exit 1;
	fi
    else
	exit 1;
fi

exit 0

bd@HPLABS.HP.COM (bob desinger) (02/11/88)

(Greg Fowler pointed out that my message got rather severely truncated
along the way.  I think my original reply may have been truncated on
my machine; we ran out of filespace in /usr/spool one night, around
the time I sent this message.  But on with the show.)  Jerry Peek's
original comment went something like this:

> But "set -v" *does* show redirection... at least on our BSD-like
> Bourne shell.

My reply went on for a few screens showing the differences between
"set -x" and "set -v".  Here's the condensed version.

Our Bourne shell on System V (HP-UX) does exactly what Jerry's does,
so -v is the right flag to use here.  Use -x when you're debugging and
you want to see which lines are actually being executed.  Use -v when
you'd rather see the whole script, including redirection.  The -x flag
prints each line as it executes, omits lines that aren't executed
because a condition is false, and never mentions any redirection.
The -v flag prints the whole script as it's being parsed, including
lines that won't be executed, and shows redirection.

To be more concrete, the script:

	if true
	then	echo It was true on `date` >>results
	else	echo It was false, yow!    >>results
	fi

prints when executed with `sh -x':

	+ true 
	+ date 
	+ echo It was true on Wed Feb 10 11:58:48 PST 1988 

Notice no redirection, but trace lines showing which lines
were executed (the file "results" contains what you'd expect).
Using `sh -v' produces:

	if true
	then	echo It was true on `date` >>results
	else	echo It was false, yow!    >>results
	fi

This is probably closer to the output that Dave would like to see
in his notification, so I agree with Jerry:  use -v instead of -x.

-- bd

kolding@ji.Berkeley.EDU (Eric Koldinger) (02/18/88)

I use the following shell and sed scripts to archive my old mail.  It takes
everything in all my folders and compacts them into msgbox files in the
same folder that they came from.  It will automatically take any file older
than 5 days (or other number of days if you specify it on the command line)
and saves them away for posterity.  sed runs on the files to remove most of
the unecessary sendmail header lines.  Note, this keeps the messages around
as ,X (or actually #X on our systems).  You need to clean these out, but this
can easily be done with a shell script, or added to this one, if your system
doesn't delete them automatically.

-- archive shell script ---

#! /bin/csh -f
# Archive old messages in 'msgbox' file
# Purge any messages older than $days and save them in the $msgfile file
# create a $msgfile if necessary
# format:
#   archive [n]
#      n - age of messages to purge after {default 5}
#
# errors variable is useful for debugging

# Define default variables
set msgfile=msgbox
set errors=/dev/null
set days=5

if ($#argv != 0) then
    set days=$1
endif

folders -push +inbox > $errors

foreach i (`folders -fast`)
    # set the prefix and uncompress the file 
    set prefix=`mhpath +$i`
    if { pick +$i -before -$days -sequence archive >>& $errors } then
	if (-e $prefix/$msgfile.Z) then
	    uncompress $prefix/$msgfile.Z
	    set recompress='y'
	else
	    if (-e $prefix/$msgfile) then
		set recompress='n'
	    else
		touch $prefix/$msgfile
		set recompress='y'
	    endif
	endif

	# select and pack the messages 

	packf +$i archive -file $prefix/$msgfile >>& $errors
	rmm +$i archive >>& $errors
	sortm +$i >>& $errors

	sed -f ~/bin/strip.sed < $prefix/$msgfile > /tmp/archive$$
	mv -f /tmp/archive$$ $prefix/$msgfile

	# recompress the message file

	if ($recompress == 'y') then
	    compress $prefix/$msgfile
	endif
    endif
end

folders -pop >> $errors

--- strip.sed sed commands ---

/^Received:/d
/^	id /d
/^Message-Id:/d
		_   /|				Eric
		\`o_O'				kolding@ji.berkeley.edu
  		  ( )     "Gag Ack Barf"	{....}!ucbvax!ji!kolding
   	    	   U