home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d9xx / d992 / cyberpager.lha / CyberPager / rexx / mwm / mailpage < prev    next >
Text File  |  1994-04-05  |  4KB  |  139 lines

  1. /*
  2.  * Script to send mail to an IXO paging service via ixo.
  3.  *
  4.  * Copyright 1992, Mike W. Meyer
  5.  * All Rights Reserved
  6.  *
  7.  * Modified by Christopher A. Wichura for use with spoolpage.
  8.  *
  9.  * Usage: mailpage [dest] [format]
  10.  *
  11.  * Format specifies what format the page should take. It is a REXX
  12.  * expression that is evaluated to determine the string to send to
  13.  * the pager. If the string is "", then no page is sent. When format
  14.  * is evaluated, the following variables are defined:
  15.  *
  16.  * message.field- the value of all the header line <field>.
  17.  * message.body    - the body of the message, with newlines and tabs
  18.  *          replaced by spaces.
  19.  * message.    - is "" for any other indices.
  20.  * who        - the user name (stripped of machine and routing info)
  21.  *          of the sender.
  22.  * what        - the subject, stripped of all initial "Re:"'s
  23.  * text        - the text of the body, with lines starting with ">"
  24.  *          deleted.
  25.  *
  26.  * Note: By using external functions, this can be a *very* powerfull facility!
  27.  */
  28. debug = 0            /* set to 1 to enable debugging messages */
  29. if ~debug then trace Background
  30.  
  31. /* Arrange things so signals send us somewhere reasonable */
  32. signal on ioerr
  33. signal on halt
  34. signal on syntax
  35.  
  36. /* Argument processing */
  37. parse arg dest format
  38. if dest = "" then do
  39.     say "no destination specified"
  40.     exit
  41.     end
  42.  
  43. if format = "" then format = "who'/'what'/'text"
  44.  
  45. /* Read in the header */
  46. message. = ""    
  47. field = ""
  48. do until eof(stdin)
  49.     line = translate(readln(stdin), ' ', '09'x)
  50.     /* Save field information for possible future use */
  51.     select
  52.         when line = "" then leave
  53.         when left(line, 1) ~= " " then do
  54.             parse var line field ':' data
  55.             field = upper(field)
  56.             message.field = strip(data)
  57.             end
  58.         when field = "" then do
  59.             if debug then say "Broken header line:" line", ignored"
  60.             end
  61.         otherwise message.field = message.field strip(line)
  62.         end
  63.     end
  64.  
  65. /* Skip to the body. */
  66. do while line = "" & ~eof(stdin)
  67.     line = readln(stdin)
  68.     end
  69.  
  70. /* Read in the body */
  71. line = strip(translate(line, ' ', '09'x))
  72. text = ""
  73. message.body = ""
  74. do while ~eof(stdin)
  75.     if line ~= "" then do
  76.         message.body = message.body || line || d2c(10)
  77.         if left(line, 1) ~= '>' then text = text || line || d2c(10)
  78.         end
  79.     line = strip(translate(readln(stdin), ' ', '09'x))
  80.     end
  81. message.body = message.body || line || d2c(10)
  82. if left(line, 1) ~= '>' then text = text || line || d2c(10)
  83. text = strip(text)
  84.  
  85. /* Set up the magic variables: inverse of text */
  86. message.body = text
  87.  
  88. /* Who, stripped down to the user name */
  89. who = message.from
  90. parse var who '<' mail '>'
  91. if mail = "" then do
  92.     firstpar = pos('(', who)
  93.     lastpar = lastpos(')', who)
  94.     if firstpar = 0 | lastpar = 0 then mail = who
  95.     else mail = delstr(who, firstpar, lastpar - firstpar + 1)
  96.     end
  97. parse var mail who '@'
  98. parse var who who '%'
  99. bangdex = lastpos('!', who)
  100. if bangdex ~= 0 then who = substr(who, bangdex + 1)
  101. who = strip(who)
  102.  
  103. /* subject, stripped of Re:'s */
  104. what = message.subject
  105. do while upper(left(what, 3)) = "RE:"
  106.     what = strip(substr(what, 4), 'Leading')
  107.     end
  108.  
  109. /* Get the date the user wants, in a clean room */
  110. data = builddata(format)
  111. if data = "" then exit 0
  112.  
  113. /* Run the command, exiting properly if it fails */
  114. options failat 21
  115. rc = 0
  116. if debug then say data
  117. else do
  118.     tempname = 't:mailpage.' || time('s')
  119.  
  120.     if open(dataout, tempname, 'W') then do
  121.         call writech(dataout, data)
  122.         call close(dataout)
  123.  
  124.         address command 'pager:bin/spoolpage' dest '<' || tempname
  125.         address command 'delete' tempname 'quiet force'
  126.         end
  127. exit rc
  128.  
  129. /* Catch errors and exit in that mode */
  130. ioerr:
  131. halt:
  132. syntax:
  133. exit 20
  134.  
  135. /* create a lexical scope with only the advertized variables visible. */
  136. builddata: procedure expose message. who what text
  137.     interpret "return" arg(1)
  138.  
  139.