home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mail.zip / MAIL.CMD < prev    next >
OS/2 REXX Batch file  |  1995-09-10  |  17KB  |  394 lines

  1. /**********************************************************************/
  2. /*                                                                    */
  3. /* MAIL.CMD version 1.1                                               */
  4. /*                                                                    */
  5. /* REXX-script to make a connection with the Internet, exchange       */
  6. /* mail and news, and terminate the connection.                       */
  7. /*                                                                    */
  8. /* Written and copyrighted by Ruud Senden, 1995                       */
  9. /*                                                                    */
  10. /**********************************************************************/
  11.  
  12. /**********************************************************************/
  13. /* Start of user variables, it is all right to change these.          */
  14. /* Please see MAIL.DOC for information about these variables.         */
  15. /*                                                                    */
  16. logFile     = 'E:\INTERNET\ACCU\MAIL.LOG'    /* Logfile               */
  17. dirExport   = 'E:\INTERNET\ACCU\SOUP'        /* Process mail to send  */
  18. dirSend     = 'E:\INTERNET\ACCU\SOUP\REPLY'  /* Send mail and news    */
  19. dirRecv     = 'E:\INTERNET\ACCU\SOUP'        /* Receive mail and news */
  20. dirImport   = 'E:\INTERNET\ACCU\SOUP'        /* Process received mail */
  21.  
  22. prgExport   = 'SOUP2SQ -s'                   /* Process mail to send  */
  23. prgSend     = 'SOUPER -s'                    /* Send mail and news    */
  24. prgRecv     = 'SOUPER'                       /* Receive mail and news */
  25. prgImport   = 'SOUP2SQ -r'                   /* Process received mail */
  26.  
  27.                                              /* Initialise connection */
  28. prgConnect  = 'DETACH ppp.exe com1 19200 mru 1500 rtscts modem defaultroute priority 1 notify exit idle 15 connect "accu.cmd"'            
  29. prgKill     = 'PPPKILL'                      /* Terminate connection  */
  30.  
  31. newsServer  = 'news.cs.ruu.nl'               /* News server           */
  32.  
  33. timeout1    = 300                            /* First timeout         */
  34. timeout2    = 60                             /* Second timeout        */
  35. triggerFile = 'E:\INTERNET\ACCU\CONNECT.TMR' /* File needed for timer */
  36. /*                                                                    */
  37. /* End of user variables, don't change anything after this point.     */
  38. /**********************************************************************/
  39.  
  40. parse upper arg HangUp  /* Parse program parameters                   */
  41.  
  42. say ''                  /* Print empty line                           */
  43. ConnectionStarted = 0   /* No Initialise Connection-cmd given         */
  44. startDir = directory()  /* Save current directory                     */
  45.  
  46. call loadFuncs          /* Load necessary external functions          */
  47. call checkFiles         /* Check logfile and triggerfile              */
  48.  
  49. signal on error name error     /* Install signal handlers to catch    */
  50. signal on failure name error   /* fatal errors, so the connection     */
  51. signal on halt name error      /* can be terminated if necessary.     */
  52. signal on syntax name error    /*                                     */
  53. signal on notready name error  /*                                     */
  54.  
  55. call export             /* Export mail and news to send from msg-base */
  56. call connect            /* Initialise connection with the Internet    */
  57. call wait_server        /* Wait for the server to become available    */
  58. call send               /* Send mail and news to the Internet         */
  59. call receive            /* Receive mail and news from the Internet    */
  60. call disconnect         /* Terminate connection with the Internet     */
  61. call import             /* Import received mail and news in msg-base  */
  62.  
  63. call directory startDir /* Reset current directory                    */
  64. call SockDropFuncs      /* Drop REXX socket-functions                 */
  65. call SysDropFuncs       /* Drop REXX utility-functions                */
  66. exit                    /* Exit REXX-script                           */
  67.  
  68.  
  69. /**********************************************************************/
  70. /* The export-function will process mail and news from your           */
  71. /* message-base to create reply-packets which will be sent to         */
  72. /* the Internet after the connection is established.                  */
  73. /* If prgExport is empty this function will be skipped.               */
  74. /*                                                                    */
  75. export:
  76.  
  77. if prgExport \= 'PRGEXPORT' & prgExport \= '' then do
  78.  
  79.    call wrt_msg 'Scanning for mail and news to send to the Internet...'
  80.    call chgDir dirExport
  81.    prgExport' >>& 'logFile
  82.  
  83.    /* The following part will only work if you use SOUP-packets,      */
  84.    /* else you'll have to change or delete it.                        */
  85.    /*                                                                 */
  86.    call chgDir dirSend
  87.    if stream('REPLIES','c','query exists') = '' then
  88.       call wrt_msg 'No mail or news available to send to the Internet.'
  89.    /*                                                                 */
  90.    /* End of SOUP-part.                                               */
  91.  
  92. end  /* Do */
  93.  
  94. return
  95. /*                                                                    */
  96. /* End of export-function.                                            */
  97. /**********************************************************************/
  98.  
  99.  
  100. /**********************************************************************/
  101. /* The connect-function will initialise the connection with the       */
  102. /* Internet.                                                          */
  103. /* If prgConnect is empty, this function will be skipped.             */
  104. /*                                                                    */
  105. connect:
  106.  
  107. if prgConnect \= 'PRGCONNECT' & prgConnect \= '' then do
  108.    call wrt_msg 'Initializing connection with the Internet...'
  109.    ConnectionStarted = 1
  110.    prgConnect
  111. end  /* Do */
  112.  
  113. return                                                                
  114. /*                                                                    */
  115. /* End of connect-function                                            */
  116. /**********************************************************************/
  117.  
  118.  
  119. /**********************************************************************/
  120. /* The wait_server-function will wait for the news-server to become   */
  121. /* available. There are two time-out values, the first one will       */
  122. /* start immediatly, the second one will start after a CONNECT-msg    */
  123. /* is received by your dial-script (a change to you dial-script is    */
  124. /* needed to enable the second time-out, see MAIL.DOC).               */
  125. /*                                                                    */
  126. wait_server:
  127.  
  128. strt2 = -1
  129. tm = time( 'Reset' )
  130. call wrt_msg 'Waiting until the news-server becomes available...'
  131.  
  132. do while SockGetHostByName( NewsServer, "host.!" ) = 0
  133.  
  134.    if timeout1 \= 0 then
  135.       if time( 'Elapsed' ) > timeout1 then do
  136.          call wrt_msg 'Timer 1 expired.'
  137.          signal error
  138.       end  /* Do */
  139.  
  140.    if timeout2 \= 0 then do
  141.       if strt2 \= -1 then do
  142.          if time( 'Elapsed' ) - strt2 > timeout2 then do
  143.             call wrt_msg 'Timer 2 expired.'
  144.             signal error
  145.          end  /* Do */
  146.       end  /* Do */
  147.       else
  148.          if stream( triggerFile, 'c', 'query exists' ) \= '' then do
  149.             strt2 = time( 'Elapsed' )
  150.             ret = SysFileDelete( triggerFile )
  151.          end  /* Do */
  152.    end  /* Do */
  153.  
  154.    call SysSleep 1
  155.  
  156. end /* do */
  157.  
  158. return
  159. /*                                                                    */
  160. /* End of connect-function.                                           */
  161. /**********************************************************************/
  162.  
  163.  
  164. /**********************************************************************/
  165. /* The send-function will send available mail and news to the         */
  166. /* Internet.                                                          */
  167. /* If prgSend is empty this function will be skipped.                 */
  168. /*                                                                    */
  169. send:
  170.  
  171. if prgSend \= 'PRGSEND' & prgSend \= '' then do
  172.    call chgDir dirSend
  173.  
  174.    /* The following check will only work if you use SOUP-packets.     */
  175.    /* If you use other packets or don't use packets at all, you will  */
  176.    /* have to change or delete this test.                             */
  177.    /*                                                                 */
  178.    if stream('REPLIES','c','query exists') \= '' then do
  179.       call wrt_msg 'Sending mail and/or news to the Internet...'
  180.       prgSend' >>& 'logFile
  181.    end  /* Do */
  182.    /*                                                                 */
  183.    /* End of SOUP-part                                                */
  184.  
  185. end  /* Do */
  186.  
  187. return
  188. /*                                                                    */
  189. /* End of send-function.                                              */
  190. /**********************************************************************/
  191.  
  192.  
  193. /**********************************************************************/
  194. /* The receive-function will receive new mail and news from the       */
  195. /* Internet.                                                          */
  196. /* If prgRecv is empty this function will be skipped.                 */
  197. /*                                                                    */
  198. receive:
  199.  
  200. if prgRecv \= 'PRGRECV' & prgRecv \= '' then do
  201.  
  202.    call wrt_msg 'Receiving new mail and/or news from the Internet...'
  203.    call chgDir dirRecv
  204.    prgRecv' >>& 'logFile
  205.  
  206.    /* This check will only work if you use SOUP-packets, else you'll  */
  207.    /* have to change or delete it.                                    */
  208.    /*                                                                 */
  209.    if stream('AREAS','c','query size') = 0 then
  210.       call wrt_msg 'No mail or news received from the Internet.'
  211.    /*                                                                 */
  212.    /* End of SOUP-part.                                               */
  213.  
  214.    end  /* Do */
  215.  
  216. return
  217. /*                                                                    */
  218. /* End of receive-function.                                           */
  219. /**********************************************************************/
  220.  
  221.  
  222. /**********************************************************************/
  223. /* The disconnect-function will terminate the connection with the     */
  224. /* Internet, or, if a parameter is specified on the command-line,     */
  225. /* it will display a message of how to terminate the connection       */
  226. /* yourself.                                                          */
  227. /* If prgKill is empty, a warning message will be shown.              */
  228. /*                                                                    */
  229. disconnect:
  230.  
  231. if ConnectionStarted = 1 then do
  232.    if prgKill = 'PRGKILL' | prgKill = '' then
  233.       call wrt_msg 'Warning: no command configured to terminate the ',
  234.                    'connection with the Internet.'
  235.    else do
  236.       if HangUp \= "" then do
  237.          say "Type '"prgKill"' at an OS/2 command prompt to terminate"
  238.          say "the connection with the Internet."
  239.       end  /* Do */
  240.       else do
  241.          call wrt_msg 'Terminating connection with the Internet...'
  242.          prgKill' >>& 'logFile
  243.          ConnectionStarted = 0
  244.       end  /* Do */
  245.    end  /* Do */
  246. end  /* Do */
  247.  
  248. return
  249. /*                                                                    */
  250. /* End of disconnect-function.                                        */
  251. /**********************************************************************/
  252.  
  253.  
  254. /**********************************************************************/
  255. /* The import-funtion imports received mail and news into your        */
  256. /* message-base.                                                      */
  257. /* If prgImport is empty, this function will be skipped.              */
  258. /*                                                                    */
  259. import:
  260.  
  261. if prgImport \= 'PRGIMPORT' & prgImport \= '' then do
  262.    call chgDir dirImport
  263.  
  264.    /* This check will only work if you use SOUP-packets, else you'll  */
  265.    /* have to change or delete this check.                            */
  266.    /*                                                                 */
  267.    if stream('AREAS','c','query size') \= 0 then do
  268.       call wrt_msg 'Processing received mail and/or news...'
  269.       prgImport' >>& 'logFile
  270.    end  /* Do */
  271.    /*                                                                 */
  272.    /* End of SOUP-part.                                               */
  273.  
  274. end  /* Do */
  275.  
  276. return
  277. /*                                                                    */
  278. /* End of import-function                                             */
  279. /**********************************************************************/
  280.  
  281.  
  282. /**********************************************************************/
  283. /* the loadFuncs-function loads the necessary external functions.     */
  284. /*                                                                    */
  285. loadFuncs:
  286.  
  287. if RxFuncQuery( "SysLoadFuncs" ) then do
  288.    call RxFuncAdd "SysLoadFuncs", "REXXUTIL", "SysLoadFuncs"
  289.    call SysLoadFuncs
  290. end /* Do */
  291.  
  292. if RxFuncQuery( "SockLoadFuncs" ) then do
  293.    call RxFuncAdd "SockLoadFuncs", "RxSock", "SockLoadFuncs"
  294.    call SockLoadFuncs "NoLogo"
  295. end /* Do */
  296.  
  297. return
  298. /*                                                                    */
  299. /* End of loadFuncs-function                                          */
  300. /**********************************************************************/
  301.  
  302.  
  303. /**********************************************************************/
  304. /* The checkFiles-function checks whether the given logfile is        */
  305. /* valid and removes some files                                       */
  306. /*                                                                    */
  307. checkFiles:
  308.  
  309. ret = stream( logFile, 'c', 'open' )
  310. if ret \= 'READY:' then do
  311.    say "Can't open logfile "logFile" ("ret")."
  312.    say "Please check the logFile variable which can be found"
  313.    say "at the top of this REXX-script."
  314.    signal error
  315. end  /* Do */
  316. ret = stream( logFile, 'c', 'close' )
  317. ret = SysFileDelete( triggerFile )
  318. ret = SysFileDelete( logFile )
  319.  
  320. return
  321. /*                                                                    */
  322. /* End of checkFiles-function.                                        */
  323. /**********************************************************************/
  324.  
  325.  
  326. /**********************************************************************/
  327. /* The chgDir-function changes to another directory, displaying an    */
  328. /* error-message and terminating the program if it fails.             */
  329. /* If the given parameter is empty, this function will be skipped.    */
  330. /*                                                                    */
  331. chgDir:
  332.  
  333. parse arg newDir
  334. if newDir \= '' then do
  335.    curDir = directory( newDir )
  336.    if curDir \= newDir then do
  337.       say ''
  338.       say 'Error changing directory to 'newDir'!'
  339.       say 'Please check the variables at the top of this REXX-script.'
  340.       signal error
  341.    end  /* Do */
  342. end  /* Do */
  343.  
  344. return
  345. /*                                                                    */
  346. /* End of chgDir-function.                                            */
  347. /**********************************************************************/
  348.  
  349.  
  350. /**********************************************************************/
  351. /* The wrt_msg-function writes a message to both the logfile and      */
  352. /* the screen.                                                        */
  353. /*                                                                    */
  354. wrt_msg:
  355.  
  356. parse arg msg
  357.  
  358. ret = lineout( logFile, '' )
  359. ret = lineout( logFile, msg )
  360. ret = lineout( logFile, '' )
  361. ret = stream( logFile, 'c', 'close' )
  362. say msg
  363.  
  364. return
  365. /*                                                                    */
  366. /* End of wrt_msg-function.                                           */
  367. /**********************************************************************/
  368.  
  369.  
  370. /**********************************************************************/
  371. /* The error-function is called when an error occures. It displays    */
  372. /* a message, calls the function disconnect, resets the current       */
  373. /* directory, drops the loaded REXX-functions and terminates the      */
  374. /* program.                                                           */
  375. /*                                                                    */
  376. error:
  377.  
  378. say ''
  379. say 'Abnormal program termination.'
  380.  
  381. call disconnect
  382. call beep 50, 500
  383. call directory startDir
  384.  
  385. if \ RxFuncQuery( 'SockDropFuncs' ) then
  386.    call SockDropFuncs
  387. if \ RxFuncQuery( 'SysDropFuncs' ) then
  388.    call SysDropFuncs
  389.  
  390. exit
  391. /*                                                                    */
  392. /* End of error-function.                                             */
  393. /**********************************************************************/
  394.