[comp.mail.mush] Using mush for rn replies

schaefer@ogccse.ogc.edu (Barton E. Schaefer) (05/09/89)

Enclosed is a shell script to allow Mush to be used for 'r'eplying to news
articles from within the RN newsreader.  It was previously sent to the
mush-users mailing list, but this version includes several corrections.
If you picked up the mush-users copy, I recommend you replace it with this.

The script is presently configured for mush 6.5, but all the guts needed
for 6.4 are present in comments, so if you don't have the upgrade kit you
can rip out the 6.5 pieces and uncomment the 6.4 pieces.  The sections that
will need changing both (yes, only two) look like
	# Use this {line,section} for mush 6.4
	#  ... block comment
	#  hiding some commands ...
	# Change to this new {line,section} for mush 6.5
	... other commands ...
so it shouldn't be hard to find them to convert.

The 6.4 version works by turning the headers of the -h file into a bunch
of my_hdr commands that are then fed to mush.  That means you can't
change any of them except To: Cc: Bcc: and Subject: (which you edit with
tilde-escapes as usual).  6.4 users can expect a few error messages that
result from things like the blank Cc: and Bcc: that RN adds by default.
Also, RN's headers will overwrite any that you set in your .mushrc.

The 6.5 version merges the headers of the -h file with those generated by
mush, and edit_hdrs allows you to change any of them.  Mush nicer. :-)

As noted in the preliminary comments below, both versions create a shell
script which is used by mush as $visual.  If you "set visual" in mush to
something other than your environment $VISUAL, you will find that you
don't get the editor you expect.

To use Rnmush to send replies from RN:

	setenv MAILPOSTER "Rnmush -h %h"

To use Rnmush to post news articles:

    This is a little trickier.  The main thing needed is that Rnmush must
    be modified to add

	$echo 'set sendmail="inews -h"' >> $start

    near the beginning, right after the $echo that sets autoedit and so
    on.  Note that this makes it useless for replies, so you probably
    want to make a new copy called Pmush for this modification.  Then, if
    you use

	setenv NEWSPOSTER "Pmush -h %h"

    you have a minimal follow-up news poster.  However, that does not go
    far enough to replace Pnews as it works when invoked from the shell.
    For that, the $start file needs a bunch of my_hdr commands to set the
    Newsgroups:, Distribution:, Keywords:, etc. headers, and they must be
    set to *something* because mush will reject empties.  (For the 6.5
    version, these headers could be added to the $tmpart file before mush
    is called, and then it doesn't matter if they are empty.)

If somebody actually hacks up a fully functional Pmush, send it out. :-)


# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by ogccse!schaefer on Mon May  8 12:08:36 PDT 1989
# Contents:  Rnmush
 
echo x - Rnmush
sed 's/^@//' > "Rnmush" <<'@//E*O*F Rnmush//'
#! /bin/sh -
# Rnmush -- script to use mush for Rnmail
#
# Based on Larry Wall's Rnmail
#
# syntax: Rnmush -h headerfile [oldart]		or
#         Rnmush destination-list 		or just
#         Rnmush
#
# This script creates two other scripts:
#  1) sh script, which takes care of merging the rn header file with
#	mush's editor temp file and then calls the regular visual editor;
#  2) mush script, fed via "mush -source", which sets up some environment
#	and arranges for the first script to be used as the visual editor.

# system configuration

# your organization name
orgname="/usr/lib/news/organization"

mush=mush
defeditor=/usr/ucb/vi
test=/bin/test
sed=sed
echo=echo
cat=cat
rm=/bin/rm
chmod=chmod

# how to echo without a newline
n="-n"
c=""

dotdir=${DOTDIR-${HOME-$LOGDIR}}
tmpart=$dotdir/.letter
start=$dotdir/.rnmush$$
preedit=$dotdir/.rnvis$$
locked=$dotdir/.rnvlk$$

trap "$rm -f $start $preedit $locked; exit 1" 1 2 3 13 15 21 22 23

# some initialization for the mush script
visual=${VISUAL-${EDITOR-$defeditor}}
orgname=${ORGANIZATION-$orgname}
case $orgname in
/*) orgname=`$cat $orgname` ;;
esac

# Use this line for mush 6.4
#$echo set verify autoedit\; unset edit_hdrs > $start
# Change to this line for mush 6.5
$echo set edit_hdrs verify autoedit > $start

headerfile=""
case $# in
0) ;;
*)  case $1 in
    -h)
	headerfile="$2"
	case $# in
	3) oldart=$3 ;;
	esac
	;;
    esac
    ;;
esac

subject=""
case $headerfile in
'')
    case $# in
    0)
	$echo $n "To: $c"
	read to
	;;
    *)
	to="$*"
	;;
    esac
    $echo $n "Subject: $c"
    subject="-s `read subject; echo '\"'$subject'\"'`"
    $echo $n "$c" > $tmpart
    $echo my_hdr Organization: "$orgname" >> $start
    $cat <<EOStrip > $preedit
if $test ! -f $locked ; then
$cat $tmpart >> \$1
$echo "" > $locked
fi
$visual \$1
EOStrip
    ;;
*)
    to=`$sed -e '/^To:/p' -e '/.*/d' < $headerfile | $sed 's/^To: //'`
# Use this section for mush 6.4
#    $echo unset ask asksub askcc >> $start
#    $sed '1,/^$/d' < $headerfile > $tmpart
#    subject="-s \"`$sed -e '/^Subject:/p' -e '/.*/d' < $headerfile \
#	| $sed 's/^Subject: //'`\""
#    $sed -e '1,/^$/p' -e '/.*/d' < $headerfile \
#	| $sed -e '/^To:/d' -e '/^Subject:/d' -e '/^$/d' -e 's/^/my_hdr /' \
#	>> $start
#    $cat <<EOStrip > $preedit
#if $test ! -f $locked ; then
#$cat < $tmpart > \$1
#$echo "" > $locked
#fi
#$visual \$1
#EOStrip
#
# Change to this new section for mush 6.5
#
    $cat <<'EOStart' >> $start
if $?ask
    unset ask
endif
if $?asksub
    unset asksub
endif
if $?askcc
    unset askcc
endif
EOStart
    $cat <<EOStrip > $preedit
if $test ! -f $locked ; then
$sed -e '/^To:/d' -e '/^Subject:/d' -e '/^\$/d' < \$1 > /tmp/$$
$cat /tmp/$$ $headerfile > \$1
$rm -f /tmp/$$
$echo "" > $locked
fi
$visual \$1
EOStrip
# End of 6.5 section
    ;;
esac

$cat <<EOStart >> $start
set visual=$preedit
mail $subject $to
quit
EOStart

$chmod +x $preedit

file=h
while $test "$file" = h ; do
    $echo ""
    $echo $n "Prepared file to include [none]: $c"
    read file
    case $file in
    h)
	;;
    '')
	$echo "" >> $tmpart
	;;
    *)
	$cat $file >> $tmpart
	;;
    esac
done

$echo ""
$mush -shell -noheaders -readonly -source $start -folder /dev/null
$rm -f $preedit $start $locked
@//E*O*F Rnmush//
chmod u=rwx,g=rx,o=rx Rnmush
 
exit 0
-- 
Bart Schaefer       "And if you believe that, you'll believe anything."
							-- DangerMouse
CSNET / Internet                schaefer@cse.ogc.edu
UUCP                            ...{sequent,tektronix,verdix}!ogccse!schaefer

schaefer@ogccse.ogc.edu (Barton E. Schaefer) (05/09/89)

In article <2611@ogccse.ogc.edu> I wrote:
} 
} To use Rnmush to post news articles:
} 
}     This is a little trickier.  The main thing needed is that Rnmush must
}     be modified to add
} 
} 	$echo 'set sendmail="inews -h"' >> $start

I should probably add that this will NOT work for MMDF sites, because MMDF
takes the list of addresses on stdin rather than on the command line.  This
will confuse the heck out of inews.
-- 
Bart Schaefer       "And if you believe that, you'll believe anything."
							-- DangerMouse
CSNET / Internet                schaefer@cse.ogc.edu
UUCP                            ...{sequent,tektronix,verdix}!ogccse!schaefer