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

  1. /*                           GrabURL.rexx
  2.                            v1.2 - 19-Nov-96
  3.  
  4.    This script grabs all URLs from the current message and displays them
  5.    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. options results
  20. addlib('rexxreqtools.library',0,-30)
  21.  
  22. dup_chars='.,!?"*%&)'    /* If one of these ends the URL, it will be duplicated */
  23. wid=70            /* how many characters of the URL is shown? */
  24. maxbut=17        /* How many buttons fit the screen ? */
  25. maxurl=18        /* How many lines of URLs fit the screen ? */
  26.       title='GrabURL.rexx by knikulai@utu.fi'
  27.   not_found='Sorry, could not find any URLs!'
  28. found_these='The following URLs were found:'
  29.   error_msg='Could not open file for reading!'
  30. NL='0a'x        /* newline */
  31. uc=0            /* URL-counter */
  32.  
  33. address 'YAM'
  34. GetMailInfo File
  35. fname=result
  36.  
  37. if open(msg,fname,'R') then do
  38.    do until eof(msg) | uc=maxurl
  39.       rivi=readln(msg)
  40.       rivi=rivi || '  '        /* Just making sure there is a space at the end */
  41.       do while uc<maxurl & (pos('FILE://',upper(rivi))>0 | pos('HTTP://',upper(rivi))>0 | pos('FTP://',upper(rivi))>0)
  42.           /* There might be several URLs on one line */
  43.       b=pos('HTTP://',upper(rivi))            /* beginning */
  44.       if b=0 then b=pos('FTP://',upper(rivi))
  45. /* Adding other types is easy, just add a line like this: */      
  46.       if b=0 then b=pos('FILE://',upper(rivi))
  47.       e=pos(' ',rivi,b)                /* ending space */
  48.       call AddURL(substr(rivi,b,e-b))        /* save URL */
  49.       do while pos(right(url.uc,1),dup_chars)>0 
  50.       /* Add another URL without the last character */
  51.           spare=left(url.uc,length(url.uc)-1)
  52.           call AddURL(spare)          
  53.           end
  54.       rivi=right(rivi,length(rivi)-e)
  55.           end /* do until pos('HTTP://'*/
  56.       end /* do until eof(msg) */
  57.    if uc=0 then
  58.        call rtezrequest(not_found,,title)
  59.    else do
  60.        body=found_these || NL
  61.        buttons=''
  62.        do i=1 to uc
  63.               if i<10 then 
  64.            shortcut='_'
  65.        else
  66.            shortcut=''
  67.            if i<=maxbut then buttons=buttons || shortcut || i || '|'
  68.            body=body || i || ') '
  69.            if length(url.i)<=wid then
  70.            body=body || url.i || NL
  71.        else
  72.            body=body || left(url.i,40) || '...' || right(url.i,wid-43) || NL
  73.            end /* do i=1 to uc */
  74.        buttons=buttons || '_Ok'
  75.        sel=rtezrequest(body,buttons,title,'rtez_defaultresponse=0')
  76.        if sel>0 then do       
  77.        lst=show('P') || '  '
  78.        if pos('MINDWALKER',lst)>0 then
  79.           address 'MINDWALKER' 'OpenURL '|| url.sel
  80.        if pos('VOYAGER',lst)>0 then
  81.           address 'VOYAGER' 'OpenURL '|| url.sel
  82.        if pos('IBROWSE',lst)>0 then
  83.           address 'IBROWSE' 'GotoURL ' || url.sel
  84.        if pos('AWEB',lst)>0 then do
  85.         address value substr(lst,pos('AWEB.',lst),6)        
  86.         'Open ' || url.sel
  87.         end
  88.        end /* if sel>0 then do */
  89.        end /* else */
  90.    end
  91. else
  92.    call rtezrequest(error_msg,,title)
  93. exit
  94.  
  95. AddURL:
  96.   parse arg u
  97.   do i=1 to uc
  98.       if url.i=u then return
  99.       end
  100.   uc=uc+1
  101.   url.uc=u
  102. return
  103.