home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / IMPRO / STEWARD.ZIP / digest.cmd < prev    next >
OS/2 REXX Batch file  |  1997-08-09  |  17KB  |  583 lines

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