#!/bin/sh
#
# $Id: ALT-MAILER-2,v 1.2 1994/11/23 01:46:52 jik Exp $
#
# This shell script is designed to read mail from either standard input or
# from 1 or more files supplied as arguments, and send the contents to the
# program mh/send (/usr/new/mh/send on ULTRIX). If no arguments are specified
# then standard input is read. Otherwise, the arguments are assumed to be
# valid pathnames of files to be individually sent.
#
# This script is primarily useful in conjunction with programs which send
# mail via standard output, and the user typically use the mhmail facilities
# for sending mail (this includes DECwindows /usr/bin/dxmail program). An
# example program would be xrn, which is an X windows based netnews reader.
#
# ==========================================================================
# Marc Evans - WB1GRH - evans@decvax.DEC.COM  | Synergytics    (603)893-8481
#      Unix/X-window Software Contractor      | 3 Koper Ln, Pelham, NH 03076
# ==========================================================================
#
set -x
mhmail=${MAILER-/usr/new/mh/send}
mdir=""
argv="$*"
if [ $# = 0 ] ; then argv="-" ; fi
#
c="`grep '^Path:' $HOME/.mh_profile | sed 's/^Path:[ 	]*//'`"
if [ "$c" != "" ] ; then
    dirs="$HOME/$c $c $HOME/Mail /usr/tmp"
else
    dirs="$HOME/Mail /usr/tmp"
fi
for i in $dirs ; do
    if [ -d $i -a -w $i ] ; then
	mdir=$i
	break
    fi
done
#
if [ ! -d "$mdir" -a -w "$mdir" ] ; then
    echo "Can't determine directory in which to create draft message. Aborting"
    exit 1
fi
if [ ! -f "`echo $mhmail | sed 's/[ 	].*//'`" ] ; then
    echo "Program '$mhmail' is not available. Aborting"
    exit 1
fi
#
umask 077
for i in $argv ; do
    cat $i >$mdir/draft.$$ && $mhmail $mdir/draft.$$
done

