home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / upc12b22.zip / mailchek.cmd < prev    next >
OS/2 REXX Batch file  |  1993-04-03  |  6KB  |  158 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    Program:    mailcheck         (92-10-12)                        */
  3. /*    Author:     Evan Champion                                       */
  4. /*    Address:    evanc@uuisis.isis.org                               */
  5. /*    Language:   Procedure Langauges/2 (OS/2 REXX) with              */
  6. /*                Visual REXX                                         */
  7. /*--------------------------------------------------------------------*/
  8.  
  9. /*--------------------------------------------------------------------*/
  10. /*    Requires Visual Rexx, available from IBM's OS/2 Internet        */
  11. /*    archive or CompuServ                                            */
  12. /*--------------------------------------------------------------------*/
  13.  
  14. /*--------------------------------------------------------------------*/
  15. /*   Change history                                                   */
  16. /*   09 Nov 92 ahd   Use UUPCSYSRC to locate the mail directory and   */
  17. /*                   mailbox extension                                */
  18. /*--------------------------------------------------------------------*/
  19.  
  20. Call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  21. Call 'SysLoadFuncs'
  22. /* setup VREXX */
  23. signal on novalue
  24. call RxFuncAdd 'VInit', 'VREXX', 'VINIT'
  25. initcode = VInit()
  26.  
  27. if initcode = 'ERROR' then call CLEANUP
  28.  
  29. signal on failure name CLEANUP
  30. signal on halt name CLEANUP
  31. signal on syntax name CLEANUP
  32.  
  33. /* say product info to the fullscreen */
  34.  
  35. say 'MailCheck [92-10-12]'
  36. say 'by Evan Champion (evanc@uuisis.isis.org)'
  37. say ' '
  38. say 'Enter Control-C to close'
  39.  
  40. /* load functions in RexxUtil */
  41.  
  42. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  43. call SysLoadFuncs
  44.  
  45. y = 300 /* x and y values for printing text */
  46. x = 10  /* in the PM window */
  47. cycle = 30;                   /* Check for mail every ...      */
  48.  
  49. maildir = getuupc("maildir" );
  50. mailext = getuupc("mailext" );
  51.  
  52. empty  = 'WHITE' /* window background colour */
  53. full   = 'BLACK' /* window background colour */
  54. colour = empty;
  55. pos.left= 70 /* window positions, in percent of desktop */
  56. pos.bottom = 0
  57. pos.right = 100
  58. pos.top = 3
  59.  
  60. title = 'Mailcheck [04 Apr 93]' /* title w/version number */
  61.  
  62. mailcheckID = VOpenWindow(title, colour, 'pos')
  63. info.   = '';                 /* Flag we have no mailbox info  */
  64.  
  65. do forever /* start checking */
  66.    return = SysFileTree(maildir || '\*.' || mailext, 'found.', 'F')
  67.    if return = 2 then
  68.       call CLEANUP            /* if there isn't enough memory */
  69.    if found.0 = 0 then
  70.    do;
  71.       if colour = full then
  72.       do;
  73.          call vforecolor mailcheckID,full;
  74.          call vbackcolor mailcheckID,empty;
  75.          colour = empty;
  76.       end;
  77.       call SAYINFO            /* if there are no files */
  78.       call SysSleep Cycle;
  79.       drop counts.
  80.       info. = '';
  81.    end;
  82.    else do;
  83.       pause = cycle % found.0
  84.       if pause < 2 then
  85.          pause = 2;
  86.       if colour = empty then
  87.       do;
  88.          call vforecolor mailcheckID,empty;
  89.          call vbackcolor mailcheckID,full;
  90.          colour = full
  91.       end;
  92.       do i = 1 to found.0
  93.            parse var found.i mmddyy hhmmss bytes attr fname;
  94.            parse value filespec( "name", fname ) with id'.';
  95.            if mmddyy = date('U') then
  96.               when = hhmmss
  97.            else
  98.               when = substr(mmddyy,1,5) hhmmss;
  99.            if info.id <> found.i then
  100.            do;
  101.               count.id = CountItems( strip(fname) );
  102.                               /* Only read file when truly needed */
  103.               info.id = found.i
  104.                               /* Remember that we read the file   */
  105.            end;
  106.            call SAYINFO id, when, bytes, count.id ;
  107.            call SysSleep pause;
  108.       end i /* do */
  109.    end;
  110. end /* do */
  111.  
  112. SAYINFO:
  113. parse arg xwho, xwhen, xbytes, xitems
  114.    if xwho = '' then
  115.       output = 'No new mail' /* if there was no mail */
  116.    else
  117.       output = xwho || '  ' || xwhen '(' || xitems 'items,' ,
  118.                xbytes || ' bytes)' ;
  119.    call VClearWindow mailcheckID /* scroll through ID's with mail */
  120.    call VSay mailcheckID, x, y, output
  121.    return
  122.  
  123. CLEANUP:
  124.    call VExit /* cleanup and exit */
  125.    exit
  126.  
  127. /*--------------------------------------------------------------------*/
  128. /*       C o u n t I t e m s                                          */
  129. /*                                                                    */
  130. /*       Count number of items in a mailbox.                          */
  131. /*--------------------------------------------------------------------*/
  132.  
  133. CountItems:procedure
  134. parse arg mailbox
  135. sep = copies('01'x,19)
  136. xrc = SysFileSearch( sep ,mailbox,'data.');
  137. if xrc <> 0 then
  138. do;
  139.    say 'Internal error' xrc || ':' ,
  140.          mailbox 'has no UUPC/extended message breaks'
  141.    return 0;
  142. end;
  143. else
  144.    return data.0;
  145.  
  146. /*--------------------------------------------------------------------*/
  147. /*    n o v a l u e                                                   */
  148. /*                                                                    */
  149. /*    Trap for uninitialized variables                                */
  150. /*--------------------------------------------------------------------*/
  151.  
  152. novalue:
  153. trace n
  154. signal off novalue;           /* Avoid nasty recursion         */
  155. say 'Uninitialized variable in line' sigl || ':';
  156. say sourceline( sigl );
  157. signal Cleanup
  158.