#!/usr/bin/perl

# written by jason steiner, jsteiner@anwsun.phya.utoledo.edu, Jan 1993
#
# Modified and fixed by Dave Arcuri (tfff@grove.iup.edu)
#   April 19, 1996
#
# mailpgp  (Perl 5 script)
# -  MailPGP provides a simple, seamless (?) interface to use PGP
#    encryption directly from with a UNIX mailer such
#    as Elm (maybe Pine, although I've only tested it on Elm.)
# -  To recieve the functionality of automatic encryption in your
#    mail program (read: Elm,) change your editor (from 'O'ptions) to
#    /path/where/you/put/this/mailpgp
#    Bingo. You're all set.

($visual = $ENV{'VISUAL'}) || ($visual = '/usr/bin/vi');
print "Use PGP (Y/n): ";
$q=<STDIN>;
chop $q;
if (($q eq 'Y') || ($q eq 'y') || ($q eq '')) { $dopgp = 1; }
else { $dopgp = 0; }
$q='';
system($visual,@ARGV);
if ($dopgp) {
	while (!$q) {
	        print "Sign this message? [Y]: ";
	        $q=<STDIN>;
	        chop $q;
	        if (($q eq 'Y') || ($q eq 'y') || ($q eq '')) {
	                push(@opts,'-st','+clearsig=on');
	                $q="y";
	                }
	        elsif (($q ne 'N') && ($q ne 'n')) {
	                $q='';
	        }
	}
	$q='';
	while (!$q) {
	        print "Encrypt this message? [Y]: ";
	        $q=<STDIN>;
	        chop $q;
	        if (($q eq 'Y') || ($q eq 'y') || ($q eq '')) {
	                push(@opts,'-e');
	                $q="y";
	                }
	        elsif (($q ne 'N') && ($q ne 'n')) {
	                $q='';
	        }
	}
} #endif dopgp
if (@opts) {
        $name=$ARGV[$#ARGV];
        system('pgp','-a',@opts,$name);
        system "mv ${name}.asc $name";
}
