#!/usr/local/bin/perl
#
#NAME
#  Edit - edit the current email message
#
#SYNOPSIS
#  Edit [+folder] [index]
#
#REQUIRES
#
	$LNAM = $ENV{'LOGNAME'} || $ENV{'USER'};
	$HOME = $ENV{'HOME'} || "/home/$LNAM";
	@INC = ($HOME, "$HOME/mh","$HOME/sh",@INC);
	require 'jcmh.pm';
#
#DESCRIPTION
#  This lists the current message from  an  mh-style  directory.   If
#  there is no current message, we start at 1. If the current message
#  doesn't exist, we act as Next, and hunt for the next message.
#
#OPTIONS
#
#EXAMPLES
#
#FILES
#
#BUGS
#
#SEE ALSO
#   Inc, List, Prev, Next, ...
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>

$| = 1;

for $a (@ARGV) {
	print "$0: Arg \"$a\"\n" if $V>2;
	if ($a =~ /^\+(\w+)$/) {
		$FLDR = $1;
		print "Folder \"$FLDR\" from command line.\n" if $V>2;
	} elsif ($a =~ /^\d+$/) {
		$ndx = $a;
	} else {
		print STDERR "$P: Unrecognized arg \"$a\" ignored.\n";
	}
}
print "Folder \"$FLDR\"\n" if $V>1;

unless ($ndx) {
	$ndx = &getindex($MDIR,$FLDR,1);
	print "Current index in $FLDR is $ndx.\n" if $V>1;
}

unless (-f "$FDIR/$ndx") {
	print STDERR "$P: CUrrent message $FDIR/$ndx does not exist.\n";
	exit 1;
}
print "$FDIR/$ndx\n" if $V>0;
print "$FDIR/$ndx\n" if $V>0;
$ed = $ENV{'VISUAL'} || $ENV{'EDITOR'} || 'vi';
$cmd = "$ed $FDIR/$ndx";
print "cmd: $cmd\n" if $V>0;
system $cmd;
exit 0;
