Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Sep 1995 09:49:39 -0700 (PDT)
From:      bmk@dtr.com
To:        mcw@hpato.aus.hp.com (M C Wong)
Cc:        questions@freebsd.org
Subject:   Re: PGP aware mailer ?
Message-ID:  <199509081649.JAA00338@rainier>
In-Reply-To: <199509080533.AA029138409@hp.com> from "M C Wong" at Sep 8, 95 03:33:27 pm

next in thread | previous in thread | raw e-mail | index | archive | help
-----BEGIN PGP SIGNED MESSAGE-----

> How about does there exist any editor which can support pgp 
> stuff ? In which case, I was hoping that I can just change the
> editor in elm instead of installing a new version of elm or
> different mailer.

Write a shell script wrapper that does this.  PGP includes example
scripts - I used the morepgp and mailpgp scripts to do exactly what
you're looking for.

- --- morepgp
#!/usr/bin/perl

# 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.

$|=1;
$topgp=0;
$logname = $ENV{'LOGNAME'};
$pager='/usr/local/bin/less -i -n -s -S -c -M';
$pager = $ENV{'PAGER'} if ($ENV{'PAGER'});
umask 077;
open (PAGER, "|$pager") || die "Cannot open pipe to $pager.\n";
print PAGER "\n";
while (<>) {
	if (!$topgp && m/^-----BEGIN PGP .*-----/) {
		$topgp = 1;
		$tmpfile = "/tmp/.pgp.$logname.$$";
		unlink($tmpfile);
		open (TMPFILE, ">$tmpfile") || die "Cannot open $tmpfile for output.\n";
	}
	if (!$topgp) {
		print PAGER;
	} else {
		print TMPFILE $_;
		if (m/^-----END PGP .*-----/) {
			$topgp = 0;
			close TMPFILE;
			open (CLEAR, "pgp -f < $tmpfile |") || die "Cannot open pipe to PGP.\n";
			print PAGER "-----BEGIN PGP DECRYPTED BLOCK-----\n";
			while (<CLEAR>) {
				print PAGER;
			}
			close CLEAR;
			unlink($tmpfile);
			print PAGER "-----END PGP DECRYPTED BLOCK-----\n";
		}
	}
}
close PAGER;

- --- mailpgp
#!/usr/bin/perl

($visual = $ENV{'VISUAL'}) || ($visual = '/usr/bin/vi');
$topgp = 0;
$blanks = 0;
$paragraphs = 1;
$blankcompress = 1;
$name=@ARGV[$#ARGV];
umask (077);
open (INPUT, "<$name");
open (OUTPUT, ">${name}.rply") || die "Cannot open ${name}.rply for output.\n";
while (<INPUT>) {
	if (!$topgp && !m/^> -----BEGIN PGP .*-----/) {
		if (m/^> *$/) {
			if ($paragraphs) {
				if ($blankcompress) {
					if ($blanks == 0) {
						print OUTPUT "\n";
						$blanks = 1;
					}
				} else {
					print OUTPUT "\n";
				}
			} else {
				print OUTPUT;
			}
		} elsif (m/^ *$/) {
			if ($blankcompress) {
				if ($blanks == 0) {
					print OUTPUT "\n";
					$blanks = 1;
				}
			} else {
				print OUTPUT;
			}
		} else {
			print OUTPUT;
			if ($. == 1 && !m/^> /) {
				print OUTPUT "\n";
				$blanks = 1;
			} else {
				$blanks = 0;
			}
		}
	}
	if (!$topgp && m/^> -----BEGIN PGP .*-----/) {
		$topgp = 1;
		$tmpfile = "${name}.pgp",
		unlink ($tmpfile);
		open (TMPFILE, ">$tmpfile") || die "Cannot open $tmpfile for output.\n";
	}
	if ($topgp) {
		$_ =~ s/^> //;
		print TMPFILE $_;
		if (m/^-----END PGP .*-----/) {
			$topgp = 0;
			close TMPFILE;
			$clrfile = "${name}.clr";
			`pgp $tmpfile -o $clrfile`;
			open (CLEAR, "<$clrfile") || die "Cannot open $clrfile for input.\n";
			print OUTPUT "-----BEGIN OF PGP DECRYPTED TEXT-----\n\n";
			while (<CLEAR>) {
				if (m/^$/) {
					print OUTPUT "\n";
				} else {
					print OUTPUT "> ";
					print OUTPUT;
				}
			}
			close CLEAR;
			unlink ($clrfile);
			unlink ($tmpfile);
			print OUTPUT "\n-----END OF PGP DECRYPTED TEXT-----\n\n";
		}
	}
}
close OUTPUT;
close INPUT;
unlink ($name);
rename ("${name}.rply", "$name");

system ($visual,@ARGV);

while (!$q) {
	print "Sign this message? [Y]: ";
	$q = <STDIN>;
	$q =~ s/[ \t\n]//g;
	$q = substr ($q, 0, 1);
	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? [N]: ";
	$q = <STDIN>;
	$q =~ s/[ \t\n]//g;
	$q = substr ($q, 0, 1);
	if (($q eq 'Y') || ($q eq 'y')) {
		push(@opts,'-e');
		$q = "y";
	} elsif (($q ne 'N') && ($q ne 'n')) {
		$q = 'n';
	}
}
if (@opts) {
	system ('pgp','-a',@opts,$name);
	if ($? == 0) {
		unlink ${name};
		rename ("${name}.asc", "$name");
	}
}

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQBFAwUBMFB0F2ADWC0MDkc5AQF/hwGAgc8Beooqgb4PO8BwPkYKq9wiS39xOxOl
AJzTYs8PWLdnkmfXVqLKwsvzDXfoggjp
=CgXZ
-----END PGP SIGNATURE-----



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199509081649.JAA00338>