The scandrafts Shell Script

[return-to Explanation of scandrafts] [table of contents] [index]
#! /bin/sh
#   $Id: scandrafts,v 1.8 1995/04/26 20:02:49 jerry book3 $
### scandrafts - scan MH draft folder; return to original folder if no -stay
### Usage: scandrafts [-stay] [scan arguments]
##
##  THIS SCRIPT IS NICE WHEN YOU'RE WONDERING WHAT'S IN YOUR DRAFT
##  FOLDER, OR YOU NEED TO WORK IN IT.
##  
##  BY DEFAULT, scandrafts SHOWS A LIST OF THE MESSAGES YOU'VE ALREADY
##  SENT (THESE MESSAGES ARE IN FILES WITH A COMMA OR POUND SIGN BEFORE
##  THEIR NAMES).  THEN, IT  scanS YOUR DRAFT FOLDER, AND POPS YOU BACK
##  TO YOUR CURRENT FOLDER.
##  
##  IF YOU USE THE -stay OPTION, scandrafts WILL START A SHELL WITH
##  BOTH THE CURRENT DIRECTORY AND CURRENT FOLDER IN THE DRAFT FOLDER.
##  THAT WAY, YOU CAN RESTORE ONE OF THE ALREADY-SENT MESSAGES AND/OR
##  refile IT TO ANOTHER FOLDER (IN CASE YOU FORGOT TO GIVE YOURSELF A
##  COPY WHEN YOU SENT IT).  OR, YOU CAN DO EXTENSIVE WORK ON THE
##  DRAFTS, MORE DIRECTLY THAN A SCRIPT LIKE recomp WILL LET YOU.
##  
##  HERE'S A DEMONSTRATION:
##  
##  $ scandrafts -stay 
##  Draft message(s) you've already sent:
##  
##  ,1:Subject: Re: SC or GA islands
##  ,5:Subject: Re: our previous message about banners dialups etc
##  ,6:Subject: Re: Can you help?
##  ,7:Subject: Out this morning
##  
##  To get them back, use 'mv'.
##  ===================================================================
##  Draft message(s) you haven't sent:
##  
##     1  03/07*To:alison@mvus.cs  Project status<<Alison, the project
##     2  empty
##     3+ 03/07*To:kx9cq@cornell.  Scientific Visualization Demo<<I re
##  
##      You'll be in a /usr/local/bin/ksh shell in the +drafts folder.
##      To quit, type control-d.
##  scandrafts> rmm 2 
##  scandrafts> mv ,6 6 
##  scandrafts> scan 
##     1  03/07*To:alison@mvus.cs  Project status<<Alison, the project
##     3+ 03/07*To:kx9cq@cornell.  Scientific Visualization Demo<<I re
##     6  03/04*To:warren          Re: Can you help?<<Warren, you aske
##  scandrafts> refile 6 +outbox 
##  scandrafts> ^D 
##  [folder +inbox now current]
##  $
##
##  NOTE TO HACKERS: TABSTOPS ARE SET AT 4 IN THIS CODE

args=   # RESET IN CASE THERE'S AN args ENVIRONMENT VARIABLE
folopts="-fast -nolist -nototal -nopack"
mh=/usr/local/mh
pageprog=${PAGER-/usr/ucb/more} # DISPLAYS SCREEN-BY-SCREEN
stat=1  # DEFAULT EXIT STATUS; RESET TO 0 FOR NORMAL EXITS
temp=/tmp/SCANDRFTS$$
>$temp
chmod 600 $temp
trap 'rm -f $temp; exit $stat' 0 1 2 15

# IF -stay SWITCH IS SET, SET $stay TO y:
for arg
do
    case "$arg" in
    -stay)  stay=y ;;
    *)  args="$args $arg" ;;
    esac
done

# GET DRAFT FOLDER NAME:
draftfold="`$mh/mhparam draft-folder`" || {
    echo "`basename $0`: quitting: can't find your 'Draft-Folder'." 1>&2
    exit
}

$mh/folder $folopts -push +$draftfold >/dev/null || exit
folpath=`$mh/mhpath +$draftfold` || exit
cd $folpath || exit

# IF ANY UN-SENT DRAFTS, SHOW THEM; THEN, scan FOLDER.
# PIPE ALL OF IT TO PAGER SO NONE OF IT SCROLLS OFF SCREEN:
grep "^Subject: " [,#]*[1-9]* >$temp 2>/dev/null
(if test -s $temp
then
    echo "Draft message(s) you've already sent:
    "
    cat $temp
    echo
    case "$stay" in
    y) echo "To get them back, use 'mv'." ;;
    *) echo "To get them back, use 'cd $folpath' and 'mv'." ;;
    esac
    echo "============================================================="
    echo "Draft message(s) you haven't sent:
    "
fi
$mh/scan $args 2>&1) | $pageprog

# USE THEIR $SHELL, IF DEFINED... OTHERWISE, USE sh:
case "$stay" in
y) echo "
    You'll be in a ${SHELL-Bourne} shell in the +$draftfold folder.
    To quit, type control-d."
    PS1="scandrafts> " ${SHELL-sh}
    ;;
esac

# POP FOLDER BACK; PUT NEWLINE BEFORE MESSAGE:
echo "
[folder +`$mh/folder $folopts -pop` now current]"
stat=0

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


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 <jerry@ora.com>

Questions or problems regarding this web site should be directed to Steve Gielda.
Copyright 1999 www.cotse.com.  All rights reserved.
Last modified: Friday April 02, 1999.