home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mlp09.zip / PAGER.CMD < prev    next >
OS/2 REXX Batch file  |  1995-07-18  |  6KB  |  174 lines

  1. /*
  2.     REXX SCRIPT FILE
  3. */
  4.  
  5. COPYRIGHT = "PAGER V1.0 by I&J Solutions, Created 07-02-95"
  6.  
  7. /*
  8.  
  9. This script file will parse the messages listed in the INBOX and based on some filters will
  10. call specified pager number with certain code.
  11.  
  12. The name of the program that calls the pager is tcomm.exe and is part of the MLP package.
  13.  
  14. The correct way to use that program is:
  15.  
  16.         tcomm /com:2 /exit:30 /dial:1234567,,,,,,09877
  17.                                                  ^^^^^-> Code for the pager
  18.                                            ^^^^^^-> delay for the modem
  19.                                     ^^^^^^^-> the number for the pager
  20.                                ^^^^->stuff that follows after ATDT command.
  21.                            ^^-> 30 secunds delay before closing the com port
  22.                       ^^^^-> after dialing the number close the com port and exit
  23.                     ^-> use COM2
  24.                ^^^->specify com port (default is COM2)
  25.  
  26.  
  27. ----------------------
  28.  
  29. This script file requires a special configuration file (pager.cf) which 
  30. would keep some keys and pager parameters. The configuration file is 
  31. organized as a table with the following fields:
  32.  
  33. SENDER;SUBJECT;PAGER;CODE
  34.  
  35.  
  36. The logic is the following:
  37.  
  38. If SENDER or SUBJECT matches the PAGER number will be dialed and CODE will be sent to the pager.
  39. The mail message will be forwarded to pager@site and deleted from the InBox folder.
  40.  
  41. EXAMPLE:
  42.  
  43. pager.cf
  44. --------
  45. jivko;page me;123-4567;9999
  46.  
  47. when e-mail from jivko@any.site is received addressed to the mailing list or E-mail with
  48. Subject: ... page me ... is received addressed to the same list the pager number 123-4567
  49. will be dialed and code 9999 will be sent to the pager.
  50.  
  51. */
  52.  
  53.  
  54.  
  55. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  56. call SysLoadFuncs
  57.  
  58. parse arg message_file extra
  59.  
  60. say COPYRIGHT
  61.  
  62. debug=0
  63. config = pager.cf
  64. PAGERTMP = pager.tmp    /* temporary file for the pager.cmd script         */
  65. COMAS = ",,,,,,,"       /* This should be enough for most pagers           */
  66. EXITDELAY=25            /* 20 secunds delay should be enough for the modem */
  67.                         /* to dial the pager and enter the code using the  */
  68.                         /* above number of comas                           */
  69.  
  70. /****************************************************************************/
  71.  
  72. if "" = message_file then
  73.   exit
  74. else do
  75.  
  76.     MESSAGE_PATH = filespec('drive',message_file)""filespec('path',message_file)
  77.     message = filespec('name',message_file)
  78.     if debug then say "Message directory: "MESSAGE_PATH
  79.     done = 0
  80.     move = 0
  81.     mfile = MESSAGE_PATH""message
  82.     if debug then say "Checking "mfile
  83.     do while lines(mfile) & (done = 0)
  84.       cl2 = strip(linein(mfile))
  85.  
  86.       done1 = 0
  87.  
  88.       /* Check for the end of the header */
  89.       /* If the end of the header we have all the information we might need so we should go and */
  90.       /* search the configuration file for matches.                                             */
  91.       if (0 = length(cl2)) then do
  92.  
  93.         /* Open the configuration file and check it out */
  94.          do while lines(config) 
  95.            cl1 = strip(linein(config))
  96.  
  97.            /* Skip comments */
  98.  
  99.            if 1 <>pos("#",cl1) then do
  100.               coma1 = pos(";",cl1)
  101.               sender = substr(cl1,1,coma1-1)
  102.               if debug then say "Sender = "sender
  103.               coma2 = pos(";",substr(cl1,coma1+1))
  104.               subj= substr(cl1,coma1+1,coma2-1)
  105.               if debug then say "Subject= "Subject
  106.               coma3 = pos(";",substr(cl1,coma1+coma2+1))
  107.               Pager= substr(cl1,coma1+coma2+1,coma3-1)
  108.               if debug then say "pager= "Pager
  109.               coma4 = pos(";",substr(cl1,coma1+coma2+coma3+1))
  110.               Code = substr(cl1,coma1+coma2+coma3+1)
  111.               if debug then say "code= "Code
  112.  
  113.               /* Now we have one record read already and we could check it out */
  114.  
  115.               if 0<pos(sender,From) | 0<pos(subject,Subj) then do
  116.  
  117.                  /* there is a match and we should beep that pager now */
  118.  
  119.                  sh = '@tcomm /com:'COMPORT' /exit:'EXITDELAY' /dial:'Pager''COMAS''CODE
  120.                  if debug then say sh
  121.                  else sh
  122.  
  123.                  /* OK. We did what we had to do with the pager. Now we need to forward that */
  124.                  /* message to pager@site and delete the original file                       */
  125.  
  126.                  rc=stream(mfile,'c','close')
  127.  
  128.                  /* Prepare a header for tha message */
  129.  
  130.                  host = value('HOSTNAME',,'OS2ENVIRONMENT')
  131.                  rc=lineout(PAGERTMP,"From: Pager.CMD@"host)
  132.                  rc=lineout(PAGERTMP,"To: Pager@"host)
  133.                  rc=lineout(PAGERTMP,"Subject: Re: Message that made me page you")
  134.                  rc=lineout(PAGERTMP,"")
  135.                  rc=lineout(PAGERTMP,"")
  136.  
  137.                  do while lines(mfile) & (done = 0)
  138.                    cl2 = linein(mfile)
  139.                    rc=lineout(PAGERTMP,cl2)
  140.                  end
  141.                  rc=stream(mfile,'c','close')
  142.                  rc=stream(PAGERTMP,'c','close')
  143.  
  144.                  sh= '@sendmail -af 'PAGERTMP' pager@'host
  145.                  if debug then say sh
  146.                  else sh
  147.  
  148.                  '@del 'mfile
  149.                  '@del 'PAGERTMP
  150.               end  /* Do */
  151.  
  152.            end
  153.          end /* do */
  154.          rc=stream(config,'c','close')
  155.  
  156.          done = 1
  157.       end
  158.  
  159.       /* If this is the From: filed get store that line */
  160.       if (1 = pos("From:",cl2)) then do
  161.          From = substr(cl2,6)
  162.       end
  163.  
  164.       /* If this is the SUBJECT: filed get store that line */
  165.       if (1 = pos("Subject:",cl2)) then do
  166.          Subject = substr(cl2,9)
  167.       end
  168.  
  169.  
  170.   end /* do */
  171.  
  172. exit
  173.  
  174.