home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IMHAPI10.ZIP / CHEKMAIL.CMD next >
OS/2 REXX Batch file  |  1991-12-07  |  5KB  |  129 lines

  1. /* REXX */
  2. /* CHEKMAIL.CMD - Check for unviewed electronic mail.
  3.  * This sample REXX procedure demonstrates the use of IMHAPI with a
  4.  * named pipe.  This procedure uses the two external functions supplied
  5.  * with IMHAPI, MkHaPipe and ToHapi.  MkHaPipe creates a named pipe,
  6.  * starts IMAPI as a background task and connects it to the new named
  7.  * pipe.  From then on, the procedure uses the pipe handle returned by
  8.  * MkHaPipe to send commands to IMHAPI with the ToHapi function.  The
  9.  * results from IMHAPI are collected and checked and appropriate
  10.  * actions taken.  Specifically, this procedure uses these functions
  11.  * to check for electronic mail messages and pop up the appropirate
  12.  * terminal window if mail is waiting.  Please see IMHAPI.DOC for more
  13.  * information on the format of IMHAPI itself.  The source code for
  14.  * MkHaPipe and ToHapi is included with this set of files.
  15.  * 
  16.  * This sample will have to be modified to work in your environment, of
  17.  * course.  The references to a specific userid, user name, session
  18.  * name, etc. are all unique to each user and each system.
  19.  *     Paul Firgens, December 1991
  20.  */
  21.  
  22. /* First, add the IMHAPI functions to the REXX session
  23.  */
  24. call RxFuncAdd 'MkHaPipe', 'HAPIREXX', 'MKHAPIPE'
  25. call RxFuncAdd 'ToHapi',   'HAPIREXX', 'TOHAPI'
  26.  
  27. /* Start up IMHAPI, get it connected to a pipe and return the pipe's     
  28.  * handle number.  We need that to know where to direct IMHAPI commands  
  29.  */
  30. phandle = MkHaPipe('\pipe\kahuna')
  31.  
  32. /* Get the user's password.  Send ANSI control codes to hide the entry   
  33.  * and then restore the screen.                                          
  34.  */
  35. say "Please enter your password (the characters will be invisible):"
  36. say ""
  37. pull psw
  38. say ""
  39. say "Thank you.  Please be patient while your mail queue is checked."
  40.  
  41. /* Begin to make the connection....turn AutoWait on for IMHAPI.
  42.  */
  43. ignore = ToHapi(phandle, '-a') 
  44.  
  45. /* Attempt to connect with one of the terminal sessions, 'd' here
  46.  */
  47. rc = ToHapi(phandle, '1 d') 
  48.  
  49. /* Pick off the return code.  Check that the CONNECT_PS was successful.  
  50.  * If it wasn't, quit the procedure, otherwise continue.
  51.  */
  52. firstch = substr(rc,1,1)
  53. if firstch <> '0'
  54.     then
  55.     do
  56.         say 'Cannot connect to Terminal session.  Program terminated.'
  57.         call GBYE  /* go, clean-up and leave */
  58.     end
  59. else
  60.     nop
  61.  
  62. /* The session is available, assume it is on the initial VTAM panel and  
  63.  * login through CICS to the mail software.
  64.  */
  65. ignore = ToHapi(phandle, '3 cics@E') 
  66. ignore = ToHapi(phandle, '3 @C * * MMMM')
  67. ignore = ToHapi(phandle, '3 cesn@E')
  68. ignore = ToHapi(phandle, '3 UFFDA@T'psw'@E * * PASSWORD:')
  69.  
  70. /* The CICS logon is complete so login to the electronic mail system,
  71.  * after waiting for specific phrases to appear before continuing.
  72.  */
  73. ignore = ToHapi(phandle, '3 mail@E * * COMPLETE')
  74. ignore = ToHapi(phandle, '3 "Ann E. Mailuser@T'psw'@E" * * MAIL')
  75. ignore = ToHapi(phandle, '3 @0 * * MEETINGS')
  76.  
  77. /* SEARCH the PSP (function code 6) for the key word 'UNVIEWED'.
  78.  */
  79. msgloc = ToHapi(phandle, '6 UNVIEWED * 1000')
  80. firstch = substr(msgloc,1,1)
  81.  
  82. /* If SEARCH doesn't find the key word, tell the user and quit.
  83.  */
  84. if firstch <> '0'
  85.     then
  86.     do
  87.         say 'No UNVIEWED messages are in your mail queue.'
  88.         beep(220,60)
  89.         ignore = ToHapi(phandle, '3 off@E')
  90.         ignore = ToHapi(phandle, '3 "cssf logoff" * * QUIT')
  91.         ignore = ToHapi(phandle, '2')
  92.         call GBYE
  93.     end
  94. else
  95. /* The key word was found, so bring up the terminal window and make     
  96.  * it the active window and beep.  Then, quit this procedure.
  97.  */
  98.     do
  99.         ignore = ToHapi(phandle, '3 in@E')
  100.         ignore = ToHapi(phandle, '2')
  101.         ignore = ToHapi(phandle, '101 d')
  102.         ignore = ToHapi(phandle, '104 d\c1\\s1080')
  103.         beep(440,60)
  104.         say "Mail is waiting.  Please check the active terminal window."
  105.         call GBYE
  106.     end
  107. exit
  108.     
  109. GBYE:
  110. /* BE CERTAIN to clean-up!  Otherwise, restarting REXX procedures       
  111.  * with calls to these external functions in the same OS/2 session      
  112.  * is likely to crash the session, as they try to allocate resources    
  113.  * (esp. the named pipe) that are already hanging around                
  114.  * from the previous execution of the procedure.  This can happen       
  115.  * during debugging of REXX programs using these functions as the       
  116.  * programs don't get to close down properly before terminating.  One   
  117.  * way around the debugging problem is to EXIT the session with the     
  118.  * crashed, buggy REXX procedure before re-trying it in a new session.
  119.  */
  120.  
  121. /* First, the 'exit' command to IMHAPI has it terminate.  The           
  122.  * 'closepipe' command has ToHapi close the pipe.
  123.  */
  124.     ignore = ToHapi(phandle, 'exit') 
  125.     ignore = ToHapi(phandle, 'closepipe')
  126.     call RxFuncDrop 'MkHaPipe'
  127.     call RxFuncDrop 'ToHapi'
  128. exit
  129.