#!/usr/local/bin/perl 
# -d
# this is used as whatnow proc ( see MH-plus )

$vi = "vi";
$less = "less";
$mhn = "mhn -auto -headers -junet";
$file = $ENV{'mhdraft'};

&edit($vi);

print "$ENV{'mhdraft'}\n";

$|=1;

print "what now? ";
while(<STDIN>) {
    chop;
    s/\s+(.*)$//; $opt = $1;
    if ("quit"=~/^$_/) {
	if ($opt =~/\-d/) {
	    unlink($file);
	}
        exit;
    } elsif ("edit"=~/^$_/) {
	if ($opt) {
	    edit($opt);
	} else {
	    edit($vi);
	}
    } elsif ("list"=~/^$_/) {
	if ($opt) {
	    less($opt);
	} else {
	    less($less);
	}
    } elsif ("send"=~/^$_/) {
	use News::NNTPClient;
	my $c = new News::NNTPClient;
	# $c->debug(0);
	system "$mhn $file";
	open(IN,"<$file") or die("can't open $file $!");
	@buf = <IN>; 
	$c->post(@buf);
	system "refile -src +drafts last +posted";
	exit(0);
    } else {
	print "edit/send/list/quit\n";
    }
    print "what now? ";
}

sub edit {
    my($vi) = @_;
    system "$vi $file";
}

sub less {
    my($less) = @_;
    system "$less $file";
}



