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

  1. /* Steward Digest Version 1.1 Build 8 */
  2. /*
  3.  * A digest processor for Steward 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. /* Variables normally read from the configuration file */
  19. /* These values are provided as defaults only */
  20. HomeDir = 'c:'
  21. LogDir = 'c:'
  22. ListDir = 'c:'
  23. Mailer = 'hmailer'
  24. WhereAmI = 'hostname'
  25. WhoAmI = Steward
  26. WhoAmIOwner = 'postmaster@'WhereAmI
  27. MasterPassword = 'steward'
  28.  
  29. /* The following are set on a per list basis */
  30. AdminPassword = 'steward-list'
  31. Administrivia = 0
  32. Owner = WhoAmIOwner
  33. Advertise = '*'
  34. ApprovePassword = 'steward-list'
  35. DoArchive = 0
  36. Moderated = 0
  37. NoList = 0
  38. Precedence = 1
  39. ListHeader = 1
  40. DoDigest = 0
  41. DigestVolume = 0
  42. DigestIssue = 0
  43. DigestName = 'steward-digest'
  44. DigestRmHeader = 1
  45. DigestFronter = 'digest.fronter'
  46. DigestFooter = 'digest.footer'
  47. SubscribePolicy = 'open'
  48. ReplyTo = ''
  49. SubjectPrefix = 'Steward-List: '
  50. DigestSubs = TRUE
  51. DigestDelete = TRUE
  52.  
  53. /* The external functions we need */
  54. call RxFuncAdd 'SysTempFileName', 'RexxUtil', 'SysTempFileName'
  55. call RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
  56. call RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
  57. call RxFuncAdd 'SysSleep', 'RexxUtil', 'SysSleep'
  58.  
  59. /* start main function */
  60. /* The argument to Digest is the digest listname to send out */
  61. parse arg Digest
  62.  
  63. /* Read the master configuration file now */
  64. call ReadMasterCf
  65.  
  66. /* change to the Steward Home Directory */
  67. Junk = directory(HomeDir)
  68.  
  69. /* Read the list configuration file */
  70. parse var Digest ListName '-' Other
  71. call ReadListCf(ListName)
  72.  
  73. /* Now send out the digest to the digest list members
  74.  * We're going to send yesterday's digest since today's
  75.  * is still being compiled.
  76.  */
  77.  
  78. DigestDay = ''
  79. DigestMon = ''
  80. DigestYear = ''
  81. DigestDate = ''
  82.  
  83. call GetDigestDate
  84.  
  85. /* create a temp file for the outgoing message */
  86. OutFile = SysTempFileName('f?????.tmp', '?');
  87. rc = stream(OutFile, 'C', 'OPEN WRITE')  /* open the file for writing */
  88.  
  89. call WriteHeaders
  90.  
  91. /* Write out a banner line with the digest date */
  92. rc = lineout(OutFile, '**************************************************', )
  93. rc = lineout(OutFile, '', )
  94. rc = lineout(OutFile, DigestName ' Volume' DigestVolume ' Issue' DigestIssue, )
  95. rc = lineout(OutFile, 'Digest Date ' DigestDate, )
  96. rc = lineout(OutFile, '', )
  97. rc = lineout(OutFile, '**************************************************', )
  98. rc = lineout(OutFile, '', )
  99.  
  100. /* Write out the subject lines if requested */
  101. if DigestSubs = TRUE then
  102.   do
  103.   FileName = ListDir'\'ListName'\Digests\'DigestYear'.'DigestMon'.'DigestDay'.subs'
  104.   rc = LockOpen(FileName 'READ')
  105.   if rc = TRUE then do
  106.     rc = lineout(OutFile, "Today's Subjects ---", )
  107.     do while lines(FileName) <> 0         /* until end of file */
  108.       Line = linein(FileName)             /* get a line of the file */
  109.       rc = lineout(OutFile, Line, )       /* output it */
  110.     end
  111.     rc = lineout(OutFile, '', )
  112.     rc = LockClose(FileName)
  113.   end
  114. end
  115.  
  116.  
  117. /* See if there is a fronter to prepend to the digest */
  118. if DigestFronter <> '' then do
  119.   FileName = ListDir'\'ListName'\Digests\'DigestFronter
  120.   rc = LockOpen(FileName 'READ')
  121.   if rc = TRUE then do
  122.     do while lines(FileName) <> 0         /* until end of file */
  123.       Line = linein(FileName)             /* get a line of the file */
  124.       rc = lineout(OutFile, Line, )       /* output it */
  125.     end
  126.     rc = LockClose(FileName)
  127.   end
  128. end
  129.  
  130. /* Now the digest file */
  131. FileName = ListDir'\'ListName'\Digests\'DigestYear'.'DigestMon'.'DigestDay
  132. /* open the file */
  133. rc = LockOpen(FileName 'READ')
  134. do while lines(FileName) <> 0         /* until end of file */
  135.   Line = linein(FileName)             /* get a line of the file */
  136.   rc = lineout(OutFile, Line, )       /* output it */
  137. end
  138. rc = stream(FileName, 'C', 'CLOSE')
  139.  
  140. /* See if there is a footer to append to the digest */
  141. if DigestFooter <> '' then do
  142.   FileName = ListDir'\'ListName'\Digests\'DigestFooter
  143.   rc = LockOpen(FileName 'READ')
  144.   if rc = TRUE then do
  145.     do while lines(FileName) <> 0         /* until end of file */
  146.       Line = linein(FileName)             /* get a line of the file */
  147.       rc = lineout(OutFile, Line, )       /* output it */
  148.     end
  149.     rc = LockClose(FileName)
  150.   end
  151. end
  152.  
  153. rc = stream(OutFile, 'C', 'CLOSE')  /* close the output file */
  154.  
  155. /* now create the file with the email addresses in it */
  156. FileName = ListDir'\'ListName'\'ListName'.digest'
  157. /* make sure there is a file for email addresses */
  158. rc = SysFileTree(FileName, s., 'FO')
  159. if rc = 0 & s.0 = 0 then do
  160.   say 'Nobody to send digest to.'
  161.   call IncrementIssue(DigestIssue)
  162.   call SysFileDelete(OutFile)
  163.   exit
  164.   end
  165. /* create a temp file for the email addresses */
  166. EmailFile = SysTempFileName('e?????.tmp', '?');
  167. /* copy the list's email addresses to the temporary name */
  168. rc = CopyLock(FileName EmailFile)
  169.  
  170. /* start the mail program to send the message out */
  171. Mailer ListName'-owner@'WhereAmI EmailFile OutFile
  172.  
  173. /* Now increment the issue number in the list configuration file */
  174. call IncrementIssue(DigestIssue)
  175.  
  176. if DigestDelete = TRUE then
  177.   do
  178.   FileName = ListDir'\'ListName'\Digests\'DigestYear'.'DigestMon'.'DigestDay
  179.   rc = SysFileDelete(FileName)
  180.   FileName = FileName'.subs'
  181.   rc = SysFileDelete(FileName)
  182.   end
  183.  
  184. exit
  185.  
  186. /* ------------------------------------------------------------------ */
  187. /*
  188.  * Write out our standard headers for a digest
  189.  *
  190.  */
  191.  
  192. WriteHeaders:  /* note that we have full access to all globals here */
  193.  
  194. TimeZone = value( 'TZ', , Env)
  195. TmpTime = time('N')
  196. DayOfWeek = date('W')
  197. DayOfWeek = left(DayOfWeek, 3)
  198. TmpDate = date('N')
  199.  
  200. rc = lineout(OutFile, 'Date:' DayOfWeek',' TmpDate TmpTime TimeZone, )
  201. rc = lineout(OutFile, 'Sender:' ListName'-owner' '<'ListName'-owner@'WhereAmI'>', )
  202. rc = lineout(OutFile, 'From:' Digest '<'Digest'@'WhereAmI'>', )
  203. rc = lineout(OutFile, 'Reply-To:' Digest '<'Digest'@'WhereAmI'>', )
  204. rc = lineout(OutFile, 'Subject:' DigestName, )
  205. if ListHeader = TRUE then
  206.   rc = lineout(OutFile, 'X-ListName:' DigestName, )
  207. rc = lineout(OutFile, '', )
  208.  
  209. return
  210.  
  211. /* ------------------------------------------------------------------ */
  212.  
  213. GetDigestDate: procedure expose DigestDay DigestMon DigestYear DigestDate
  214.  
  215. /* Today's date */
  216. TmpDate = date('E')
  217. parse var TmpDate TmpDay '/' TmpMon '/' TmpYear
  218.  
  219. /* We must check the single digit dates because simple math
  220.  * will make them single digits and we'll get the wrong filename.
  221.  */
  222. select
  223.   when TmpDay = '01' then DigestDay = '00'  /* We'll catch it below */
  224.   when TmpDay = '02' then DigestDay = '01'
  225.   when TmpDay = '03' then DigestDay = '02'
  226.   when TmpDay = '04' then DigestDay = '03'
  227.   when TmpDay = '05' then DigestDay = '04'
  228.   when TmpDay = '06' then DigestDay = '05'
  229.   when TmpDay = '07' then DigestDay = '06'
  230.   when TmpDay = '08' then DigestDay = '07'
  231.   when TmpDay = '09' then DigestDay = '08'
  232.   when TmpDay = '10' then DigestDay = '09'
  233.   otherwise DigestDay = TmpDay - 1
  234. end
  235.  
  236. DigestMon = TmpMon
  237. DigestYear = TmpYear
  238.  
  239. if DigestDay < 1 then do
  240.   select
  241.     when TmpMon = '01' then do  /* January */
  242.       DigestYear = TmpYear - 1
  243.       DigestMon = '12'          /* December */
  244.       DigestDay = '31'
  245.       end
  246.     when TmpMon = '02' then do  /* February */
  247.       DigestMon = '01'          /* January */
  248.       DigestDay = '31'
  249.       end
  250.     when TmpMon = '03' then do  /* March */
  251.       DigestMon = '02'          /* February */
  252.       if ( (0 = (DigestYear // 4)) & (0 <> (DigestYear // 100)) ) |,
  253.          ( (0 = (DigestYear // 400) ) then
  254.         DigestDay = '29'
  255.       else
  256.         DigestDay = '28'
  257.       end
  258.     when TmpMon = '04' then do  /* April */
  259.       DigestMon = '03'          /* March */
  260.       DigestDay = '31'
  261.       end
  262.     when TmpMon = '05' then do  /* May */
  263.       DigestMon = '04'          /* April */
  264.       DigestDay = '30'
  265.       end
  266.     when TmpMon = '06' then do  /* June */
  267.       DigestMon = '05'          /* May */
  268.       DigestDay = '31'
  269.       end
  270.     when TmpMon = '07' then do  /* July */
  271.       DigestMon = '06'          /* June */
  272.       DigestDay = '30'
  273.       end
  274.     when TmpMon = '08' then do  /* August */
  275.       DigestMon = '07'          /* July */
  276.       DigestDay = '31'
  277.       end
  278.     when TmpMon = '09' then do  /* September */
  279.       DigestMon = '08'          /* August */
  280.       DigestDay = '31'
  281.       end
  282.     when TmpMon = '10' then do  /* October */
  283.       DigestMon = '09'          /* September */
  284.       DigestDay = '30'
  285.       end
  286.     when TmpMon = '11' then do  /* November */
  287.       DigestMon = '10'          /* October */
  288.       DigestDay = '31'
  289.       end
  290.     when TmpMon = '12' then do  /* December */
  291.       DigestMon = '11'          /* November */
  292.       DigestDay = '30'
  293.       end
  294.     otherwise
  295.       nop
  296.   end  /* select */
  297. end  /* endif */
  298.  
  299. TmpWkDay = date('W')
  300.  
  301. select
  302.   when TmpWkDay = 'Sunday' then
  303.     TmpWkDay = 'Saturday'
  304.   when TmpWkDay = 'Monday' then
  305.     TmpWkDay = 'Sunday'
  306.   when TmpWkDay = 'Tuesday' then
  307.     TmpWkDay = 'Monday'
  308.   when TmpWkDay = 'Wednesday' then
  309.     TmpWkDay = 'Tuesday'
  310.   when TmpWkDay = 'Thursday' then
  311.     TmpWkDay = 'Wednesday'
  312.   when TmpWkDay = 'Friday' then
  313.     TmpWkDay = 'Thursday'
  314.   when TmpWkDay = 'Saturday' then
  315.     TmpWkDay = 'Friday'
  316.   otherwise
  317.     TmpWkDay = ''
  318. end
  319.  
  320. select
  321.   when DigestMon = '01' then
  322.     TmpMon = 'January'
  323.   when DigestMon = '02' then
  324.     TmpMon = 'February'
  325.   when DigestMon = '03' then
  326.     TmpMon = 'March'
  327.   when DigestMon = '04' then
  328.     TmpMon = 'April'
  329.   when DigestMon = '05' then
  330.     TmpMon = 'May'
  331.   when DigestMon = '06' then
  332.     TmpMon = 'June'
  333.   when DigestMon = '07' then
  334.     TmpMon = 'July'
  335.   when DigestMon = '08' then
  336.     TmpMon = 'August'
  337.   when DigestMon = '09' then
  338.     TmpMon = 'September'
  339.   when DigestMon = '10' then
  340.     TmpMon = 'October'
  341.   when DigestMon = '11' then
  342.     TmpMon = 'November'
  343.   when DigestMon = '12' then
  344.     TmpMon = 'December'
  345.   otherwise
  346.     TmpMon = DigestMon
  347. end
  348.  
  349. DigestDate = TmpWkDay DigestDay TmpMon DigestYear
  350.  
  351. return
  352.  
  353. /* ------------------------------------------------------------------ */
  354. /*
  355.  * Read the master configuration file
  356.  *
  357.  */
  358.  
  359. ReadMasterCf: procedure expose HomeDir LogDir ListDir Mailer WhereAmI WhoAmI ,
  360.               WhoAmIOwner MasterPassword Env TRUE FALSE
  361.  
  362. /* Find out where the configuration file should be */
  363. StewardCf = value('steward_cf',,Env)
  364.  
  365. /* If its not defined then assume wherever we are */
  366. if StewardCf = '' then do
  367.   StewardCf = '.'
  368.   end
  369.  
  370. FileName = StewardCf'\steward.cf'
  371.  
  372. rc = LockOpen(FileName 'READ')  /* open the file locking it */
  373. if rc = FALSE then
  374.   return FALSE                   /* return FALSE if cannot open */
  375.  
  376. /* now read the configuration file */
  377. do while lines(FileName) <> 0         /* until end of file */
  378.   Line = linein(FileName)             /* get a line of the file */
  379.   parse var Line Line '#' Comment     /* separate out any comments */
  380.   if Line <> '' then do               /* if not null */
  381.     parse var Line Key '=' Val        /* find the key and value */
  382.     if Key <> '' then do
  383.       Val = strip(Val, 'B', ' ')      /* remove any blanks */
  384.       Key = strip(Key, 'B', ' ')
  385. /*      say Key '=' Val */
  386.       select
  387.         when Key = 'HomeDir' then
  388.           HomeDir = Val
  389.         when Key = 'LogDir' then
  390.           LogDir = Val
  391.         when Key = 'ListDir' then
  392.           ListDir = Val
  393.         when Key = 'Mailer' then
  394.           Mailer = Val
  395.         when Key = 'WhereAmI' then
  396.           WhereAmI = Val
  397.         when Key = 'WhoAmI' then
  398.           WhoAmI = Val
  399.         when Key = 'WhoAmIOwner' then
  400.           WhoAmIOwner = Val
  401.         when Key = 'MasterPassword' then
  402.           MasterPassword = Val
  403.         otherwise nop
  404.         end   /* select */
  405.       end     /* if Key <> '' */
  406.     end       /* if Line <> '' */
  407.  
  408.   Key = ''
  409.  
  410. end /* end do while */
  411.  
  412. rc = LockClose(FileName)
  413.  
  414. return TRUE
  415.  
  416. /* ------------------------------------------------------------------ */
  417. /*
  418.  * Read the per list configuration file
  419.  *
  420.  */
  421.  
  422. ReadListCf: procedure expose ListDir AdminPassword ListOwner Administrivia,
  423.             Advertise ApprovePassword DoArchive Moderated NoList Precedence,
  424.             ListHeader SubscribePolicy ReplyTo SubjectPrefix TRUE FALSE,
  425.             DoDigest DigestRmHeader DigestVolume DigestIssue DigestFronter,
  426.             DigestFooter DigestName DigestSubs DigestDelete
  427.  
  428. parse arg ListName
  429.  
  430. FileName = ListDir'\'ListName'\'ListName'.cf'
  431. rc = LockOpen(FileName 'READ')  /* open the file locking it */
  432. if rc = FALSE then
  433.   return FALSE                   /* return FALSE if cannot open */
  434.  
  435. /* now read the configuration file */
  436. do while lines(FileName) <> 0         /* until end of file */
  437.   Line = linein(FileName)             /* get a line of the file */
  438.   parse var Line Line '#' Comment     /* separate out any comments */
  439.   if Line <> '' then do               /* if not null */
  440.     parse var Line Key '=' Val        /* find the key and value */
  441.     if Key <> '' then do
  442.       Val = strip(Val, 'B', ' ')      /* remove any blanks */
  443.       Key = strip(Key, 'B', ' ')
  444. /*      say Key '=' Val */
  445.       select
  446.         when Key = 'AdminPassword' then
  447.           AdminPassword = Val
  448.         when Key = 'ListOwner' then
  449.           ListOwner = Val
  450.         when Key = 'Administrivia' then
  451.           Administrivia = Val
  452.         when Key = 'Advertise' then
  453.           Advertise = Val
  454.         when Key = 'ApprovePassword' then
  455.           ApprovePassword = Val
  456.         when Key = 'DoArchive' then
  457.           DoArchive = Val
  458.         when Key = 'Moderated' then
  459.           Moderated = Val
  460.         when Key = 'NoList' then
  461.           NoList = Val
  462.         when Key = 'Precedence' then
  463.           Precedence = Val
  464.         when Key = 'ListHeader' then
  465.           ListHeader = Val
  466.         when Key = 'SubscribePolicy' then
  467.           SubscribePolicy = Val
  468.         when Key = 'ReplyTo' then
  469.           ReplyTo = Val
  470.         when Key = 'SubjectPrefix' then
  471.           SubjectPrefix = Val
  472.         when Key = 'DoDigest' then
  473.           DoDigest = Val
  474.         when Key = 'DigestRmHeader' then
  475.           DigestRmHeader = Val
  476.         when Key = 'DigestVolume' then
  477.           DigestVolume = Val
  478.         when Key = 'DigestIssue' then
  479.           DigestIssue = Val
  480.         when Key = 'DigestName' then
  481.           DigestName = Val
  482.         when Key = 'DigestFronter' then
  483.           DigestFronter = Val
  484.         when Key = 'DigestFooter' then
  485.           DigestFooter = Val
  486.         when Key = 'DigestSubs' then
  487.           DigestSubs = Val
  488.         when Key = 'DigestDelete' then
  489.           DigestDelete = Val
  490.         otherwise nop
  491.         end   /* select */
  492.       end     /* if Key <> '' */
  493.     end       /* if Line <> '' */
  494.  
  495.   Key = ''
  496.  
  497. end /* end do while */
  498.  
  499. rc = LockClose(FileName)
  500.  
  501. return TRUE
  502.  
  503. /* ------------------------------------------------------------------ */
  504.  
  505. IncrementIssue: procedure expose TRUE FALSE ListDir ListName
  506.  
  507. parse arg CurIssue
  508.  
  509. NextIssue = CurIssue + 1
  510.  
  511. /* create a temp file for the outgoing message */
  512. TmpFile = SysTempFileName('t?????.tmp', '?');
  513. rc = stream(TmpFile, 'C', 'OPEN WRITE')  /* open the file for writing */
  514.  
  515. FileName = ListDir'\'ListName'\'ListName'.cf'
  516. rc = LockOpen(FileName 'READ')  /* open the file locking it */
  517. if rc = FALSE then
  518.   return FALSE                   /* return FALSE if cannot open */
  519.  
  520. /* now read the configuration file */
  521. do while lines(FileName) <> 0         /* until end of file */
  522.   Line = linein(FileName)             /* get a line of the file */
  523.   parse var Line Key '=' Val '#' Comment
  524.   Key = strip(Key, 'B', ' ')
  525.   if Key = 'DigestIssue' then
  526.     rc = lineout(TmpFile, 'DigestIssue =' NextIssue, )
  527.   else
  528.     rc = lineout(TmpFile, Line, )
  529. end
  530.  
  531. /* Close the files in current mode */
  532. rc = LockClose(FileName)
  533. rc = stream(TmpFile, 'C', 'CLOSE')
  534.  
  535. rc = CopyLock(TmpFile FileName)
  536.  
  537. rc = SysFileDelete(TmpFile)
  538.  
  539. return
  540.  
  541. /* ------------------------------------------------------------------ */
  542.  
  543.  
  544.  
  545.  
  546.