home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / comm / bbbbs-7.2.lha / BBBBS / BBBBS72.lha / rexx / ArcMsgs.rexx < prev    next >
OS/2 REXX Batch file  |  1994-02-12  |  10KB  |  419 lines

  1. /*         $VER: ArcMsgs.rexx 6.7 (12.2.94)
  2. archives unread conference messages into file in users email
  3.    © 1990-94 Richard Lee Stockton - FREELY DISTRIBUTABLE
  4. */
  5.  
  6. SIGNAL ON BREAK_C
  7. SIGNAL ON ERROR
  8. SIGNAL ON SYNTAX
  9. OPTIONS FAILAT 999999
  10.  
  11. PARSE ARG name' 'single_dir' '.
  12. IF STRIP(single_dir)='' THEN single_dir=0
  13. IF name='' THEN CALL GETOUT(20)
  14.  
  15. CALL CLOSE(STDOUT)
  16. CALL OPEN(STDOUT,'RAM:ArcMsgs.STDOUT','W')
  17. SAY STRIP(SUBSTR(SOURCELINE(1),3))
  18. SAY
  19. CALL TIME('R')
  20.  
  21. figarg='s:CONFIG.BBS'
  22. IF ~EXISTS(figarg) THEN figarg='BBS:BBS_TEXT/CONFIG.BBS'
  23. x=OPEN(f,figarg,'R')
  24. IF x=0 THEN
  25.   DO
  26.     SAY 's:CONFIG.BBS and BBS:BBS/CONFIG.BBS are both missing!'
  27.     CALL GETOUT(21)
  28.   END
  29.  
  30. data.=''
  31. DO i=1 TO 33
  32.   data.i=READLN(f)
  33. END
  34. CALL CLOSE(f)
  35.  
  36. compos=POS('/*',data.1)
  37. IF compos>0 THEN data.1=LEFT(data.1,compos-1)
  38. bbsname = STRIP(data.1)
  39. sysop   = WORD(data.2,1)
  40. bbspath = WORD(data.6,1)
  41. IF ~EXISTS(bbspath) THEN
  42.   DO
  43.     SAY bbspath 'does not exist!'
  44.     CALL GETOUT(22)
  45.   END
  46. testchar=RIGHT(bbspath,1)
  47. IF testchar~='/' & testchar~=':' THEN bbspath=bbspath'/'
  48.  
  49. msgpath = WORD(data.7,1)
  50. IF ~EXISTS(msgpath) THEN
  51.   DO
  52.     SAY msgpath 'does not exist!'
  53.     CALL GETOUT(23)
  54.   END
  55. testchar=RIGHT(msgpath,1)
  56. IF testchar~='/' & testchar~=':' THEN msgpath=msgpath'/'
  57. msgpath=msgpath'MSG'
  58.  
  59. extension=WORD(data.32,1)
  60. arccom=data.33
  61. compos=POS('/*',data.33)
  62. IF compos>0 THEN data.33=LEFT(data.33,compos-1)
  63. arccom=STRIP(data.33)
  64. IF LEFT(extension,1)~='.' THEN
  65.   DO
  66.     extension='.lzh'
  67.     arccom='lharc -m m'
  68.   END
  69.  
  70. DO i=1
  71.   IF GETCLIP('BBS_MSGS'i)='' THEN  /* info clip for external STOP */
  72.     DO
  73.       CALL SETCLIP('BBS_MSGS'i,name)
  74.       CALL SETCLIP('BBS_STOP_MSGS'i)
  75.       clipnum=i
  76.       LEAVE i
  77.     END
  78. END
  79.  
  80. x=OPEN(f,bbspath'Users/'name,'R')
  81. IF x=0 THEN
  82.   DO
  83.     CALL DELAY(150)
  84.     x=OPEN(f,bbspath'Users/'name,'R')
  85.     IF x=0 THEN
  86.       DO
  87.         SAY name 'user file is missing!'
  88.         CALL GETOUT(24)
  89.       END
  90.   END
  91. data.=''
  92. DO i=1 TO 25
  93.   data.i=READLN(f)
  94. END
  95. CALL CLOSE(f)
  96. level=data.20%1
  97. lastread.=0
  98.  
  99. x=GETCLIP('BBS_'name'_22')
  100. IF x~='' THEN
  101.   DO
  102.     data.22=x
  103.     CALL SETCLIP('BBS_'name'_22')
  104.   END
  105.  
  106. msg.=''
  107. IF readopen(bbspath'Lists/Conferences') THEN
  108.   DO
  109.     DO i=1
  110.       line=READLN(f)
  111.       IF line='END' THEN BREAK
  112.       IF EOF(f) THEN BREAK
  113.       num=WORD(line,1)
  114.       IF DATATYPE(num,'N') THEN msg.num=WORD(line,2)
  115.     END
  116.     CALL CLOSE(f)
  117.   END
  118.  
  119. CALL SETCLIP('BBS_MSGS')
  120. CALL PRAGMA('P',-2)         /* lower the priority of this task */
  121.  
  122. oldt=0
  123. count=0
  124. archives=1
  125. CALL open_new()
  126.  
  127. filepath=bbspath'EmailFiles/'name
  128. CALL MAKEDIR(filepath)
  129. arcname=filepath'/BBBBS_'lastm
  130. IF GETCLIP('BBS_'name)~='' THEN arcname=filepath'/Messages'
  131. CALL open_arc()
  132. CALL newmsgs()
  133. CALL CLOSE(a)
  134. CALL DELAY(28)
  135. IF WORD(STATEF(arcname),2)<80 THEN CALL GETOUT(24)
  136. CALL write_msg()
  137. CALL GETOUT(0)
  138. EXIT
  139.  
  140.  
  141.  
  142. /* Functions */
  143.  
  144.  
  145. write_msg:
  146. IF GETCLIP('BBS_'name)~='' THEN RETURN
  147. CALL PRAGMA('P',0)         /* normal priority */
  148. ADDRESS COMMAND arccom arcname||extension arcname
  149. IF ~EXISTS(arcname||extension) THEN CALL GETOUT(27)
  150. CALL PRAGMA('P',-2)
  151. x=OPEN(f,bbspath'Email/'name'/BBBBS.'lastm,'W')
  152. IF x=0 THEN CALL GETOUT(26)
  153. CALL WRITELN(f,' Mail: 'lastm'   FILE: BBBBS_'lastm||extension)
  154. CALL WRITELN(f,' From: BBBBS')
  155. CALL WRITELN(f,'   To: 'name)
  156. CALL WRITELN(f,' Subj: 'subj)
  157. CALL WRITELN(f,' Date: 'DATE('W') DATE() TIME('C'))
  158. CALL WRITELN(f,LEFT('=',75,'='))
  159. temp='Here are the archived new messages you requested'
  160. IF WORD(finfo,2)>1400000 THEN temp=temp', part' archives-1
  161. CALL WRITELN(f,temp)
  162. t=(.5+TIME('E'))%1
  163. t=t-oldt
  164. oldt=t+oldt
  165. min=t%60
  166. hrs=min%60
  167. min=min//60
  168. sec=t//60
  169. temp=' - It took'
  170. IF hrs>1 THEN temp=temp hrs 'hours'
  171. ELSE IF hrs=1 THEN temp=temp '1 hour'
  172. IF min>1 THEN temp=temp min 'minutes'
  173. ELSE IF min=1 THEN temp=temp '1 minute'
  174. IF sec=1 THEN temp=temp '1 second'
  175. ELSE IF sec>0 THEN temp=temp sec 'seconds'
  176. temp=temp 'to compile these messages -'
  177. CALL WRITELN(f,temp)
  178. CALL CLOSE(f)
  179. newmess='Your archived messages are waiting in Email.'
  180. IF GETCLIP('BBS_level')~='' & WORD(GETCLIP('BBS_lastcaller'),1)=name THEN
  181.   DO
  182.     oldmess=GETCLIP('BBS_MESSAGE')
  183.     IF oldmess~='' THEN oldmess=oldmess||'0D0A'x
  184.     CALL SETCLIP('BBS_MESSAGE',oldmess||newmess)
  185.   END
  186. IF GETCLIP('BBS_LOCAL')=name THEN CALL SETCLIP('BBS_LOCAL_MSG',newmess)
  187. RETURN
  188.  
  189.  
  190. open_new:
  191. subj='All New Conference Messages'
  192. IF single_dir>0 THEN subj=msg.single_dir' conference messages'
  193. IF WORD(finfo,2)>1400000 THEN subj=subj', part' archives
  194. IF GETCLIP('BBS_'name)='' THEN
  195.   DO
  196.     x=OPEN(f,bbspath'Numbers/LastMail','R')
  197.     IF x~=0 THEN lastm=READLN(f)+1
  198.     CALL CLOSE(f)
  199.     ADDRESS COMMAND 'ECHO >'bbspath'Numbers/LastMail 'lastm
  200.     x=OPEN(f,bbspath'Email/'name'/BBBBS.'lastm,'W')
  201.     IF x=0 THEN CALL GETOUT(26)
  202.     CALL WRITELN(f,' Mail: 'lastm'   FILE: BBBBS_'lastm)
  203.     CALL WRITELN(f,' From: BBBBS')
  204.     CALL WRITELN(f,'   To: 'name)
  205.     CALL WRITELN(f,' Subj: 'subj)
  206.     CALL WRITELN(f,' Date: 'DATE('W') DATE() TIME('C'))
  207.     CALL WRITELN(f,LEFT('=',75,'='))
  208.     CALL WRITELN(f,'Here are the new messages you requested.')
  209.     CALL WRITELN(f,'The collection process was interrupted.')
  210.     CALL CLOSE(f)
  211.   END
  212. RETURN
  213.  
  214.  
  215. countcheck:
  216. PARSE ARG fname' '.
  217. IF ~readopen(fname) THEN RETURN(cknum)
  218. retval=STRIP(READLN(f))
  219. CALL CLOSE(f)
  220. IF ~DATATYPE(retval,'N') THEN retval=0
  221. RETURN(retval)
  222.  
  223.  
  224. newmsgs:
  225. IF single_dir>0 THEN
  226.   DO
  227.     msgdir=single_dir
  228.     CALL readmsg()
  229.     RETURN
  230.   END
  231. CALL WRITELN(a,'Scanning all Conferences for new messages..')
  232. DO newi=1 TO level
  233.   IF msg.newi='' THEN ITERATE newi
  234.   msgdir=newi
  235.   CALL readmsg()
  236. END
  237. RETURN
  238.  
  239.  
  240. readmsg:
  241. IF msg.msgdir='' | FIND(data.21,msgdir)>0 THEN RETURN;   /* sysop excluded */
  242. IF WORD(data.22,msgdir)=-1 THEN RETURN;  /*  user excluded */
  243. IF DATATYPE(WORD(data.22,msgdir),'N') THEN
  244.   lastread.msgdir=WORD(data.22,msgdir)
  245. IF STRIP(SHOWDIR(msgpath||msgdir))='' THEN RETURN
  246. lstwrt=countcheck(bbspath'Numbers/LastMessage'msgdir 0)
  247. frstwrt=countcheck(bbspath'Numbers/FirstMessage'msgdir 0)
  248. temp=''
  249. IF lastread.msgdir>=lstwrt THEN
  250.   DO
  251.     lastread.msgdir=lstwrt
  252.     RETURN
  253.   END
  254. CALL WRITELN(a,'Entering' msg.msgdir 'Message Conference..')
  255. dirname=msgpath||msgdir
  256. msglist.=0 /* set read to 0, unread to 1, and reply >=2 */
  257. firstmess=999999
  258. testlist=SHOWDIR(dirname)
  259. DO i=1 TO WORDS(testlist)
  260.   test=WORD(testlist,i)
  261.   IF test>lastread.msgdir THEN msglist.test=1
  262.   IF test<firstmess THEN firstmess=test
  263. END
  264. IF firstmess=999999 THEN firstmess=0
  265. CALL countcheck(bbspath'Numbers/FirstMessage'msgdir firstmess)
  266. msgstatus=1
  267. DO msgloop=1
  268.   lastreadnum=lastread.msgdir
  269.   DO WHILE msglist.lastreadnum=0 & lastreadnum<lstwrt
  270.     lastreadnum=lastreadnum+1
  271.   END
  272.   lastread.msgdir=lastreadnum
  273.   IF lastreadnum=lstwrt & msglist.lstwrt=0 THEN RETURN
  274.   DO mess=lastread.msgdir TO lstwrt+1
  275.     IF msglist.mess~=msgstatus THEN ITERATE mess
  276.     IF msgstatus>1 THEN CALL WRITELN(a,'Following the thread, level' msgstatus-1'.')
  277.     msglist.mess=0
  278.     arg=dirname'/'mess
  279.     IF ~EXISTS(arg) THEN
  280.       DO
  281.         CALL WRITELN(a,'Message number' mess 'is missing.')
  282.         ITERATE mess
  283.       END
  284.     IF ~readopen(arg) THEN ITERATE mess
  285.     firstline  = READLN(f)
  286.     secondline = READLN(f)
  287.     thirdline  = READLN(f)
  288.     forthline  = READLN(f)
  289.     CALL CLOSE(f)
  290.     IF WORDS(firstline)>2 THEN  /* if replies, change their num to >1 */
  291.       DO
  292.         thread=SUBSTR(firstline,WORDINDEX(firstline,4))
  293.         DO tindx=1 TO WORDS(thread)
  294.           test=WORD(thread,tindx)
  295.           IF msglist.test~=0 THEN msglist.test=msgstatus+1
  296.         END
  297.       END
  298.     CALL add_msg(arg)
  299.     IF thread~='' THEN
  300.        DO
  301.          thread=''
  302.          msgstatus=msgstatus+1
  303.        END
  304.   END
  305.   IF msgstatus>1 THEN msgstatus=msgstatus-1
  306. END
  307. RETURN
  308.  
  309.  
  310. readopen:
  311. PARSE ARG fname
  312. ok=OPEN(f,fname,'R')
  313. IF ok~=0 THEN RETURN(1)
  314. SAY fname 'failed to open for reading!'
  315. RETURN(0)
  316.  
  317.  
  318. readlines:
  319. CALL CLOSE(f)
  320. PARSE ARG tempname readstart .
  321. IF ~readopen(tempname) THEN RETURN(1)
  322. IF readstart<2 THEN lynes.=''
  323. DO ri=readstart
  324.   line=READLN(f)
  325.   IF EOF(f) THEN BREAK
  326.   lynes.ri=line
  327. END
  328. lynes.0=ri-1
  329. RETURN
  330.  
  331.  
  332. open_arc:
  333. CALL CLOSE(a)
  334. x=OPEN(a,arcname,'W')
  335. IF x=0 THEN CALL GETOUT(30)
  336. temp='= Custom archived for' name
  337. IF WORD(finfo,2)>1400000 THEN temp=temp', part' archives
  338. CALL WRITELN(a,temp)
  339. CALL WRITELN(a,'=' bbsname  'conferen