#! /bin/sh
# $Id: append,v 1.12 92/07/24 17:35:58 jerry book2 $
### append - append file(s) to an MH mail message
### Usage:   What now? e append file [files...]
##
##  THIS SCRIPT LETS YOU APPEND ONE OR MORE FILES TO A DRAFT MH MAIL
##  MESSAGE; IT ALSO ALLOWS WILDCARDS AND ENVARIABLES.
##  YOU CALL IT AS AN EDITOR, AT THE What now? PROMPT.
##  FOR EXAMPLE, TO APPEND A COPY OF YOUR FILE report TO YOUR DRAFT:
##      What now? e append report
##  YOU CAN MODIFY THE case "$1" BELOW TO LET YOU TYPE ABBREVIATIONS
##  FOR FILENAMES YOU USE A LOT.
##
##  AFTER IT APPENDS THE FILE(S), YOU GET ANOTHER What now? PROMPT.
##  IF YOU WANT TO SEPARATE THE FILES WITH BLANK LINES, ROWS OF DASHES,
##  OR WHATEVER, AN EASY WAY IS TO MAKE A LITTLE FILE NAMED SOMETHING
##  LIKE SEP WITH THAT SEPARATOR IN IT.  THIS NEXT EXAMPLE SHOWS HOW TO
##  APPEND ALL THE FILES FROM THE $HOME/proj DIRECTORY WHOSE NAMES END
##  WITH .out, THEN YOUR SEPARATOR FILE, THEN THE FILE .signature:
##      What now? e append $HOME/proj/*.out sep .signature
##
## Original, apparently by John Romine, from the paper
## "MH.5: How to process 200 messages a day and still get some
## real work done," in the Summer 1985 USENIX Proceedings.
## Hacked more by Jerry Peek, with hints from John Romine.
## Edward Vielmetti added the "filename abbreviation" setup.
# 
#                             NO WARRANTY
# 
#   BECAUSE THIS PROGRAM IS AVAILABLE FREE OF CHARGE, THERE IS NO WARRANTY
# FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
# OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
# PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
# OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
# TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
# PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
# REPAIR OR CORRECTION.
# 
#   IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
# WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
# REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
# INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
# OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
# TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
# YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
# PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGES.


case $# in
0)  echo 1>&2 "`basename $0`: shouldn't get here!"; exit 1;;
1)  echo 1>&2 "Usage: e[dit] `basename $0` file [files...]"; exit 1 ;;
*)  while :
    do
        case $# in
        1)  msg=$1; break ;;
        *)  # WIRE IN COMMON NAMES HERE.  COMMENT OUT IF NOT USING. -emv
            case "$1" in
#           sig)    files="$files $HOME/.signature" ;;
#           sep)    files="$files $HOME/Mail/separator" ;;
            *)      files="$files $1" ;;
            esac
            shift
            ;;
        esac
    done
    ;;
esac

eval cat $files '>>' $msg  # EXPAND ENVARIABLES IN $files (PROTECT >>)
exit 0  # FAKE SUCCESS TO KEEP MH FROM DELETING DRAFT IF cat FAILED
