home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / comm / mail / YAMscripts.lha / GrabAllURLs.rexx < prev    next >
OS/2 REXX Batch file  |  1997-02-21  |  4KB  |  116 lines

  1. /*                         GrabAllURLs.rexx
  2.                            v1.1 - 20-Nov-96
  3.  
  4.    This script grabs all URLs from the read messages in the folder and displays 
  5.    them in a requester.  From that requester you can send the URL to your browser.
  6.    Currently supported browsers are AWeb, IBrowse and Voyager.
  7.    
  8.    All adresses which end with a character in variable dup_chars will be 
  9.    duplicated and displayed also without that character.
  10.  
  11.    The script requires rexxreqtools.library and reqtools.library.
  12.    
  13.    Send bug reports, comments and spare bodyparts to knikulai@utu.fi
  14.  
  15.    If you send a message with subject REQUEST INDEX, you'll get a list
  16.    of my AREXX scripts. REQUEST <filename> will get you the script you
  17.    want.
  18.  
  19.    Version 1.0 had a stupid error that put it into an infinite loop
  20.    whenever file:// was encountered.  Thanks to Milco Veljanoski 
  21.    <mvljnski@xs4all.nl> for letting me know.
  22. */
  23. options results
  24. addlib('rexxreqtools.library',0,-30)
  25.  
  26. dup_chars='.,!?"*%&)'    /* If one of these ends the URL, it will be duplicated */
  27. wid=70            /* how many characters of the URL is shown? */
  28. maxbut=17        /* How many buttons fit the screen ? */
  29. maxurl=17        /* How many lines of URLs fit the screen ? 
  30.                            This may be different from maxbut, if you wish.*/
  31.       title='GrabAllURLs.rexx by knikulai@utu.fi'
  32.   not_found='Sorry, could not find any URLs!'
  33. found_these='The following URLs were found:'
  34. NL='0a'x        /* newline */
  35. uc=0            /* URL-counter */
  36.  
  37. address 'YAM'
  38. GetFolderInfo Max
  39. n=result
  40. do viesti=0 to n-1
  41.     SetMail viesti
  42.     GetMailInfo File
  43.     fname=result
  44.     GetMailInfo Status
  45.     if pos(result,'UN')=0 then do  /* The message isn't new or unread */
  46.        if open(msg,fname,'R') then do
  47.            do until eof(msg) | uc=maxurl 
  48.                rivi=readln(msg)
  49.                rivi=rivi || '  '        /* Just making sure there is a space at the end */
  50.                do while uc<maxurl & (pos('GOPHER://',upper(rivi))>0 | pos('FILE://',upper(rivi))>0 | pos('HTTP://',upper(rivi))>0 | pos('FTP://',upper(rivi))>0)
  51.                   /* There might be several URLs on one line */
  52.                   b=pos('HTTP://',upper(rivi))        /* beginning */
  53.                   if b=0 then b=pos('FTP://',upper(rivi))
  54.                   /* Adding other types is easy, just add a line like this: */      
  55.               if b=0 then b=pos('GOPHER://',upper(rivi))
  56.               if b=0 then b=pos('FILE://',upper(rivi))
  57.               e=pos(' ',rivi,b)            /* space ends the URL */
  58.                   if e-pos('//',rivi,b)>2 then do    /* only save if URL has chars in it */
  59.                   call AddURL(substr(rivi,b,e-b))    /* save URL */
  60.                   do while uc<maxurl & pos(right(url.uc,1),dup_chars)>0 
  61.                   /* Add another URL without the last character */
  62.                       spare=left(url.uc,length(url.uc)-1)
  63.                       call AddURL(spare)          
  64.                       end /* do while uc<maxurl & pos */
  65.           end /*if e-pos('//',rivi,b)>2*/
  66.           rivi=right(rivi,length(rivi)-e)
  67.                end /* do while uc<maxurl & (pos('FILE://',upper(rivi))> */
  68.            end /* do until eof(msg) */
  69.            close(msg)
  70.         end /* if open(msg,fname,'R') then do */
  71.     end /* if pos(result,'UN')=0 then do */
  72. end /* do viesti=0 to n-1 */
  73. if uc=0 then
  74.        call rtezrequest(not_found,,title)
  75. else do
  76.        body=found_these || NL
  77.        buttons=''
  78.        do i=1 to uc
  79.               if i<10 then 
  80.            shortcut='_'
  81.        else
  82.            shortcut=''
  83.            if i<=maxbut then buttons=buttons || shortcut || i || '|'
  84.            body=body || i || ') '
  85.            if length(url.i)<=wid then
  86.            body=body || url.i || NL
  87.        else
  88.            body=body || left(url.i,40) || '...' || right(url.i,wid-43) || NL
  89.            end /* do i=1 to uc */
  90.        buttons=buttons || '_Ok'
  91.        sel=rtezrequest(body,buttons,title,'rtez_defaultresponse=0')
  92.        if sel>0 then do       
  93.        lst=show('P') || '  '
  94.        if pos('VOYAGER',lst)>0 then
  95.           address 'VOYAGER' 'OpenURL '|| url.sel
  96.        if pos('MINDWALKER',lst)>0 then
  97.           address 'MINDWALKER' 'OpenURL '|| url.sel
  98.        if pos('IBROWSE',lst)>0 then
  99.           address 'IBROWSE' 'GotoURL ' || url.sel
  100.        if pos('AWEB',lst)>0 then do
  101.         address value substr(lst,pos('AWEB.',lst),6)        
  102.         'Open ' || url.sel
  103.         end
  104.        end /* if sel>0 then do */
  105. end /* else */
  106. exit
  107.  
  108. AddURL:
  109.   parse arg u
  110.   do i=1 to uc
  111.       if url.i=u then return
  112.       end
  113.   uc=uc+1
  114.   url.uc=u
  115. return
  116.