home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / comm / fido / spot / rexx / pgp / decrypt.spot < prev    next >
Text File  |  1994-08-11  |  5KB  |  130 lines

  1. /* This is an Arexx script which you can use to decrypt your netmail. This  */
  2. /* script is only useful in conjunction with PGP.                           */
  3. /* Decrypt.spot Version 1.22 © 1993 by Wim Van Goethem                      */
  4. /*                            Enhancements by Nico Francois                 */
  5. /* For comments, remarks, bugs, etc. contact:                               */
  6. /* Fidonet: 2:292/603.6                                                     */
  7. /* Internet: wim@wolf359.augfl.be                                           */
  8.  
  9. /* Path were you keep PGP (must end on "/" or ":" or be empty) */
  10. PGPpath = ""
  11. DelPGPPASS=1  /* Set this to '1' if you want that the password will be deleted when the script has done. */
  12.  
  13. options results
  14. address spot
  15.  
  16. if ~show(Libraries,'rexxsupport.library') then
  17.     if ~addlib("rexxsupport.library",0,-30,0) then exit
  18.  
  19. /* Does PGPPASS already exists? If so then we won't delete PGPPASS if DelPGPPASS=1. */
  20. NoDelPGPPASS=0
  21. IF EXISTS('env:PGPPASS') THEN NoDelPGPPASS=1
  22.  
  23. 'saveascii TO T:pgptemp_a OVERWRITE NOKLUDGES'    /* Save the msg */
  24.  
  25. /* Get all headerinfo */
  26. 'getfrom'
  27. from_name = result
  28. 'getfromaddress'
  29. from_adres = result
  30. 'getsubject'
  31. subject = result
  32. 'getto'
  33. to_name = result
  34. 'gettoaddress'
  35. to_adres = result
  36.  
  37. /* Do we have a key from this user? */
  38. address command PGPpath"PGP -kv >T:users"
  39. foo = open('file','T:users','R')
  40. ok = 0
  41. do until (ok > 0) | (eof('file'))
  42.     ok = pos(upper(from_name),upper(readln('file')))
  43. end
  44. foo = close('file')
  45. foo = delete('T:users')
  46. if ok == 0 then    /* Key not found! */
  47. do
  48.     address spot
  49.     'requestnotify "Public key of 'from_name' missing! If an error occurs, press Return"'
  50. end
  51.  
  52. /* Let's get the password */ 
  53. if ~exists("ENV:PGPPASS") then  /* We suppose that this password is correct, we do not test any further */
  54. do
  55.     foo = open('file','T:pgptemp_x','W')    /* This is a testfile */
  56.     foo = writeln('file','Testing...')
  57.     foo = close('file')
  58.     do until rc == 0     /* if rc = 0 , the password is valid */
  59.         address spot
  60.         'requeststring PROMPT "     Please give your password     " TITLE "Encryption" INVISIBLE'
  61.         if rc == 5 then  /* User pressed 'Cancel' */
  62.         do
  63.             foo = delete('T:pgptemp_x')
  64.             foo = delete('T:pgptemp_x.asc')
  65.             foo = delete('T:pgptemp_a')
  66.             foo = delete('env:PGPPASS')
  67.             say "Please close window to quit."
  68.             IF (DelPGPPASS & ~NoDelPGPPASS) THEN foo=DELETE('Env:PGPPASS')
  69.             EXIT
  70.         end
  71.         address command ""setenv PGPPASS ""||result||""
  72.         /* Is it correct? */
  73.         address command PGPpath'PGP >NIL: +batchmode -sa T:pgptemp_x'
  74.         foo = delete('T:pgptemp_x.asc')
  75.     end
  76.     foo = delete('T:pgptemp_x')
  77. end
  78.  
  79. /* Search the PGP block */
  80. foo = open('infile','T:pgptemp_a','R')  /* The input file */
  81. foo = open('outfile','T:pgptemp_b','W') /* The output file */
  82. do while ~eof('infile')                 /* Repeat until end of file */
  83.     instring = readln('infile')
  84.     if left(instring,26)=="-----BEGIN PGP MESSAGE----" then /* We found the beginning */
  85.     do
  86.         foo = writeln('outfile',instring)
  87.         do while left(instring,24)~=="-----END PGP MESSAGE----" /* We found the end */
  88.             instring = readln('infile')
  89.             foo = writeln('outfile',instring)
  90.         end
  91.     end
  92. end
  93. foo = close('infile')
  94. foo = close('outfile')
  95. foo = delete('T:pgptemp_a') /* We won't need this anymore */
  96.  
  97. /* Decrypt the message */
  98. options failat 100
  99. address command PGPpath"PGP T:pgptemp_b -o T:pgptemp_c"
  100. if rc ~= 0 then do
  101.     foo = delete('T:pgptemp_b')
  102.     say "Please close window to quit."
  103.     IF (DelPGPPASS & ~NoDelPGPPASS) THEN foo=DELETE('Env:PGPPASS')
  104.     exit
  105.     end
  106. foo = delete('T:pgptemp_b') /* We won't need this anymore */
  107.  
  108. /* Make sure the subject is back restored to the original subject           */
  109. foo = open('infile','T:pgptemp_c','R')          /* The input file           */
  110. foo = open('outfile','T:pgptemp_d','W')         /* The output file          */
  111. instring = readln('infile')                     /* Get the subject line     */
  112. subject = right(instring,length(instring)-10)   /* Get the subject          */
  113. do while ~eof('infile')                         /* Repeat until end of file */
  114.     instring = readln('infile')
  115.     foo = writeln('outfile',instring)
  116. end
  117. foo = close('infile')
  118. foo = close('outfile')
  119. foo = delete('T:pgptemp_c') /* We won't need this anymore */
  120.  
  121. /* Put the decrypted msg back into the message base */
  122. address spot
  123. 'edit FILE T:pgptemp_d REFLOW=OFF SUBJECT "'subject'" NOEDIT NOGUI NOSIG NOREQ'
  124. foo = delete('T:pgptemp_d') /* We won't need this anymore (gets a bit boring, don't you think?:-) */
  125.  
  126. /* Quit */
  127. say "Please close window to quit."
  128. IF (DelPGPPASS & ~NoDelPGPPASS) THEN foo=DELETE('Env:PGPPASS')
  129. exit
  130.