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

  1. /*                      CheckNewMail.rexx
  2.             v 1.4 - 20-Feb-97 
  3.  
  4.    This script checks if there are new or unread messages and where they are.
  5.    It requiress reqtools and rexxreqtools libraries.
  6.  
  7.    Changes in 1.4
  8.     - Doesn't get confused if some folders have been deleted
  9.  
  10.    Changes in 1.3
  11.     - YAM hides for the duration of the scan, which makes the script much
  12.       quicker.
  13.     - The requester will not disappear until the user selects 'Done'
  14.       if the variable dontquit is set to 'on'.
  15.  
  16.    Changes in 1.2
  17.     - Output is slightly different
  18.     - Message counts should now always fit, even with long foldernames
  19.  
  20.    Changes in 1.1
  21.     - Displays number of new/unread messages in each folder
  22.     - All messages are now in variables and easy to change
  23.  
  24.    This and more than dozen other scripts can be found at
  25.    http://www.utu.fi/~knikulai/ARexx.html
  26.  
  27.    You can also get the latest version of this script by send a message
  28.    with subject REQUEST CheckNewMail.rexx to knikulai@utu.fi.  If you send
  29.    a message with subject REQUEST INDEX, you'll get a listing of all my
  30.    publicly available AREXX scripts.
  31. */
  32. options results
  33.  
  34. maxfolder=12    /* Set this to the number of folders you have-1*/
  35. cols=3        /* How many colums of folders in requester */
  36. wid=17        /* Max displayed width of foldername + message counts*/
  37. butl=70        /* Maximum length of buttons in characters. Increase this a bit
  38.                    if you are using a proportional font. */
  39. dontquit='OFF'  /* If 'on', the requester stays until Done is selected*/
  40. sunr='YES'    /* Search for unread messages too ( yes/no ) */
  41.  
  42. /* Change these to something you like */
  43.           title='CheckNewMail.rexx' 
  44.       new_title='You have new mail in following folders: (new/unread)' 
  45.    no_new_title='You have no new mail.'
  46.    unread_title='You have unread mail in following folders:' 
  47. no_unread_title='You have no folders with only unread mail.'
  48.   select_folder='Select folder you want to read next'
  49.     last_button='_Done'
  50.  
  51. addlib('rexxreqtools.library',0,-30)
  52. address 'YAM' 
  53. 'Hide'
  54.  
  55. GetFolderInfo Number    /* Let's remember where we are now */
  56. orig_fold=result
  57. GetMailInfo Active
  58. orig_msg=result
  59.  
  60. nc=0        /* new-counter */
  61. uc=0        /* unread-counter */
  62. NL='0a'x    /* newline */
  63. do f=0 to maxfolder
  64.    if f~=1 & f~=2 then do  /* Don't check Outgoing nor Sent */
  65.         SetFolder f
  66.     if rc=0 then do
  67.          GetFolderInfo Name
  68.         fn=result        /* Name of the folder */
  69.         GetFolderInfo Max
  70.         n=result        /* Number of messages in the folder */
  71.         i=0
  72.         nm=0
  73.         um=0
  74.         do while i<n
  75.            SetMail i
  76.            i=i+1
  77.            GetMailInfo Status
  78.            if result='N' then nm=nm+1    /* New message was found */
  79.            if result='U' & upper(sunr)='YES' then um=um+1/* Unread message was found */
  80.         end /* do while i<n */
  81.         if nm>0 then do  /* New messages were found */
  82.            nc=nc+1
  83.            foo= nm ||'/'|| um 
  84.            new.nc=left(fn||' ',wid-length(foo), '.') || foo
  85.            newn.nc=f
  86.            end
  87.         else
  88.         if um>0 & upper(sunr)='YES' then do  /* New messages were found */
  89.            uc=uc+1       
  90.            unread.uc=left(fn||' ', wid-length(um), '.') || um
  91.            unreadn.uc=f
  92.            end
  93.     end /* if rc=0 */
  94.     
  95.     end /* if f~=1 & f`=2 then do */    
  96. end /* do f=0 to maxfolder */
  97.  
  98. /* Now all folders have been scanned */
  99. but=''
  100. bc=0
  101.  
  102. /* Return to where we were before starting this script */
  103. 'Show'
  104. 'SetFolder' orig_fold
  105. 'SetMail' orig_msg
  106.  
  107. /* Let's first list new messages */
  108. if nc>0 then 
  109.       rt=new_title
  110. else 
  111.       rt=no_new_title || NL
  112.  
  113. rt=rt || NL
  114. do i=1 to nc
  115.     rt=rt || new.i || '  '
  116.     if length(but)+length(word(new.i,1))<butl then do 
  117.         but=but || word(new.i,1) || '|'
  118.         bc=bc+1
  119.         butn.bc=newn.i
  120.         end
  121.     if i//cols = 0 then rt=rt || NL
  122. end
  123.  
  124. /* Then it's time to list unread messages, if that was asked */
  125. if upper(sunr)='YES' then do
  126.     if uc>0 then 
  127.         rt=rt||NL|| unread_title
  128.     else 
  129.         rt=rt||NL|| no_unread_title
  130.     rt=rt || NL
  131.     do i=1 to uc
  132.         rt=rt || unread.i ||'  '
  133.         if i//cols = 0 then rt=rt || NL
  134.         if length(but)+length(word(unread.i,1))<butl then do
  135.             but=but || word(unread.i,1) || '|'
  136.             bc=bc+1
  137.             butn.bc=unreadn.i
  138.             end
  139.     end
  140. end /* if upper(sunr)='YES' */
  141.  
  142. rt=rt || NL || NL || select_folder
  143. but=but || last_button
  144. tags='rtez_defaultresponse=0'
  145.  
  146. sel=1
  147.  
  148.  
  149. do until sel=0 | upper(dontquit)='OFF'
  150.    sel=rtezrequest(rt,but,title,tags)
  151.    if sel>0 then address 'YAM' 'SetFolder ' || butn.sel
  152. end
  153.