home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Current Shareware 1994 January
/
SHAR194.ISO
/
modem
/
ozpgp.zip
/
OZPGPD.CMD
next >
Wrap
OS/2 REXX Batch file
|
1993-10-13
|
5KB
|
139 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, ">decoded.txt") || die "Can't open decoded.txt: $!.\n";
while (<mail>) {
if (/^-----BEGIN PGP.*MESSAGE.*/) {
if (open (tmp, ">PGPTEMP")) {
do {
print tmp $_;
$_ = <mail>;
} until (/^-----END.*/);
print tmp $_;
close tmp; # File must be closed or we lose
# some information.
system "pgp +batchmode=on +force=on PGPTEMP -o PGPTEMP.OUT >output";
if (open (tmp, "output")) {
print out "-----BEGIN DECODING INFORMATION-----\n";
while (<tmp>) {
s/^plaintext.*\n//i; # needless information
s/^For .*\n//;
s/\cG//g; # strip the ^G. I don't need a beep
# in a message.
print out $_;
}
close tmp;
print out "-----END DECODING INFORMATION-----\n";
} else {
print out "\nCan't open the output of pgp for some reason.\n\n";
}
if (open (tmp, "PGPTEMP.OUT")) {
print out "-----BEGIN DECODED PGP MESSAGE-----\n";
while (<tmp>) {
print out $_;
}
print out "-----END DECODED PGP MESSAGE-----\n";
close tmp;
} else {
print out "\nAn error ocurred.\n";
print out "This message is probably not encrypted with your public key.\n";
# Add an extra space to prevent retrying
# to decrypt next time.
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") { # remove temporary files.
unlink ("PGPTEMP");
}
if (-e "PGPTEMP.OUT") {
unlink ("PGPTEMP.OUT");
}
if (-e "output") {
unlink ("output");
}
} else { # Maybe this error should be changed to
# something non fatal.
die "Can't open PGPTEMP: $!.\n";
}
} elsif (/^-----BEGIN PGP PUBLIC KEY.*/) {
if (open (tmp, ">PGPTEMP")) {
do {
print tmp $_;
$_ = <mail>;
} until (/^-----END.*/);
print tmp $_;
close tmp; # File must be closed or we lose
# some information.
system "pgp +batchmode=on +force=on -ka PGPTEMP >output";
if (open (tmp, "output")) {
print out "-----BEGIN KEY ADDING INFORMATION-----\n";
$added = 1;
while (<tmp>) {
if (/^No new keys or signatures in keyfile\.$/i) {
$added = 0;
}
s/\cG//g; # Strip the ^G. I don't need a beep
# in a message.
print out $_;
}
close tmp;
print out "-----END KEY ADDING INFORMATION-----\n";
if ($added) {
system "pgp -kv >list";# A new key was added. Generate a new list file.
}
if (-e "PGPTEMP") { # remove temporary files.
unlink ("PGPTEMP");
}
if (-e "output") {
unlink ("output");
}
} else {
print out "\nCan't open the output of pgp for some reason.\n\n";
}
} else { # Maybe this error should be changed to
# something non fatal.
die "Can't open PGPTEMP: $!.\n";
}
} else {
print out $_;
}
}
close mail;
close out;
$bakfile = $cismail; # Make a backupfile...
while (chop($bakfile) ne "\."){}
$bakfile = "$bakfile\.bak";
if (-e "$bakfile") {
unlink ("$bakfile");
}
rename ("$cismail" , "$bakfile");
rename ("decoded.txt", "$cismail");
__END__