The rmmer Shell Script

[return-to Explanation of rmmer] [table of contents] [index]
#! /bin/sh
# $Id: rmmer,v 4.6 1994/06/23 02:43:29 jerry book3 $
### rmmer, rmmer.noask, rmmer_1, rmmer_1.noask - MH "rmmproc" SCRIPT
### rmmer AND rmmer.noask MOVE MAIL TO @DELETE FOR find TO CLEAN UP
### rmmer_1 AND rmmer_1.noask MOVE MAIL TO +DELETE FOR find TO CLEAN UP
### xmh USERS SHOULD USE A ".noask" VERSION.
##
##  rmmer IS DESIGNED TO BE USED WITH THE MH MAIL rmm COMMAND.
##  INSTEAD OF JUST ADDING A COMMA (,) TO THE MESSAGE NAME, LIKE
##  STANDARD rmm DOES, rmmer MOVES THE MESSAGE INTO A SUB-FOLDER
##  NAMED "DELETE".  A SYSTEM PROGRAM SHOULD CLEAN OUT THAT FOLDER
##  EVERY SO OFTEN (YOU MAY HAVE TO SET THAT UP, TOO).  MESSAGES IN A
##  "DELETE" SUB-FOLDER ARE EASY TO RECOVER IF YOU rmm'ED ACCIDENTALLY.
##
##  FOR EXAMPLE, LET'S SAY YOU JUST DELETED A MESSAGE BY ACCIDENT.
##  TO GET IT BACK, YOU GO TO THE SUB-FOLDER.  YOUR MESSAGE WILL
##  BE THE LAST ONE IN THE SUB-FOLDER BECAUSE YOU JUST REMOVED IT.
##  TO RECOVER THE DELETED MESSAGE, MOVE IT BACK TO THE PARENT FOLDER
##  (WHERE IT WAS BEFORE) WITH refile.  AFTER YOU RECOVER IT, IT'LL
##  BE THE LAST MESSAGE IN THE FOLDER:
##      % rmm
##      % show last @DELETE
##      (Message inbox/DELETE:25)
##          (message appears -- this is the one you "deleted")
##      % refile @..
##      % show last @..
##      (Message inbox:54)
##          (same message appears -- now it's back in the parent folder)
##
##  IF YOU DON'T WANT rmmer TO USE A SUB-FOLDER--AND, INSTEAD, PUT
##  ALL THE MESSAGES IN A CENTRAL "DELETE" FOLDER--YOU CAN CALL THE
##  PROGRAM WITH THE NAME rmmer_1 AND THAT'LL DO IT.
##
##  IF YOU PUT A FILE NAMED .rmmer.ask IN A FOLDER, THAT WILL MAKE
##  rmmer PROMPT BEFORE REMOVING ANY MESSAGES THERE.  IT WON'T
##  PROMPT WHEN THE STANDARD INPUT ISN'T COMING FROM A TERMINAL OR
##  WHEN YOU USE THE VERSIONS NAMED rmmer.noask AND rmmer_1.noask.
##  xmh USERS NEED A .noask VERSION TO KEEP xmh FROM HANGING!
##
##  TO INSTALL THIS, PUT IN A FILE NAMED rmmer, THEN MAKE THREE LINKS
##  (SYMBOLIC OR STANDARD): rmmer_1, rmmer.noask, AND rmmer_1.noask.
##
##  NOTE TO HACKERS: TABSTOPS ARE SET AT 4 IN THIS CODE

askfile=.rmmer.ask  # IF THIS FILE EXISTS IN FOLDER, ASK BEFORE REMOVING
moveto=DELETE       # NAME OF FOLDER FOR DELETED MESSAGES
myname=rmmer        # NAME FOR PROMPTS, FASTER/CLEANER THAN basename $0

mhbin=/usr/local/mh mkdir=/bin/mkdir touch=/bin/touch # SET FOR YOUR SYSTEM
profile=/tmp/RMMERp$$ context=/tmp/RMMERc$$
folder="`$mhbin/folder -fast`" || exit
mhdir="`$mhbin/mhpath +`" || exit

# UNCOMMENT THE RIGHT LINE FOR YOUR UNIX:
# echo="echo -n" nnl=   # BSD
# echo=echo      nnl="\c"   # SYSV
echo="echo -n" nnl=     PATH=/usr/bin:$PATH; export PATH    # SunOS

# PROGRAM NAME SETS DESTINATION FOLDER, WHETHER TO LOOK FOR $askfile:
case "$0" in
*rmmer)         destfol="@$moveto" ask=ok ;;
*rmmer.noask)   destfol="@$moveto" ask=no ;;
*rmmer_1)       destfol="+$moveto" ask=ok ;;
*rmmer_1.noask) destfol="+$moveto" ask=no ;;
*)  echo "$0 aborting: can't find my name." 1>&2; exit 1 ;;
esac

stat=1  # DEFAULT EXIT STATUS; RESET TO 0 BEFORE NORMAL EXIT
trap '/bin/rm -f $profile $context; exit $stat' 0
trap 'echo "$0: ouch! $* may not be removed." 1>&2; exit' 1 2 15

# TO AVOID ENDLESS LOOPS WHERE THE refile IN rmmer RUNS rmmproc,
# MAKE TEMPORARY MH PROFILE TO BYPASS USER'S rmmproc: rmmer.
# rmm SETS SHELL'S DIRECTORY TO THE FOLDER WITH THE MESSAGES.
# STORE $folder IN CONTEXT FILE SO refile CAN FIND FOLDER.
# rmm UPDATES THE SEQUENCES BEFORE THE rmmproc RUNS, SO
# THIS rmmproc CAN HIDE SEQUENCE FILE FROM refile.
/bin/cat > $profile << ENDPROF || exit
Path: $mhdir
rmmproc: /bin/rm
mh-sequences:
context: $context
ENDPROF
echo "Current-Folder: $folder" > $context || exit
MH=$profile MHCONTEXT=$context
export MH MHCONTEXT

# IF [OVERHEAD] CONFIG OPTION IS SET, OVERRIDE IT TO USE OUR FILES:
case "${MHFD}X${MHCONTEXTFD}" in
[0-9]X[0-9])
    eval exec $MHCONTEXTFD\< $MHCONTEXT
    eval exec $MHFD\< $MH
    ;;
esac

# IF CURRENT FOLDER ISN'T ALREADY $moveto, WE MIGHT MAKE SUB-FOLDER.
# OTHERWISE, DON'T BURY MESSAGE DEEPER (IT'S PROBABLY BEING UNDELETED).
# THANX TO David Vezie, dv@Sonoma.EDU, FOR THE SUGGESTION, 3/24/92.
case "$folder" in
?*/$moveto)
    # DON'T RUN refile (BELOW) SO MESSAGE WILL STAY HERE.
    stat=0
    exit
    ;;
*)  # rmm SETS CURRENT DIRECTORY TO FOLDER, SO IT'S EASY TO MAKE
    # NEW SUB-FOLDER.  (LET USER MAKE THEIR OWN "+DELETE" ONCE.)
    if [ "$destfol" = "@$moveto" -a ! -d "$moveto" ]
    then $mkdir $moveto || exit
    fi
    ;;
esac

# IF WE SHOULD ASK AND USER ANSWERS "NO", EXIT:
if [ -f $askfile -a -t 0 -a "$ask" = ok ]
then
    $echo "$myname: remove $* in +$folder? [ny](n) $nnl"
    read ans
    case "$ans" in
    [yY]*) ;;   # DO refile BELOW
    *)  exit ;;
    esac
fi
# rmm PUTS SINGLE MESSAGE NUMBERS INTO $* (LIKE 12 13 14).
# UPDATE LAST-MOD TIME SO find -mtime WON'T DELETE TOO SOON.
# USE refile TO "REMOVE" THE MESSAGES.  EXIT WITH refile's STATUS:
$touch $* >/dev/null 2>&1
$mhbin/refile $destfol $*
stat=$?
exit

[Table of Contents] [Index] [Return to Explanation of rmmer]


Last change $Date: 1996/06/06 15:13:53 $

This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright © 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.

Suggestions are welcome: Jerry Peek <jpeek@jpeek.com>