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

  1. /* GetAdresses.rexx v1.1 - 05-Feb-97
  2. ** Check http://www.utu.fi/~knikulai/ARexx.html for more scripts for YAM!
  3. */
  4.  
  5. options results
  6. addlib('rexxreqtools.library',0,-30)
  7. NL='0a'x    
  8.      scrn=''        /* Name of YAM's screen where the requester appears */
  9.     title='GrabAddresses.rexx by Kai.Nikulainen@utu.fi'
  10.   cho_txt='Do you want to'
  11.   cho_but='_Save Address|_Write Mail|_Cancel'
  12.   sel_txt='Select address to save in addressbook'
  13.   sel_but='_Next Page|_Cancel'
  14.    yn_but='_Yes, I certainly do!|_No, I do not!'
  15. error_txt='Could not write to file '
  16. addressbook='YAM:.addressbook'
  17. ignore='Received:'         /* If the first word of the line is one of these, no
  18.                   addresses will be searched from that line */
  19.  
  20. ac=0    /* address count */
  21.  
  22. address 'YAM'
  23. 'GetFolderInfo Max'
  24. n=result
  25. do m=0 to n-1
  26.    'SetMail' m
  27.    'GetMailInfo File'
  28.    call ScanFile(result)
  29. end /*do m=0 to n-1*/
  30.  
  31. first=1
  32. do until sel=0
  33.     body=ac 'addresses were found:'NL
  34.     buttons=''
  35.     i=first
  36.     lab=0
  37.     do while lab<9 & i<=ac
  38.        body=body || i-first+1 || ') ' || name.i email.i || NL
  39.        buttons=buttons'_'|| i-first+1 || '|'
  40.        lab=i-first+1     /* last address button */
  41.        i=i+1
  42.        end /* do while */
  43.     buttons=buttons || sel_but
  44.     
  45.     sel=rtezrequest(body,buttons,title,'rtez_defaultresponse=0 rt_pubscrname='scrn)
  46.     if sel>0 then do
  47.         if sel>lab then do
  48.             first=first+lab
  49.         if first>ac then first=1
  50.         end /* if sel>lab then do */
  51.         else do /* sel<=lab */
  52.         j=first+sel-1
  53.             cho=rtezrequest(cho_txt,cho_but,title,'rtez_defaultresponse=1 rt_pubscrname='scrn)
  54.         if cho=0 then exit
  55.         if cho=2 then do
  56.             'MailWrite'
  57.             'WriteMailTo' email.j
  58.             exit
  59.             end
  60.                 call AddToAddresbook(j)
  61.         end /* else do */             
  62.     end /* if sel>0 then do */
  63. end /* do until sel=0 */
  64. exit
  65.  
  66. AddToAddresbook:
  67.    parse arg ind
  68.    na=rtgetstring(name.ind' ',"Edit  name",title,'_Ok|_Forget It!','',s1)
  69.    if s1=0 then return
  70.    ad=rtgetstring(email.ind,'Edit address for' na,title,,,se) 
  71.    if ad='' then return
  72.    al=rtgetstring(alias.ind' ','Edit alias for' na 'at' ad,title,,'',s2)
  73.    if s2=0 then return
  74.    de=rtgetstring('Friend','Enter description for' na 'at' ad,title,,,s3)
  75.    if s3=0 then return
  76.    body='Do you want to add the following'NL'lines to' addressbook '?' NL NL
  77.    body=body '@USER' al NL ad NL na NL de NL '@ENDUSER' NL NL
  78.    body=body 'Remember to reload the addressbook after changes!'
  79.    if rtezrequest(body,yn_but,title,'rtez_defaultresponse=0') then do
  80.        if open(out,addressbook,'A') then do
  81.           call writeln(out,'@USER' al)
  82.           call writeln(out,ad)
  83.           call writeln(out,na)
  84.           call writeln(out,de)
  85.           call writeln(out,'@ENDUSER')
  86.           call close(out)
  87.       end
  88.        else
  89.           call rtezrequest(error_txt addressbook,,title,'rtez_defaultresponse=0')
  90.        end
  91. return
  92.  
  93. ScanFile:
  94.   parse arg fname
  95.   if open(1,fname,'R') then do
  96.     do until eof(1)
  97.         rivi=translate(readln(1),' ',',<>()"~$;'||'09'x,' ')
  98.         if pos('@',rivi)>0 & pos(word(rivi,1),ignore)=0 then do
  99.         fn=''
  100.         ln=''
  101.         ad=''
  102.         do w=1 to words(rivi)
  103.            fn=ln
  104.            ln=ad
  105.            ad=word(rivi,w)
  106.            if right(ad,1)=':' then ad=''
  107.            if pos('@',ad)>0 & ad~='@' then call AddIt(ad fn ln)
  108.            end /* do w=1 */
  109.     end /* if pos */
  110.     end /* do until eof(1) */
  111.     call close(1)
  112.   end /* if open(1, */
  113. return
  114.  
  115. AddIt:
  116.   parse arg addy etu suku
  117.   k=1
  118.   do while k<=ac
  119.      if addy=email.k then return    /* The address is already there, go home */
  120.      k=k+1
  121.      end
  122.   ac=ac+1            /* Prepare to add new entry... */
  123.   email.ac=strip(addy)        /* address */
  124.   name.ac=strip(etu suku)    /* name */
  125.   alias.ac=strip(etu)        /* alias. First name should be reasonable default */
  126. return
  127.