[comp.mail.mh] unrmm command

leres@ace.ee.lbl.gov (Craig Leres) (06/24/88)

On occasion, I rmm a message and then change my mind. I just wrote the
following script which allows you to safely un-rmm a message (without
having to root around in the folder directory). It's kinda like inc in
that the message reappears as the last message in the folder.

		Craig

#!/bin/csh -f
set new=`mhpath new`
if ($#argv > 0) then
    set old=`echo $new//\#$1 | sed -e 's,/[0-9][0-9]*//,/,'`
    if ( ! -r $old ) then
	    echo "unrmm: message $1 doesn't exist"
	    exit 1
    endif
else
    set old=`mhpath .`
    if ( ! -r $old ) then
	    echo "unrmm: no cur message"
	    exit 1
    endif
endif
mv -i $old $new
if ($status == 0) scan last

matt@ODDJOB.UCHICAGO.EDU (Matt Crawford) (06/24/88)

Here's my unrmm.  It's more limited in that it only undeletes
the "current" message.
================
#!/bin/sh
d=`mhpath`
n=`egrep '^cur:' $d/.mh_sequences | awk '{print $2}'`
echo $n
mv -i $d/\#$n $d/$n
================

And here's a little off-the-cuff mod of Craig's unrmm, using a csh
feature and adding the possibility of multiple messages:
================
#!/bin/csh -f
if ($#argv == 0) set argv=(`mhpath cur`)
set num=0 stat=0
while ($#argv)
    set new=`mhpath new`
    set old=$new:h/\#$1
    if ( ! -r $old ) then
	    echo "unrmm: deleted message $1 doesn't exist"
	    set stat=1
    else
	mv $old $new
	@ num++
    endif
   shift
end
if ( $num ) scan last:$num
exit $stat
================
________________________________________________________
Matt Crawford	     		matt@oddjob.uchicago.edu

bd@HPLABS.HP.COM (bob desinger) (06/24/88)

Here's yet another unrmm that I wrote while waiting for the csh
versions to finish.  (Well, okay, it's been written for a couple of
years now, but the opportunity to bash csh was too good to pass up.)

This one tries to preserve the message's original message number,
making a new message only if the slot has been filled.  You can also
give it a +folder argument to unrmm a message in another folder.
Finally, the resurrected message doesn't need to be the current one.
(I usually decide the next day that I shouldn't have nuked a
particular message---the message to unremove is never my current one.)

By the way, MTR hates all these unrmm solutions because they don't put
back the context, restore the message-sequences, comb your hair, and
stop world hunger.  Oh well.

#! /bin/sh
# This is a shell archive.  Remove anything before this line,
# then unwrap it by saving it in a file and typing "sh file".
#
# Wrapped by bd at hpsemc on Fri Jun 24 09:01:01 1988
# Contents:
#	unrmm 	

PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:$PATH; export PATH
echo 'At the end, you should see the message "End of shell archive."'

echo Extracting unrmm
cat >unrmm <<'@//E*O*F unrmm//'
#! /bin/sh
: unrmm - resurrect a dead mh message, handling optional +folder

if [ $# = 0 -o "$1" = "-help" ]
then
	echo 2>&1 "Usage:  `basename $0` [+folder] message ..."
	exit 1
fi

fpath=`mhpath`
while [ -n "$1" ]
do
	# Handle +folder arguments, if given.
	case "$1" in
	+*)	# +folder argument specified
		folder $1 >/dev/null && fpath=`mhpath`
		shift
		;;
	esac

	if [ ! -f $fpath/\#$1 ]
	then	# rmm'd file doesn't exist
		folder=`mhpath`
		echo 2>&1 `basename $0`: \
			"sorry, +`basename $folder`:#$1 isn't there."
	else
		if [ ! -f $fpath/$1 ]
		then	# original message slot not filled in yet
			mv $fpath/\#$1 $fpath/$1
			scan $1
		else	# original message slot was filled
			newname=`mhpath $folder new`
			echo 1>&2 `basename $0`: 'original slot is filled;' \
				resurrecting $1 as message `basename $newname`.
			mv $fpath/\#$1 $newname
			scan `basename $newname`
		fi
	fi
	shift
done
@//E*O*F unrmm//

set `wc -lwc <unrmm`
if test $1 -ne 40 -o $2 -ne 143 -o $3 -ne 898
then	echo ! unrmm should have 40 lines, 143 words, and 898 characters
	echo ! but has $1 lines, $2 words, and $3 characters
fi
chmod 755 unrmm

echo "End of shell archive."
exit 0

mesard@bbn.com (Wayne Mesard) (06/25/88)

From article <8806241416.AA04206@oddjob.uchicago.edu>, by matt@ODDJOB.UCHICAGO.EDU (Matt Crawford):
> And here's a little off-the-cuff mod of Craig's unrmm, using a csh
> feature and adding the possibility of multiple messages:
[script deleted]

Not to be outdone, here's my unrmm.  I guess this is the Cadillac
version.  It handles multiple messages, folder context changes and
relative message number specification.  So if the current message in
folder +foo is 28, the following command will undelete the 28, 26 and
29:

unrmm +foo cur -2 -+1

It tries to use the same message number, but if a new message has
already been put in it's place, it refiles it as the last message in the
folder.

(It ain't pretty on the outside, but you should see all the dials on the
dashboard, and oh! that plush interior :-)

-- 
unsigned *Wayne_Mesard();        MESARD@BBN.COM        BBN Labs, Cambridge, MA

Is it because of the people you hang around with that you say you do not
need dan rather?
			M-x psychoanalyze-pinhead
(Gee, whataneditor!!)

=============================snip===============================
#!/bin/csh -fe

set msgs
while ( X$1 != X )
	switch ($1)
		case -help:
			echo "syntax: `basename $0` [+folder] [special-msgs] [switches]"
			echo "  switches are:"
			echo "  -[no]changecur"
			echo "  -(help)"
			echo ""
			exit 0
		case -nochangecur:
			echo match
			set newcur
			breaksw
		case -changecur:
			unset newcur
			breaksw
		case +*:
			set mfolder = $1
			breaksw
		default:
			set msgs = "$msgs $1"
			breaksw
		endsw
	shift
end
exit
if ($?mfolder == '0') then
	set mfolder = +`folder -fast`
endif

cd `mhpath $mfolder`

set temp = `mhpath cur`
set curnum = $temp:t

if ("$msgs" == "") set msgs = $curnum

foreach msgnum ( $msgs )
	switch ($msgnum)
		case cur:
			set msgnum = $curnum
			breaksw
		case -+*:
			@ msgnum = $curnum + `expr $msgnum : '.\(.*\)'`
			breaksw
		case -*:
			@ msgnum = $curnum + $msgnum
			breaksw
		case [0-9]*:
			breaksw
		default:
			set msgnum = `pick $msgnum`
			breaksw
		endsw

	if (-e ",$msgnum") then
		if (-e "$msgnum") then
			echo Refiling ",$msgnum" as last message.
			echo refile $mfolder -file ",$msgnum"
			refile $mfolder -file ",$msgnum"
			if ( $?newcur == 0 )
				set newcur = `pick last`
		else
			echo Undeleting $msgnum.
			echo mv ",$msgnum" "$msgnum"
			mv ",$msgnum" "$msgnum"
			if ( $?newcur == 0 )
				set newcur = "$msgnum"
		endif
	else
		echo \"$mfolder/,$msgnum\": no such deleted message file.
	endif
end

## Change context to first message restored. ##
if ( $?newcur == 0)
	set newcur
folder $mfolder $newcur >/dev/null

-- 
unsigned *Wayne_Mesard();        MESARD@BBN.COM        BBN Labs, Cambridge, MA

Is it because of the people you hang around with that you say you do not
need dan rather?
			M-x psychoanalyze-pinhead
(Gee, whataneditor!!)

jerryp@CMX.NPAC.SYR.EDU (Jerry Peek) (06/26/88)

I tend to "inc" a lot of single messages, handle them, them run "rmm"
right away.  So, lots of my messages overwrite each other (for example,
I "inc" message 123 -- then remove it, which makes it ",123" -- then soon
"inc" another message 123 -- then remove it, which blows away the previous
removed message ",123" -- and so on).

To fix this, I changed my "rmmproc:" to use a program I wrote called "temp".
Before it adds a comma to a filename, "temp" checks to see if the destination
file already exists.  If so, it adds enough commas to make a unique filename.
So, I end up with removed messages named ",123", ",,123", ",,,123", etc.
I also wrote an "unrmm" that checks to see if there's more than one removed
message with the same message number; if so, it shows you each message with
that number and asks if you want to restore that one; otherwise, it just
restores the single message.

If anyone wants copies of these, send me mail (personal -- no sense mailing to
the whole list, is there?) and I'll put together a shar file.

--Jerry Peek, Northeast Parallel Architectures Center, Syracuse, NY
  jerryp@cmx.npac.syr.edu
  +1 315 443-1722

davy@INTREPID.ECN.PURDUE.EDU (Dave Curry) (06/27/88)

     From:  Jerry Peek <jerryp%cmx.npac.syr.edu@ICS.UCI.EDU>
     Date:  Sun, 26 Jun 88 08:03:42 EDT
     Subject:  Re: unrmm command 

     I tend to "inc" a lot of single messages, handle them, them run "rmm"
     right away.  So, lots of my messages overwrite each other (for example,
     I "inc" message 123 -- then remove it, which makes it ",123" -- then soon
     "inc" another message 123 -- then remove it, which blows away the previous
     removed message ",123" -- and so on).

Me, too.

     To fix this, I changed my "rmmproc:" to use a program I wrote called "temp".
     Before it adds a comma to a filename, "temp" checks to see if the destination
     file already exists.  If so, it adds enough commas to make a unique filename.
     So, I end up with removed messages named ",123", ",,123", ",,,123", etc.
     I also wrote an "unrmm" that checks to see if there's more than one removed
     message with the same message number; if so, it shows you each message with
     that number and asks if you want to restore that one; otherwise, it just
     restores the single message.

All these "unrmm" scripts seem like a lot of overkill to me.  I just
followed the MH doc's suggestion and did an

	alias rmm	refile +deadbox

And then I have a shell script which I start up with "cron" each night (you
could use "at" if you don't have a Sun whose crontab is essentially only
for you).  The shell script uses "pick" and zaps all messages in deadbox
that are over three days old.  (The script also cleans up my folder of
outgoing mail, and some digest folders, but that's not important right
now.)

There's no need for an "unrmm" script; I just have everything in a folder
and can use "pick", "scan", and all that good stuff to manipulate my deleted
messages.

--Dave Curry

cosell@WILMA.BBN.COM (Bernie Cosell) (06/27/88)

I know that this is off this thread, but there is another approach to this
whole problem that I find a lot more pleasant (and have used for years):

I have rmm aliased to be a "refile $@ +junk".  in addition to making
unrmm mostly moot (since it is just a simple refile in the other
direction), it also has the nice effect that you can *scan* the stuff,
so if you did "rmm cur-last" and you suddenly realized that you wanted
to save one message, just "scan +junk" then a "refile <> +inbox" and
you're done.  Even works for replying: when I'm on a roll throwing mail
away, if I miss one an doverzealously rmm it when I want to repl ro
forw it, I can - don't even have to mess around "unrmm"ing it --just
"repl last +junk" works like a charm).  Having your deleted messages
ina proper folder means that you can use all of the usual MH tools and
tricks on them.

The only other hook in this whole mess was that I have a hack in my logout
script that rmf's junk.  But that's no more bletcherous than having to have a
hack that removes "comma" files.

   __
  /  )                              Bernie Cosell
 /--<  _  __  __   o _              BBN Labs, Cambridge, MA 02238
/___/_(<_/ (_/) )_(_(<_             cosell@bbn.com