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

  1. /* This is an Arexx script which you can use to encrypt your netmail. This  */
  2. /* script is only useful in conjunction with PGP.                           */
  3. /* Encrypt.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. cr = '0D'x
  12. DelPGPPASS=1  /* Set this to '1' if you want that the password will be deleted when the script has done. */
  13.  
  14. address spot
  15. options results
  16.  
  17. if ~show(Libraries,'rexxsupport.library') then
  18.     if ~addlib("rexxsupport.library",0,-30,0) then exit
  19.  
  20. /* Does PGPPASS already exists? If so then we won't delete PGPPASS if DelPGPPASS=1. */
  21. NoDelPGPPASS=0
  22. IF EXISTS('env:PGPPASS') THEN NoDelPGPPASS=1
  23.  
  24. 'saveascii TO T:pgptemp_a OVERWRITE NOKLUDGES'    /* Save the msg */
  25.  
  26. /* Get all headerinfo */
  27. 'getfrom'
  28. from_name = result
  29. 'getsubject'
  30. subject = result
  31. 'getto'
  32. to_name = result
  33. 'gettoaddress'
  34. to_adres = result
  35. if rc == 5 then /* This is not a netmail area, exit */
  36. do
  37.     foo = delete('T:pgptemp_a')
  38.     'requestnotify "You are not in a netmail area.'cr'Only netmail can be encrypted."'
  39.     IF (DelPGPPASS & ~NoDelPGPPASS) THEN foo=DELETE('Env:PGPPASS')
  40.     exit
  41. end
  42.  
  43. /* Do we have a key from this user? */
  44. address command PGPpath"PGP -kv >T:users"
  45. foo = open('file','T:users','R')
  46. ok = 0
  47. do until (ok > 0) | (eof('file'))
  48.     ok = pos(upper(to_name),upper(readln('file')))
  49. end
  50. foo = close('file')
  51. foo = delete('T:users')
  52. address spot
  53. if ok == 0 then /* Key not found! */
  54. do
  55.     foo = delete('T:pgptemp_a')    
  56.     'requestnotify "Public key of 'to_name' missing!"'
  57.     say "Please close window to quit."
  58.     IF (DelPGPPASS & ~NoDelPGPPASS) THEN foo=DELETE('Env:PGPPASS')
  59.     exit
  60. end
  61. 'clearflags EXPORT' /* We want only the encrypted msg to be exported */
  62.  
  63. /* Let's get the password */ 
  64. if ~exists("env:PGPPASS") then  /* We suppose that this password is correct, we do not test any further */
  65. do
  66.     foo = open('file','T:pgptemp_x','W')    /* This is a testfile */
  67.     foo = writeln('file','Testing...')
  68.     foo = close('file')
  69.     do until rc == 0     /* if rc = 0 , the password is valid */
  70.         address spot
  71.         'requeststring PROMPT "     Please give your password     " TITLE "Encryption" INVISIBLE'
  72.         if rc == 5 then  /* User pressed 'Cancel' */
  73.         do
  74.             foo = delete('T:pgptemp_x')
  75.             foo = delete('T:pgptemp_x.asc')
  76.             foo = delete('T:pgptemp_a')
  77.             foo = delete('env:PGPPASS')
  78.             'setflags EXPORT' /* We haven't encrypted anything, so this msg must be exported */
  79.             say "Please close window to quit."
  80.             IF (DelPGPPASS & ~NoDelPGPPASS) THEN foo=DELETE('Env:PGPPASS')
  81.             exit
  82.         end
  83.         address command ""setenv PGPPASS ""||result||""
  84.         /* Is it correct? */
  85.         address command PGPpath'PGP >NIL: +batchmode -sa T:pgptemp_x'
  86.         foo = delete('T:pgptemp_x.asc')
  87.     end
  88.     foo = delete('T:pgptemp_x')
  89. end
  90.  
  91. /* Delete the five first lines from the msg */
  92. foo = open('infile','T:pgptemp_a','R')
  93. foo = open('outfile','T:pgptemp_b','W')
  94. do x=1 to 5
  95.     foo = readln('infile')
  96. end
  97. foo = writeln('outfile','*** Subj: ' || subject || '0a'x)
  98. do while ~eof('infile')
  99.     instring = readln('infile')
  100.     foo = writeln('outfile',instring)
  101. end
  102. foo = close('infile')
  103. foo = close('outfile')
  104. foo = delete('T:pgptemp_a') /* We won't need this anymore */
  105.  
  106. /* Encrypt the msg with PGP */
  107. options failat 100
  108. address command PGPpath'PGP -esta T:pgptemp_b "'to_name'"'
  109. if rc ~= 0 then do
  110.     foo = delete('T:pgptemp_b')
  111.     foo = delete('T:pgptemp_b.asc')
  112.     say "Please close window to quit."
  113.     IF (DelPGPPASS & ~NoDelPGPPASS) THEN foo=DELETE('Env:PGPPASS')
  114.     exit
  115.     end
  116. foo = delete('T:pgptemp_b') /* We won't need this anymore */
  117.  
  118. /* Put the encrypted msg back into the msgbase */
  119. address spot
  120. 'write FILE T:pgptemp_b.asc REFLOW=OFF TO "'to_name'" TOADDR 'to_adres' FROM "'from_name'" SUBJECT "-- PGP --" NOEDIT NOGUI NOSIG'
  121. 'clearflags EXPORT' /* This msg should not to be exported */
  122. 'getmessagenum'     /* Get this msg number so we can jump back to it later */
  123. orig_msg = result
  124. 'lastmessage'       /* The (encrypted) msg we just wrote should be the last in the msgbase */
  125. 'setflags KILLSENT' /* Set the 'Kill/Sent' flag on */
  126. 'gotomessage "'orig_msg'"'  /* Go back to the original msg */
  127.  
  128. /* Delete the *.asc file in T: */
  129. foo = delete('T:pgptemp_b.asc')
  130.  
  131. /* Quit */
  132. say "Please close window to quit."
  133. IF (DelPGPPASS & ~NoDelPGPPASS) THEN foo=DELETE('Env:PGPPASS')
  134. exit
  135.