home *** CD-ROM | disk | FTP | other *** search
/ Current Shareware 1994 January / SHAR194.ISO / modem / ozpgp.zip / OZPGPE.CMD < prev    next >
OS/2 REXX Batch file  |  1993-10-19  |  4KB  |  144 lines

  1. extproc perl -x
  2. #!perl
  3. # Since these perl scripts are FREE, they are provided AS IS. I MAKE NO
  4. # WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING WITHOUT LIMITATION,
  5. # ANY WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
  6. #
  7. # If you find any bugs, please mail me a detailed description so I can fix it.
  8. # Better yet, fix it yourself and mail the fix to me. :-)
  9. # Any comment is welcome.
  10. #
  11. # Eric Veldhuyzen 
  12. #
  13. #   CIS ID: [100010,3051]
  14. # Internet: v912182@si.hhs.nl
  15.  
  16. $cismail = $ARGV[$#ARGV];
  17. if ("$cismail" eq "") {
  18.   die "Argument required!\n";
  19. }
  20.  
  21. open (mail, "$cismail") || die "Can't open $cismail: $!.\n";
  22. open (out, ">encoded.txt") || die "Can't open encoded.txt: $!.\n"; 
  23.  
  24. if (open (lst, "list")) {
  25.   @list = <lst>;
  26. } else {
  27.   print "No listfile found. Generating one. Please be patient...\n";
  28.   system "pgp -kv >list";
  29.   if (open (lst, "list")) {
  30.     $i = 0;
  31.     while (<lst>) {
  32.       $list[$i] = <lst>;
  33.       $i++;
  34.     }
  35.   } else {
  36.     die "Too bad. No list file found, and I couldn't generate one. Disk full?\n";
  37.   }
  38. }
  39. close lst;
  40.  
  41. while (<mail>) {
  42. #  if ((/^\xb3MAIL\xb3.*/) || (/^\xb3REP \d*\xb3.*/)) { # Not tested well. For
  43.                             # signing in forums.
  44.   if ((/^\xb3MAIL\xb3.*/) {
  45.     open (tmp, ">PGPTEMP") || die "Can't open PGPTEMP: $!.\n";
  46.     print out $_;
  47.     if (/.*>internet:.*/i) {    # Internet address.
  48.       s/.*>internet://i;        # This can be done different. But how...
  49.       s/\xb3.*//;
  50.       chop;                     # Remove the \n
  51.       $address = $_;
  52.       @grepoutput = grep(/$address/oi,@list);
  53.       if (!@grepoutput) {
  54.         $address = "";
  55.       }
  56.     } elsif (/.*\[([0-7]*,[0-7]*)\].*/) {
  57.                                 # CompuServe address. I think I should
  58.                                 # do this different. But I don't know how...
  59.       ($address = $1 . '@compuserve.com') =~ s/,/./ if /\[(\d+,\d+)\]/;
  60.       #($adres = $1) =~ (s/.*\[/\[/) && (s/].*/]/);
  61.       ($adres = $1) =~ s/.*\[([^\]]*)\].*/\1/;
  62.       @grepoutput = grep(/$address/oi,@list);
  63.       if (!@grepoutput) {
  64.         @grepoutput = grep(/$adres/oi,@list);
  65.         if (!@grepoutput) {
  66.           $address = "";
  67.         }
  68.       }
  69.     } else {                    # Something else. Don't encrypt.
  70.       print "Illegal address?\n";
  71.       $address= "";
  72.     }
  73.     $_ = <mail>;
  74.     if ((/^-----BEGIN PGP.*/) || (/^#leave$/)) {
  75.       if (/^#leave$/) {
  76.         print "Leaving message alone.\n\n";
  77.       } else {
  78.         print "\nOops! Allready encrypted or signed...\nLeaving message alone.\n\n";
  79.       }
  80.       while (!/^\xccEOM\xb9/) {
  81.         s/^#leave\n//;
  82.         print out $_;
  83.         $_ = <mail>;
  84.       } 
  85.     } else {
  86.       while (!/^\xccEOM\xb9/) {
  87.         print tmp $_;
  88.         $_ = <mail>;
  89.       } 
  90.       close tmp;
  91.       if ($address) {
  92.                                 # ID known. Sign and encrypt
  93.         print "\nEncrypting with ID \"$address\".\n\n";
  94.         system "pgp -seat +force=on +batchmode=on PGPTEMP -o PGPTEMP.OUT $address >nul";
  95.       } else {
  96.                                 # ID Unknown. Just sign it to promote PGP.
  97.         print "\nID not known by PGP. Just signing...\n\n";
  98.         system "pgp -sta +clearsig=on +force=on +batchmode=on PGPTEMP -o PGPTEMP.OUT >nul";
  99.       }
  100.       if (open (tmp, "PGPTEMP.OUT")) {
  101.         while (<tmp>) {
  102.           print out $_;
  103.         }
  104.         close tmp;
  105.       } else {
  106.         print out "\nAn error ocurred.\n";
  107.         print out "Original message follows:\n\n ";
  108.         if (open (tmp, "PGPTEMP")) {
  109.           while (<tmp>) {
  110.             print out $_;
  111.           }
  112.           close tmp;
  113.         } else {
  114.           print out "Can't open original message for some reason.\n";
  115.           print out "Message lost. Sorry.\n";
  116.         }
  117.       }
  118.       if (-e "PGPTEMP.OUT") {   # remove temporary files.
  119.         unlink ("PGPTEMP.OUT");
  120.       }
  121.       if (-e "PGPTEMP") {
  122.         unlink ("PGPTEMP");
  123.       }
  124.     }
  125.     print out "\xccEOM\xb9\n";
  126.   } else {
  127.     print out $_;
  128.   }
  129. }
  130. close mail;
  131. close out;
  132. if (-e "cismail.bak") {
  133.   unlink ("cismail.bak");
  134. }
  135. $bakfile = $cismail;            # Make a backupfile...
  136. while (chop($bakfile) ne "\."){}
  137. $bakfile = "$bakfile\.bak";
  138. if (-e "$bakfile") {
  139.   unlink ("$bakfile");
  140. }
  141. rename ("$cismail" , "$bakfile");
  142. rename ("encoded.txt","$cismail");
  143. __END__
  144.