home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / popc221h.zip / popclid.cmd < prev    next >
OS/2 REXX Batch file  |  1995-06-08  |  12KB  |  334 lines

  1. /**********************************************************************
  2. PopCliD.cmd - popclient Daemon                
  3. Copyright:
  4.     Claudio Fahey claudio@uclink.berkeley.edu, 1994 and 
  5.     Clark Gaylord (cgaylord@vt.edu), 1995.
  6.  
  7. User is licensed to use this program, associated programs, and
  8. documentation in any way provided that:
  9. 1) attribution of program source is maintained
  10. 2) copyright notices are maintained
  11. 3) changes made by user are clearly documented.
  12. Note that popclient.exe, popclient.c, and associated files are 
  13. copyright by Carl Harris; see the documentation for further 
  14. information regarding the licensing of popclient itself.
  15.                                               
  16. Procedures GetArg, ArgCheck, Help, Elm support and other changes:                       
  17. Clark K. Gaylord (cgaylord@vt.edu)
  18. Version 2.21a: 18 January 1995
  19.         2.21b: 25 March 1995
  20.         2.21c:  8 April 1995
  21.         2.21d: 25 May 1995
  22.         2.21e: 26 May 1995
  23.         2.21f: 31 May 1995
  24.         2.21g:  2 June 1995
  25.         2.21h:  7 June 1995
  26.  
  27. See README.OS2 for more details.
  28. **********************************************************************/
  29. CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  30. CALL SysLoadFuncs
  31. SIGNAL ON HALT  /* don't display REXX error message when user breaks out */
  32.  
  33. TmpDir = Value( 'TMP', , 'OS2ENVIRONMENT' )
  34.  
  35. /**********************************************************************
  36. New argument processing.  I moved Claudios' original
  37. to the bottom with label 'Changed:'.                    CKG
  38. **********************************************************************/
  39. PARSE ARG Args
  40. IF (Pos( '-?', Args )>0) THEN SIGNAL HELP
  41. CALL GetArg Args
  42.  
  43. /**********************************************************************
  44. Write the process ID to a file for use by other programs.
  45. **********************************************************************/
  46. GotPID = 0
  47. "@ps.exe|rxqueue"
  48. DO Until (GotPID)
  49.     PULL PID . . . . . . Program
  50.     IF Program = 'CMD.EXE' THEN
  51.         GotPID = 1
  52. END
  53. CALL FlushQueue
  54.  
  55. CALL SysFileDelete TmpDir'\PopClid.pid'
  56. SAY 'PID =' PID
  57. CALL Lineout TmpDir'\PopCliD.pid', PID
  58. CALL Lineout TmpDir'\PopCliD.pid'
  59.  
  60. /**********************************************************************
  61. Set environment variable POPSOUND=YES if you want to be notified that
  62. mail has arrived.  Also NEWMAILSOUNDFILE and ERRORSOUNDFILE to WAV 
  63. files to play.  Sound files can be specified on command line, but not
  64. POPSOUND.                                                   RLW 6/5/95
  65. **********************************************************************/
  66. ErrorSoundFileExists = 0
  67. NewMailSoundFileExists = 0
  68. mmpm = 0
  69. IF (Sound="Y") THEN DO
  70.     Sound=1
  71.  
  72.     mmbase = value('MMBASE',,OS2ENVIRONMENT)
  73.     IF mmbase='' THEN DO
  74.         say 'MMPM is not present.'
  75.         mmpm=0
  76.     END
  77.     ELSE DO
  78.         mmpm=1
  79.         IF NewMailSoundFile<>'' THEN DO
  80.             IF Stream(NewMailSoundFile,'c','Query Exists')='' THEN
  81.                 NewMailSoundFileExists=0
  82.             ELSE
  83.                 NewMailSoundFileExists=1
  84.         END
  85.         ELSE
  86.             NewMailSoundFileExists=0
  87.  
  88.         IF ErrorSoundFile<>'' THEN DO
  89.             IF Stream(ErrorSoundFile,'c','Query Exists')='' THEN
  90.                 ErrorSoundFileExists=0
  91.             ELSE
  92.                 ErrorSoundFileExists=1
  93.         END
  94.         ELSE
  95.             ErrorSoundFileExists=0
  96.     END
  97. END
  98. ELSE DO
  99.    Sound = 0
  100. end  
  101.  
  102. /**********************************************************************
  103. Set environment variable POPUPBIFF=YES if you want to be notified that
  104. mail has arrived.
  105. **********************************************************************/
  106. /*  Can we use PMPOPUP at all? */
  107. PopupExe = SysSearchPath( 'PATH', 'pmpopup.exe')
  108. IF (PopupExe='') THEN
  109.    PopUp = 0
  110. ELSE
  111.    PopUp = 1
  112.  
  113. PopUpBiff = Value( 'POPUPBIFF', ,'OS2ENVIRONMENT' )
  114. /*  If = YES then notify of incoming mail via PMPOPUP  */
  115.  
  116. /*  Is it POPCLIEN.EXE (FAT) or POPCLIENT.EXE (HPFS)?  */
  117. PopClient = SysSearchPath( 'PATH', 'popclient.exe')
  118. IF (PopClient = '') THEN
  119.    PopClient = SysSearchPath( 'PATH', 'popclien.exe')
  120. IF (PopClient = '') THEN DO
  121.     IF (PopUp) THEN
  122.         "@start" PopupExe "Could not find POPCLIENT executable."
  123.     ELSE
  124.         SAY 'Could not find POPCLIENT executable.'
  125.     EXIT
  126. END
  127.  
  128. IF (Mailer='U') THEN DO
  129.     mda_path = 'UMAILER.EXE'
  130.     mda_args = '-dest' inbasket '-to $u'
  131. END
  132. ELSE IF (Mailer='E') THEN DO
  133.     mda_path = 'filter.exe'
  134.     mda_args = '-u' loginname
  135. END
  136. ELSE DO
  137.     mda_path = value('COMSPEC',,'OS2ENVIRONMENT')
  138.     mda_args = '/C LaMailer.cmd -dest' inbasket '-to $u'
  139. END
  140.  
  141. /**********************************************************************
  142.    When mail arrives, popclient runs the mail delivery agent
  143.    specified by MDA_PATH with arguments MDA_ARGS.  This
  144.    sets the environment to the correct MDA.
  145. **********************************************************************/
  146. rc = Value('MDA_PATH',mda_path,'OS2ENVIRONMENT')
  147. rc = Value('MDA_ARGS',mda_args,'OS2ENVIRONMENT')
  148.  
  149. Counter = 0
  150. DO Until (Delay=0 | Counter>10)
  151.     SAY Time()
  152. /**********************************************************************
  153. This was used to write directly to the elm mailbox, bypasing filter.
  154. It is now obsolete.  Using filter is more stable than writing directly
  155. to mbox; maybe someday we'll have something better than filter, too.
  156.     IF ((Mailer='E') | (Mailer='e')) THEN
  157.         '@'PopClient '-u' Loginname '-p' Password,
  158.             ' -o' Inbasket Host
  159.     ELSE
  160. **********************************************************************/
  161.  
  162.     TmpFile = SysTempFileName( TmpDir'\PopJunk.???' )
  163.  
  164.     "@"PopClient "-u" Loginname "-p" Password OtherArgs Host "2>" TmpFile
  165.  
  166.     /* If there's an error, just beep and continue, but keep count. */
  167.     IF rc > 1 THEN DO
  168.         IF (PopUp) THEN
  169.             "@start" PopupExe "POPCLID.CMD: POPCLIENT.EXE returned error(",
  170.                                rc")"
  171.         ELSE
  172.             say 'POPCLID.CMD: POPCLIENT.EXE returned error ('rc')'
  173.         /* Does user want to "hear" it?  RLW 6/5/95 */
  174.         IF (Sound) THEN DO
  175.             IF (mmpm & ErrorSoundFileExists) THEN
  176.                 CALL "PLAY.CMD" "File="ErrorSoundFile
  177.             ELSE
  178.                 CALL Beep 400, 500
  179.             END
  180.         Counter = Counter + 1
  181.         END
  182.     ELSE
  183.         Counter = 0
  184.  
  185.     NumMsgs = 0
  186.     Line = Linein( TmpFile )
  187.     Line = Linein( TmpFile )
  188.     CALL Lineout TmpFile
  189.     "@type" TmpFile
  190.     CALL SysFileDelete TmpFile
  191.     PARSE Value(Line) WITH 1 NumMsgs 'messages'
  192.     IF (NumMsgs > 0) THEN DO
  193.         IF (PopUp & (Translate(PopUpBiff)='YES')) THEN
  194.             "@start" PopupExe "You have" NumMsgs"new messages."
  195.         ELSE
  196.             SAY "You have" NumMsgs"new messages."
  197.         /* Does user want "hear" about newmail RLW 6/5/95 */
  198.         IF (Sound & NewMailSoundFileExists) THEN 
  199.             CALL "PLAY.CMD" "File="NewMailSoundFile
  200.         ELSE IF (Sound) THEN DO
  201.             CALL Beep 200, 100
  202.             CALL Beep 400, 200
  203.             END
  204.     END
  205.  
  206.     /* wait for a specified number of seconds */
  207.     CALL SysSleep Delay
  208.  
  209. IF (Counter>1) THEN DO
  210.     IF (PopUp) THEN
  211.        "@start" PopupExe "POPCLID.CMD aborted with too many errors."
  212.     ELSE
  213.         say 'POPCLID.CMD aborted with too many errors.'
  214.     END
  215. END
  216.  
  217. halt:
  218.    exit
  219.  
  220. GetArg:
  221. /**********************************************************************
  222.     Parse arguments
  223. **********************************************************************/
  224. PARSE ARG Args
  225. PARSE Value(Args) WITH Args '-o' otherargs
  226. PARSE Value(Args) WITH  1 '-h' host .       1 '-l' loginname .      ,
  227.     1 '-p' password .   1 '-d' delay .      1 '-b' inbasket .       ,
  228.     1 '-m' mailer .     1 '-u' user .       1 '-s' sound .          ,
  229.     1 '-n' newmailsoundfile .               1 '-e' errorsoundfile .
  230.  
  231. host      = ArgCheck( host, 'POPHOST', '' )
  232. loginname = ArgCheck( loginname, 'POPUSER', '' )
  233. password  = ArgCheck( password, 'POPPASS', '' )
  234. delay     = ArgCheck( delay, 'POPDELAY', '0' )
  235. inbasket  = ArgCheck( inbasket, 'INBASKET', '.' )
  236. mailer    = Translate( Left( ArgCheck( mailer, 'MDA_PROG', 'LAMAIL' ), 1 ) )
  237. user      = ArgCheck( user, 'USER', 'root' )
  238. /*  Added for Sound capability  RLW 6/5/95 */
  239. sound     = Translate( Left( ArgCheck( sound, 'POPSOUND', 'NO' ), 1 ) )
  240. newmailsoundfile = ArgCheck( newmailsoundfile, 'NEWMAILSOUNDFILE', '' )
  241. errorsoundfile = ArgCheck( errorsoundfile, 'ERRORSOUNDFILE', '' )
  242.  
  243. IF ((host='') | (loginname='') | (password='')) THEN SIGNAL HELP
  244. RETURN
  245.  
  246. ArgCheck:
  247. /**********************************************************************
  248.     Check whether the arg was passed; if not get from OS/2 env var; if
  249.     that's empty, use default.
  250. **********************************************************************/
  251. PARSE ARG RexxVar, OS2Var, Default
  252. IF (RexxVar = '') THEN DO
  253.    RexxVar = value(OS2Var,,'OS2ENVIRONMENT')
  254.    IF (RexxVar = '') THEN
  255.       RexxVar = Default
  256. END
  257. RETURN RexxVar
  258.  
  259. Help:
  260. /**********************************************************************
  261.     This gets displayed if required parms are missing or if -? is a
  262.     parm.
  263. **********************************************************************/
  264. SAY ''
  265. SAY 'PopCliD: OS/2 frontend for Carl Harris'' popclient'
  266. SAY '   by Claudio Fahey and Clark Gaylord'
  267. SAY ' '
  268. SAY 'Usage:'
  269. SAY 'popclid -h pophost -l loginname -p password [-d delay] [-b inbasket]'
  270. SAY '           [-m L|U|E] [-u user] [-n NewMailSound] [-e ErrorSound]'
  271. SAY '           [-o otherargs]'
  272. SAY ' '
  273. SAY 'The following environment variables can be used:'
  274. SAY '   POPHOST  for pophost'
  275. SAY '   POPUSER  for loginname'
  276. SAY '   POPPASS  for password'
  277. SAY '   POPDELAY for delay, defaults to 0, i.e., retrieve mail once only'
  278. SAY '   INBASKET for inbasket, defaults to current directory, should be'
  279. SAY '            SERVER''s inbox for UltiMail Lite, incoming mbox for Elm.'
  280. SAY '   MDA_PROG LaMail, Ultimail, or Elm; only first letter significant'
  281. SAY '   USER     for Ultimail inbasket, defaults to root.'
  282. SAY '   L|U|E    for LaMail (default), Ultimail, or Elm'
  283. /* Follow added to describe MMPM options  RLW 6/5/95 */
  284. SAY '   POPSOUND for making noise on errors and new mail'
  285. SAY '   NEWMAILSOUNDFILE for specifing which sound file to play on new mail'
  286. SAY '   ERRORSOUNDFILE for specifing which sound file to play on error'
  287. EXIT
  288.  
  289. PlaySoundFile: Procedure
  290. /**********************************************************************
  291.     Routine to "play" a WAV file from REXX using MMPM/2   RLW 6/5/95 
  292.     Even though we don't use this anymore, I'm keeping it in for 
  293.     future generations.     CKG
  294. **********************************************************************/
  295.    Parse Arg FileName
  296.    if FileName='' then return
  297.    if Stream(FileName,'c','query exist')='' then return
  298.    Call mciSendString 'open waveaudio alias sound wait'
  299.    Call mciSendString 'set sound time format ms wait'
  300.    Call mciSendString 'load sound' FileName 'wait'
  301.    Call mciSendString 'play sound wait'
  302.    Call mciSendString 'close sound wait'
  303.    call mciRxExit
  304. Return
  305.  
  306. mciSendString: Procedure
  307. /* Helper routine for playing WAV files RLW 6/5/95 */
  308.    Parse Arg string
  309.    if string='' then return
  310.    rc = mciRxSendString(string, 'RetStr', '0', '0')
  311. return
  312.  
  313. FlushQueue: Procedure
  314. /**********************************************************************
  315.    Flush the REXX queue.   CKG
  316. **********************************************************************/
  317.     DO While (Queued() > 0)
  318.         PULL null
  319.     END
  320.     RETURN
  321.  
  322. Changed:
  323. /**********************************************************************
  324.    These lines are only for reference; the program never gets here.   
  325.    CKG
  326. **********************************************************************/
  327. /*********************************************************/
  328. /* Edit the following lines to configure this program:   */
  329. /*********************************************************/
  330. host = 'pop.server'                 /* POP host name                */
  331. loginname = 'loginnameonpop'        /* Login name on the host       */
  332. password = 'password'               /* Password on the host         */
  333. delay = 600                         /* Seconds between mail checks  */
  334.