home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Current Shareware 1994 January
/
SHAR194.ISO
/
modem
/
ozpgp.zip
/
OZPGPE.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1993-10-19
|
4KB
|
144 lines
extproc perl -x
#!perl
# Since these perl scripts are FREE, they are provided AS IS. I MAKE NO
# WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING WITHOUT LIMITATION,
# ANY WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
#
# If you find any bugs, please mail me a detailed description so I can fix it.
# Better yet, fix it yourself and mail the fix to me. :-)
# Any comment is welcome.
#
# Eric Veldhuyzen
#
# CIS ID: [100010,3051]
# Internet: v912182@si.hhs.nl
$cismail = $ARGV[$#ARGV];
if ("$cismail" eq "") {
die "Argument required!\n";
}
open (mail, "$cismail") || die "Can't open $cismail: $!.\n";
open (out, ">encoded.txt") || die "Can't open encoded.txt: $!.\n";
if (open (lst, "list")) {
@list = <lst>;
} else {
print "No listfile found. Generating one. Please be patient...\n";
system "pgp -kv >list";
if (open (lst, "list")) {
$i = 0;
while (<lst>) {
$list[$i] = <lst>;
$i++;
}
} else {
die "Too bad. No list file found, and I couldn't generate one. Disk full?\n";
}
}
close lst;
while (<mail>) {
# if ((/^\xb3MAIL\xb3.*/) || (/^\xb3REP \d*\xb3.*/)) { # Not tested well. For
# signing in forums.
if ((/^\xb3MAIL\xb3.*/) {
open (tmp, ">PGPTEMP") || die "Can't open PGPTEMP: $!.\n";
print out $_;
if (/.*>internet:.*/i) { # Internet address.
s/.*>internet://i; # This can be done different. But how...
s/\xb3.*//;
chop; # Remove the \n
$address = $_;
@grepoutput = grep(/$address/oi,@list);
if (!@grepoutput) {
$address = "";
}
} elsif (/.*\[([0-7]*,[0-7]*)\].*/) {
# CompuServe address. I think I should
# do this different. But I don't know how...
($address = $1 . '@compuserve.com') =~ s/,/./ if /\[(\d+,\d+)\]/;
#($adres = $1) =~ (s/.*\[/\[/) && (s/].*/]/);
($adres = $1) =~ s/.*\[([^\]]*)\].*/\1/;
@grepoutput = grep(/$address/oi,@list);
if (!@grepoutput) {
@grepoutput = grep(/$adres/oi,@list);
if (!@grepoutput) {
$address = "";
}
}
} else { # Something else. Don't encrypt.
print "Illegal address?\n";
$address= "";
}
$_ = <mail>;
if ((/^-----BEGIN PGP.*/) || (/^#leave$/)) {
if (/^#leave$/) {
print "Leaving message alone.\n\n";
} else {
print "\nOops! Allready encrypted or signed...\nLeaving message alone.\n\n";
}
while (!/^\xccEOM\xb9/) {
s/^#leave\n//;
print out $_;
$_ = <mail>;
}
} else {
while (!/^\xccEOM\xb9/) {
print tmp $_;
$_ = <mail>;
}
close tmp;
if ($address) {
# ID known. Sign and encrypt
print "\nEncrypting with ID \"$address\".\n\n";
system "pgp -seat +force=on +batchmode=on PGPTEMP -o PGPTEMP.OUT $address >nul";
} else {
# ID Unknown. Just sign it to promote PGP.
print "\nID not known by PGP. Just signing...\n\n";
system "pgp -sta +clearsig=on +force=on +batchmode=on PGPTEMP -o PGPTEMP.OUT >nul";
}
if (open (tmp, "PGPTEMP.OUT")) {
while (<tmp>) {
print out $_;
}
close tmp;
} else {
print out "\nAn error ocurred.\n";
print out "Original message follows:\n\n ";
if (open (tmp, "PGPTEMP")) {
while (<tmp>) {
print out $_;
}
close tmp;
} else {
print out "Can't open original message for some reason.\n";
print out "Message lost. Sorry.\n";
}
}
if (-e "PGPTEMP.OUT") { # remove temporary files.
unlink ("PGPTEMP.OUT");
}
if (-e "PGPTEMP") {
unlink ("PGPTEMP");
}
}
print out "\xccEOM\xb9\n";
} else {
print out $_;
}
}
close mail;
close out;
if (-e "cismail.bak") {
unlink ("cismail.bak");
}
$bakfile = $cismail; # Make a backupfile...
while (chop($bakfile) ne "\."){}
$bakfile = "$bakfile\.bak";
if (-e "$bakfile") {
unlink ("$bakfile");
}
rename ("$cismail" , "$bakfile");
rename ("encoded.txt","$cismail");
__END__