home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / comm / mail / thor / thor.lha / rexx / PostNews.thor < prev    next >
Text File  |  1994-08-06  |  4KB  |  130 lines

  1. /* PostNews.thor by Tommy Larsen and Troels Walsted Hansen
  2. ** $VER: PostNews.thor v1.05 (19.03.94)
  3. **
  4. ** An ARexx script for parsing News articles from InterNet
  5. ** and making EnterMsg events for each of the articles.
  6. */
  7.  
  8. /* this must be set correctly! */
  9.  
  10. rxpath = 'THOR:Rexx/'
  11.  
  12. options results
  13.  
  14. if(substr(address(),1,4) ~= "THOR") then do
  15.     if ~(show(p, "THOR.01")) then do
  16.         say "No THOR port found!"
  17.         exit
  18.     end
  19.     else portname = "THOR.01"
  20. end
  21. else portname = address()
  22.  
  23. address(portname)
  24.  
  25. if ~show(l, 'rexxsupport.library') then do
  26.     if ~addlib('rexxsupport.library', 0, -30) then do
  27.         REQUESTNOTIFY TEXT '"Please install rexxsupport.library in your libs: directory"' BT '"_Ok"'
  28.         exit
  29.     end
  30. end
  31.  
  32. parse arg dir bbsname
  33.  
  34. if(dir = "") then do
  35.     REQUESTFILE TITLE '"Select News directory:"' ID '"THOR:"' FP PAT '"#?"'
  36.     if(rc ~= 0|result = "") then exit
  37.     else dir = result
  38.  
  39.     endchar = right(dir,1)
  40.  
  41.     if(endchar ~= ":" & endchar ~= "/") then do
  42.         posi = lastpos("/",dir)
  43.         if(posi = 0) then posi = lastpos(":",dir)
  44.         dir = delstr(dir,posi+1)
  45.     end
  46. end
  47.  
  48. if(bbsname = "") then do
  49.     REQUESTLIST BBSLIST
  50.     bbsname = result
  51.     if(rc ~= 0 | bbsname = "RESULT") then exit
  52. end
  53. else bbsname = strip(bbsname)
  54.  
  55. files = showdir(dir, A)
  56. dirs = ""           /* String used for subdirs */
  57.  
  58. do i=1 to words(files)
  59.     dirs = CheckIfMsg(word(files, i))
  60. end
  61.  
  62. if dirs ~= "" then        /* If the News dir contained subdirs enter those */
  63.     do i = 1 to words(dirs)
  64.         address command "rx "||rxpath||"PostNews.thor "||word(dirs, i)||' '||bbsname /* Highly unrecommended hack */
  65.     end
  66.  
  67. PACKEVENTS BBS '"'bbsname'"'
  68.  
  69. exit
  70. /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
  71. CheckIfMsg:        /* Determine whether it is in fact a file or a dir */
  72.     parse arg file
  73.     sjekk = finn_type(file)
  74.     if sjekk = 1 & file ~= ".next" then call addmessage(file)    /* A file. Add it. */
  75.     if sjekk = 2 then do
  76.         dirs = dirs||' '||checker||'/'        /* Add this dir to the list of subdirs */
  77.     end
  78. return dirs
  79. /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
  80. addmessage:
  81.     parse arg messy        /* Filename will be used for subject if it isn't found in the file */
  82.  
  83.     subject = finnsubject(dir, messy)
  84.     if subject = 0 then subject = messy
  85.     konf=strip(dir, T, "/")        /* A highly insecure way of obtaining the dir name */
  86.     lstpos = lastpos('/', konf)
  87.     konf = substr(konf, lstpos + 1)
  88.  
  89.     select                /* Determine conf name based on dir name */
  90.         when upper(konf) = 'AMIGA' then konf = 'csa/sources'
  91.         when upper(konf) = 'ANNOUNCE' then konf = 'csa/announce'
  92.         when upper(konf) = 'REVIEWS' then konf = 'csa/reviews'
  93.         when upper(konf) = 'VITSER' then konf = 'no/vitser'
  94.         when upper(konf) = 'ARTIKLER' then konf = 'ntb/artikler'
  95.     otherwise
  96.         konf = 'Frainternet'            /* Default conf name */
  97.     end
  98.  
  99.     abs_file = dir || messy ; abs_file = compress(abs_file) /* Add the event */
  100.     ADDEVENT BBS '"'bbsname'"' EVENT ENTERMSG SENDTO '"ALL"' CONF '"'konf'"' MSGFILE '"'abs_file'"' SUB '"'subject'"'
  101.  
  102. return 0
  103. /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
  104. finnsubject: procedure
  105.     parse arg
  106.     file = arg(1)||arg(2)
  107.  
  108.     if open(fh, file, 'R') then do
  109.         do q=1 to 15        /* Read the first 15 lines of the message */
  110.             subj = readln(fh)
  111.             if upper(word(subj,1)) = 'SUBJECT: ' then do  /* Try to extract subject */
  112.                 close(fh)
  113.                 return(substr(subj,10))
  114.                 break
  115.             end
  116.         end
  117.         close(fh)
  118.     end
  119.     else return(0)
  120. return(0)
  121. /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
  122. finn_type:            /* Determine whether we are dealing with a file or a dir */
  123.     parse arg checker
  124.     checker=dir||checker
  125.     if word(statef(checker), 1)="DIR" then return 2
  126.     if word(statef(checker), 1)="FILE" then return 1
  127.     else return 0                /* Returns 1 if file and 2 if dir */
  128. return 0
  129. /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
  130.