home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1998 February / PCOnline_02_1998.iso / filesbbs / os2 / pgprex12.arj / PGPREXX.ZIP / PGPENCOD.CMD < prev    next >
Encoding:
Text File  |  1996-08-08  |  5.4 KB  |  206 lines

  1. /* REXX Begin PGPENCOD MAIN  Version 1.2 */
  2. /* CopyRight Lueko Willms <lueko.willms@T-Online.de>
  3.                           <L.WILLMS@LINK-F.rhein-main.de>
  4. */
  5.  
  6. parse arg OutMail DEBUG PGPpassOpt 
  7. Outmail = strip(translate(outmail))
  8.  
  9. DEBUG = (strip(translate(DEBUG)) = 'DEBUG')
  10. TRUE = 1
  11. FALSE = 0
  12. PARSE SOURCE BetrSyst Shell MyName
  13. MyDir = FILESPEC("Drive",MyName)||FILESPEC("Path",MyName)
  14.  
  15. If DEBUG then
  16.   DO
  17.   PARSE SOURCE BetrSyst Shell MyName
  18.   Erg = STREAM('DEBUGS.DAT','C','OPEN WRITE')
  19.   Erg = LINEOUT('DEBUGS.DAT',BetrSyst||' '||Shell||'::'||ADDRESS()||' '||MyName)
  20.   Erg = STREAM('DEBUGS.DAT','C','CLOSE')
  21.   END
  22.  
  23. /* ------------------------- Build Table of known PGP key users -------- */
  24. 'pgp -kv | RXQUEUE'
  25. DO 4
  26.    Call LINEIN 'QUEUE:'
  27. END
  28.  
  29. pgpKeyUser.0 = 0
  30. DO UNTIL QUEUED() = 1
  31.   pgpKeyUser.0 = pgpKeyUser.0 + 1
  32.   i = pgpKeyUser.0
  33.   pgpKeyUser.i = TRANSLATE(SUBSTR(LINEIN('QUEUE:'),31))
  34.   If DEBUG then
  35.      SAY pgpKeyUser.i
  36. END
  37. Call LINEIN 'QUEUE:'   /* Flush the Queue */
  38.  
  39. If DEBUG then
  40.   DO
  41.   Say pgpKeyUser.0 ' PGP userids in your keyring/PGP Benutzer in Deinem Schlüsselbund.'
  42.   Call SAYADDRESS "pgpKeyUser"
  43.   END
  44.  
  45.  
  46. /* ------------------------ Build Table of this message's recipients ------ */
  47.  
  48. Recipient.0 = 0
  49. From.0 = 0
  50. Sender.0 = 0
  51. MsgId = ''
  52.  
  53. Erg = STREAM(Outmail,'C','OPEN READ')
  54. If DEBUG Then
  55.   Say 'Ergebnis von OPEN ' Outmail ':' Erg
  56.  
  57.  
  58. Zeile = linein(OutMail)
  59. ContLine = FALSE
  60. DO WHILE Length(Zeile) > 0
  61.     /* Beachte Fortsetzungszeilen!! */
  62.     ContLine = ContLine & (LEFT(Zeile,1) = ' ' | LEFT(Zeile,1) = '09'x)
  63.     Zeile = STRIP(Zeile)
  64.     If \ ContLine then
  65.        DO
  66.        Tag = TRANSLATE(WORD(Zeile,1))
  67.        Zeile = Delstr(Zeile,1,Length(Tag))
  68.        END
  69.  
  70.     If RIGHT(Zeile,1) = ',' then
  71.        DO
  72.        ContLine = TRUE                                 /* for the next line... */
  73.        Zeile = DELSTR(Zeile,Length(Zeile),1)
  74.        END
  75.  
  76.     SELECT
  77.       When (Tag = 'TO:' | Tag = 'CC:' | Tag = 'BCC:') then
  78.        DO
  79.        Call GETADDRESS "Recipient" zeile
  80.        END
  81.       When (Tag = 'FROM:') then
  82.         Do
  83.         Call GETADDRESS "From" zeile
  84.         End
  85.       When (Tag = 'SENDER:') then
  86.         Do
  87.         Call GETADDRESS "Sender" zeile
  88.         End
  89.       When (Tag = 'MESSAGE-ID:') then
  90.         DO
  91.         MsgId = Zeile
  92.         end /* do */
  93.       Otherwise
  94.         NOP
  95.     END /* Switch */
  96.  
  97.     Zeile = linein(OutMail)
  98. END /* Do Header */
  99.  
  100. Erg = STREAM(Outmail,'C','CLOSE')
  101.  
  102. If DEBUG then
  103.   DO
  104.   Say MyName 'Ergebnis von CLOSE ' Outmail ':' Erg
  105.   Call SAYADDRESS "Recipient"
  106.   Call SAYADDRESS "From"
  107.   Call SAYADDRESS "Sender"
  108. /*  Call SAYADDRESS "pgpKeyUser" */
  109.   END
  110.  
  111. /* ----------- Check if we have a key for every recipient. If yes, we encrypt, otherwise only sign */
  112. Encrypt = 1       /* 1 = TRUE */
  113.  
  114. Do i = 1 to Recipient.0 UNTIL Encrypt = 0
  115.    ThisOne = 0
  116.    Do j = 1 to pgpKeyUser.0 UNTIL ThisOne = 1
  117.       ThisOne = MAX(ThisOne,POS(Recipient.i,pgpKeyUser.j))
  118.       If DEBUG then
  119.          SAY '??' Recipient.i '<?>' pgpKeyUser.j
  120.    end /* do */
  121.    Encrypt = MIN(Encrypt,ThisOne)
  122. END
  123.  
  124. PGPreceivers = ' '
  125. If Encrypt then
  126.    DO
  127.       PGPopt = 'e'
  128.       DO i = 1 to Recipient.0
  129.         PGPreceivers = PGPreceivers||Recipient.i||' '
  130.       end /* do */
  131.    END /* Encrypt = TRUE */
  132. Else
  133.    PGPopt = ''
  134.  
  135. /* -------------------------------------------------------- */
  136. PGPopt = PGPopt||'s'
  137.  
  138. Signuser = '-u '
  139. If Sender.0 > 0 then
  140.    signuser = signuser || VALUE(Sender||'.'||Sender.0)
  141. else
  142.    signuser = signuser || VALUE(From||'.'||From.0)
  143.  
  144. If DEBUG then
  145.    BugPar = 'DEBUG'
  146. else
  147.    BugPar = ''
  148.  
  149. MyDir'SPLTMAIL.cmd '||OutMail BugPar||' | '||MyDir||'PGPexec.CMD -fat'||PGPopt||PGPreceivers||signuser||PGPpassOpt' | '||MyDir||'joinmail.cmd '||OutMail BugPar
  150.  
  151. /* Do logging ---------------------------------------------- 
  152. Erfolg = RC
  153. Tab = '09'x
  154. LogFile = MyDir||'PGPREXX.LOG'
  155. Erg = STREAM(LogFile,'C','OPEN WRITE')
  156. Erg = LINEOUT(LogFile,Date('O')||' '||Time()||Tab||'>>>'||Tab||MsgId||Tab||Erfolg||Tab||SignUser||Tab||PGPreceivers)
  157. Erg = STREAM(LogFile,'C','CLOSE')
  158. */
  159.  
  160. If DEBUG  then
  161.   DO
  162.   Say 'Hallo! Gib ENTER:'
  163.   parse pull dings
  164.   END
  165. exit
  166. /* END REXX ENCODE MAIN */
  167.  
  168. /* ----- subprogram to unstring header lines and build address stem variables --- */
  169. GETADDRESS:
  170. parse arg tabelle hdrline
  171. hdrline = strip(hdrline)
  172.  
  173. Anzahl = 0
  174. Gesamtzahl = VALUE(Tabelle||'.0')
  175. DO While Length(hdrline) > 0
  176.    Anfang = LASTPOS(',',hdrline) + 1
  177.    Anzahl = Anzahl + 1
  178.    Gesamtzahl = Gesamtzahl + 1
  179.    If DEBUG then
  180.       Say Gesamtzahl ':' hdrline
  181.    Erg = VALUE(Tabelle||'.0',Gesamtzahl)
  182.    TempAddr = TRANSLATE(Strip(SUBSTR(hdrline,Anfang)))
  183.    SpAuf = POS('<',TempAddr)                     /* search for mailbox address in line */
  184.    SpZu  = LASTPOS('>',TempAddr)
  185.    If ( SpAuf > 0 & SpZu > 0) then
  186.        TempAddr = SUBSTR(TempAddr,SpAuf+1,SpZu-SpAuf-1)
  187.    If RIGHT(TempAddr,1) = ')' then               /* Address has a comment */
  188.       DO
  189.       KlAuf = LASTPOS('(',TempAddr)
  190.       TempAddr = STRIP(DELSTR(TempAddr,KlAuf))
  191.       end /* do */
  192.    /*                                               Adress processing complete */
  193.    Erg = VALUE(Tabelle||'.'||Gesamtzahl,TempAddr)
  194.    hdrline = DELSTR(hdrline,MAX(1,Anfang-1))
  195. END /* WHILE */
  196. RETURN Anzahl
  197.  
  198. SAYADDRESS:
  199. /* for DEBUG purposes */
  200. parse arg tabelle
  201. Gesamtzahl = VALUE(Tabelle||'.0')
  202. DO i = 1 to Gesamtzahl
  203.    SAY tabelle':' VALUE(tabelle||'.'||i)
  204. END
  205. RETURN
  206.