home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / steward8.zip / Steward.cmd < prev    next >
OS/2 REXX Batch file  |  1996-06-27  |  7KB  |  261 lines

  1. /* Steward Version 1.1 Build 8 */
  2. /*
  3.  * A mailing list processor in Rexx by Paul Hethmon
  4.  *
  5.  */
  6.  
  7. /* variable declarations */
  8.  
  9. Steward = 'Steward'
  10. StewardVersion = 'Version 1.1 Build 8'
  11. StewardDate = '26 June 1996'
  12. uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  13. lowercase = 'abcdefghijklmnopqrstuvwxyz'
  14. Env = 'OS2ENVIRONMENT'
  15. FALSE = 0
  16. TRUE = 1
  17.  
  18. /* Set to 1 to enable debug output */
  19. Debug = TRUE
  20. /* Set to 1 to enable logging */
  21. Log = TRUE
  22. LogFile = ''
  23. ETime1 = 0
  24. ETime2 = 0
  25. Author = ''
  26. AdminFile = ''
  27. AdminSubject = ''
  28. AdminTo = ''
  29.  
  30. /* Variables normally read from the configuration file */
  31. /* These values are provided as defaults only */
  32. HomeDir = 'c:'
  33. LogDir = 'c:'
  34. ListDir = 'c:'
  35. Mailer = 'hmailer'
  36. WhereAmI = 'hostname'
  37. WhoAmI = Steward
  38. WhoAmIOwner = 'postmaster@'WhereAmI
  39. MasterPassword = 'steward'
  40.  
  41. /* The external functions we need */
  42. call RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
  43.  
  44. /* start main function */
  45. /* The first arg is who the message was sent to.
  46.  * The second is the filename. We're responsible
  47.  * for cleaning up the file if needed.
  48.  */
  49. parse arg Rcpt MsgFile
  50.  
  51. parse var Rcpt Rcpt '@' Domain
  52. if Debug = TRUE then say 'Rcpt =' Rcpt 'MsgFile =' MsgFile
  53.  
  54. call on error name ErrHandler
  55.  
  56. say 'Reading Master Configuration File Now.'
  57.  
  58. /* Read the master configuration file now */
  59. rc = ReadMasterCf()
  60. if rc = FALSE then
  61.   do
  62.   say 'Unable to read master configuration file. Failing.'
  63.   ErrFile = SysTempFileName('?????.err', '?')
  64.   rc = stream(ErrFile, 'C', 'OPEN WRITE')
  65.   rc = lineout(ErrFile, 'Steward Error File', )
  66.   rc = lineout(ErrFile, 'You must rerun Steward with the recipient name and', )
  67.   rc = lineout(ErrFile, 'message file name listed below in order to process', )
  68.   rc = lineout(ErrFile, 'this message.', )
  69.   rc = lineout(ErrFile, 'Rcpt =' Rcpt, )
  70.   rc = lineout(ErrFile, 'MsgFile =', MsgFile, )
  71.   rc = stream(ErrFile, 'C', 'CLOSE')
  72.   exit
  73.   end
  74.  
  75. /* change to the Steward Home Directory */
  76. Junk = directory(HomeDir)
  77.  
  78. if Debug = TRUE then
  79.   do
  80.   say 'LogDir =' LogDir
  81.   say 'HomeDir = ' HomeDir
  82.   say 'ListDir =' ListDir
  83.   say 'Junk =' Junk
  84.   end
  85.  
  86. /* figure out who got the message */
  87. Rcpt = translate(Rcpt, lowercase, uppercase)
  88. WhoAmI = translate(WhoAmI, lowercase, uppercase)
  89.  
  90. /* In case its a request, digest, or owner message */
  91. if pos('-request', Rcpt, ) > 0 then do
  92.   parse var Rcpt List '-request'
  93.   RequestType = 'request'
  94.   end
  95. else if pos('-digest', Rcpt, ) > 0 then do
  96.   parse var Rcpt List '-digest'
  97.   RequestType = 'digest'
  98.   end
  99. else if pos('-owner', Rcpt, ) > 0 then do
  100.   parse var Rcpt List '-owner'
  101.   RequestType = 'owner'
  102.   end
  103. else if pos('-errors', Rcpt, ) > 0 then do
  104.   parse var Rcpt List '-errors'
  105.   RequestType = 'errors'
  106.   end
  107. else do
  108.   List = Rcpt
  109.   RequestType = 'list'
  110.   end
  111.  
  112. /* now find out if it was to steward or one of the lists */
  113. if RequestType = 'request' then do
  114.   /* process this message with the list and admin specific filter */
  115.   if Debug = TRUE then do
  116.     say 'Processing Admin request'
  117.     say 'Recipient was a request for:' List
  118.     end
  119.   call Admin(List MsgFile)
  120.   end
  121. else if RequestType = 'digest' then do
  122.   /* process this as a digest submission */
  123.   if Debug = TRUE then do
  124.     say 'Processing Message request'
  125.     say 'Recipient was a digest:' Rcpt
  126.     end
  127.   call Message(List MsgFile)
  128.   end
  129. else if RequestType = 'owner' then do
  130.   /* process this as an admin request */
  131.   if Debug = TRUE then do
  132.     say 'Processing Owner request'
  133.     say 'Recipient was an owner:' Rcpt
  134.     end
  135.   call Errors(List MsgFile)
  136.   end
  137. else if RequestType = 'errors' then do
  138.   /* Process this as an error return */
  139.   if Debug = TRUE then do
  140.     say 'Processing Errors request'
  141.     say 'Recipient was to errors:' Rcpt
  142.     end
  143.   call Errors(List MsgFile)
  144.   end
  145. else if Rcpt = WhoAmI then do
  146.   /* process this message with the admin filter */
  147.   if Debug = TRUE then do 
  148.     say 'Processing Admin request'
  149.     say 'Recipient was' WhoAmI
  150.     end
  151.   call Admin(Rcpt MsgFile)
  152.   end
  153. else do
  154.   /* process this as a message to the list */
  155.   if Debug = TRUE then do
  156.     say 'Processing List request'
  157.     say 'Recipient was a list:' List
  158.     end
  159.   call Message(List MsgFile)
  160.   end
  161.  
  162. /* Make sure the tmp file is deleted */
  163. rc = SysFileDelete(MsgFile)
  164.  
  165. exit
  166.  
  167. /* ------------------------------------------------------------------ */
  168. /*
  169.  * Read the master configuration file
  170.  *
  171.  */
  172.  
  173. ReadMasterCf: procedure expose HomeDir LogDir ListDir Mailer WhereAmI WhoAmI ,
  174.               WhoAmIOwner MasterPassword Env TRUE FALSE Debug
  175.  
  176. if Debug = TRUE then say 'Reading Steward configuration file.'
  177.  
  178. /* Find out where the configuration file should be */
  179. StewardCf = value('steward_cf',,Env)
  180. /* StewardCf = value('steward_cf_test',,Env) */
  181.  
  182. /* If its not defined then assume wherever we are */
  183. if StewardCf = '' then do
  184.   StewardCf = '.'
  185.   end
  186.  
  187. FileName = StewardCf'\steward.cf'
  188.  
  189. rc = LockOpen(FileName 'READ')  /* open the file locking it */
  190. if rc = FALSE then
  191.   return FALSE                   /* return FALSE if cannot open */
  192.  
  193. /* now read the configuration file */
  194. do while lines(FileName) <> 0         /* until end of file */
  195.   Line = linein(FileName)             /* get a line of the file */
  196.   parse var Line Line '#' Comment     /* separate out any comments */
  197.   if Line <> '' then do               /* if not null */
  198.     parse var Line Key '=' Val        /* find the key and value */
  199.     if Key <> '' then do
  200.       Val = strip(Val, 'B', ' ')      /* remove any blanks */
  201.       Key = strip(Key, 'B', ' ')
  202.       select
  203.         when Key = 'HomeDir' then
  204.           do
  205.           HomeDir = Val
  206.           end
  207.         when Key = 'LogDir' then
  208.           do
  209.           LogDir = Val
  210.           end
  211.         when Key = 'ListDir' then
  212.           do
  213.           ListDir = Val
  214.           end
  215.         when Key = 'Mailer' then
  216.           Mailer = Val
  217.         when Key = 'WhereAmI' then
  218.           WhereAmI = Val
  219.         when Key = 'WhoAmI' then
  220.           WhoAmI = Val
  221.         when Key = 'WhoAmIOwner' then
  222.           WhoAmIOwner = Val
  223.         when Key = 'MasterPassword' then
  224.           MasterPassword = Val
  225.         otherwise nop
  226.         end   /* select */
  227.       end     /* if Key <> '' */
  228.     end       /* if Line <> '' */
  229.  
  230.   Key = ''
  231.  
  232. end /* end do while */
  233.  
  234. rc = LockClose(FileName)
  235.  
  236. if Debug = TRUE then say 'Steward.cf file read.'
  237.  
  238. return TRUE
  239.  
  240. /* ------------------------------------------------------------------ */
  241.  
  242. ErrHandler:
  243.  
  244. SIGerrCode = RC
  245. StewardErrLog = 'Steward.err'
  246.  
  247. if Debug = TRUE then say 'Identified error while executing line #'Sigl'   RC = ['SIGerrCode']'
  248. if Debug = TRUE then say '['SourceLine(Sigl)']'
  249. rc = lineout( StewardErrLog, '     -----', )
  250. rc = lineout( StewardErrLog, 'Error ['SIGerrCode'] while executing line #'Sigl, )
  251. rc = lineout( StewardErrLog, '['SourceLine(Sigl)']')
  252.  
  253. return
  254.  
  255.  
  256. /* ------------------------------------------------------------------ */
  257. /* ------------------------------------------------------------------ */
  258. /* ------------------------------------------------------------------ */
  259.  
  260.  
  261.