#!/usr/bin/perl
# [postpgp.pl] v. 2.1
#
#
# written by jason steiner, jsteiner@anwsun.phya.utoledo.edu, Jan 1993
#
# if you use or make improvements to this program i would appreciate
# copies of your modifications & your PGP public key.
#
# [06.03.1998] modified by René Scholz <mrz@informatik.uni-jena.de>
#              for better+easier code (more perl, less awk :)
#
# [21.07.1998] modified by René Scholz <Voland@Jena.Thur.de>
#              for using switches in editor_command:
#              set editor_command "$HOME/Bin/postpgp.pl %s -g %d"
#
# [25.01.2000] modified by Ralf Huels, spambin@strg-alt-entf.org
#              adapted for GnuPG
#######################################################################

$HANDLE_POINTS=0;       # if 1: change . to _.  (for inews)

($visual=$ENV{'EDITOR'}) || ($visual="/usr/bin/jmacs");
$name=$ARGV[1];         # name of edited file in /tmp (or so)

system($visual,@ARGV);  # create posting with editor

print "Sign this message? [yN]: "; chomp($_=<STDIN>);
if(lc($_) eq "y")
{
  print "[R]SA or [D]SA: "; chomp($_=<STDIN>);
  if(lc($_) eq "r") {
#
# Options for RSA signing. Insert your RSA key ID below.
#
      $opts ='--armor --clearsign --sign --default-key 4931A04F --force-v3-sigs --rfc1991 --digest-algo md5';
  }
  else {
#
# Options for DSA signing. This assumes that your DSA key is the default key.
# Otherwise insert a --default-key option below.
#
      $opts='--armor --clearsign --sign';
  }
  &sign_message();
}



sub sign_message
{
  if($opts)
  {
    open(INPUT,$name);
    open(HEAD,">$name.head");
    open(BODY,">$name.body");
    open(SIG ,">$name.sig");
    $body=1;
    while (<INPUT>)
    {
	if (1 .. /^$/) 
	{ 
	    print HEAD; 
	}
	else
	{
	   s/^\./_./  if($HANDLE_POINTS);
	   if (/^-- $/){$body=0};
	   if ($body){print BODY}
	   else {print SIG};
 	}
    }
    close(HEAD);
    close(BODY);
    close(SIG);
    system("gpg $opts $name.body");
    system "cat $name.head $name.body.asc $name.sig > $name";
    unlink("$name.head", "$name.body", "$name.body.asc", "$name.sig");
  }
}






