  DELIVERF DELIVER is an adjunct to VMS MAIL which makes it possible for incomingF mail  messages  to  be  handled  and  processed automatically based onF information provided in a user-supplied file.  Different  actions  canF be  taken  based  on  a message's address, subject or contents.  TheseF actions include delivering the message, forwarding the message or evenF invoking  a DCL command script to perform some complex operation.  AnyF actions taken occur immediately upon receipt of the message; the  user/ does not need to log in for DELIVER to operate.   F The MAIL.DELIVERY file controls DELIVER and tells  it  how  to  handleF each message.  A MAIL.DELIVERY file consists of a series of directivesF with one directive on each line of the file.  Each directive specifiesF how  a  certain  kind  of  message  is  to  be  handled.  A particularF directive may or may not apply to a given message.  An attempt is madeF to  apply  every  directive in the MAIL.DELIVERY file to each message,F thus more than one directive may apply to (and more  than  one  action' may be the result of) a single message.   F Any line in the file which begins with a semicolon or  an  exclamation3 point is considered to be a comment and is ignored.   F A directive line consists of the following items in order from left to right:  F     <from-pat> <to-pat> <subject-pat> <accept> <action> <para> <para2>  F Items must be delimited by one or more spaces or tabs.  Quoted stringsF (use  double  quotes,  not single quotes) are allowed as single items;F the quotes are removed from the items as  they  are  read.   A  doubleF quote can be obtained by using two double quotes with no space betweenF them.  This form of quote handling is consistent with that of VMS DCL.  F The <para> and <para2> items are both optional and may be  omitted  ifF the  <action>  requires  no  parameters.   The  first  five  items are2 mandatory and must appear on every directive line. 3 Applicability F The <from-pat>, <to-pat>, <subject-pat> and <accept>  items  determineF whether  or  not  the  directive  applies  to a particular message.  AF string  comparison  is  performed  between  the  patterns  <from-pat>,F <to-pat>  and  <subject-pat>  and  the  "From:",  "To:" and "Subject:"F fields of the message header respectively.  The comparison is not caseF sensitive.   The  usual  VMS  wildcard characters ("*" and "%") can be; used in the patterns.  The pattern "*" will match anything.   F Once the comparisons have been performed, the <accept> item determinesF if  the  directive  should  be applied to the message.  Only the firstF character of <accept>  is  significant.   It  should  be  one  of  the
 following:  :     A - always apply this directive; ignore the results of:         the comparisons. Note that this directive does not>         count as an applied directive (see O, B, and E below).9     X - never apply this directive; ignore the results of          the comparisons.9     T - apply this directive if the patterns all matched. ?     F - apply this directive if the patterns did not all match. <     O - apply this directive if the patterns all matched and>         no previous directive has been applied to the message.;         Directives that used the A accept item don't count           as having been applied. ;     B - apply this directive if a pattern did not match and >         no previous directive has been applied to the message.;         Directives that used the A accept item don't count           as having been applied. :     E - this directive applies if all the patterns matched6         OR no other directive has been applied so far.;         Directives that used the A accept item don't count           as having been applied.   F Any character whatsoever is legal:  Y is the same as T, N is the  sameF as F, question mark is the same as O, Q is the same as B and all other characters are the same as X.   F Directives are tested in the order they appear  in  the  MAIL.DELIVERY file.   F For example, suppose JIM sends a message to BOB.  The subject line  ofF the  message  is "Re:  Mooses".  BOB's MAIL.DELIVERY file contains theF following lines (the function of the last two columns  of  each  line,3 the <action> and <para> items, is described later):        "FRED *" * *         T Q$     "JIM *"  * *         T A JIM.LOG&     *        * *mooses*  T A MOOSE.LOG&     *        * *         O A OTHER.LOG     *        * *         A D  F The first directive in the file does not apply since  the  message  isF not  from  FRED.  The second and third directives both apply since JIMF is the sender and the subject line contains the string "mooses".   TheF fourth  directive's patterns all apply, but a preceeding directive hasF applied, so it does not apply.  The final directive applies  since  itF would apply to any message.  The result is that three directives applyF to this  message,  and  thus  three  separate  actions  are  taken  in processing the message.   F Note:  The patterns "FRED *" and "JIM *" are  useful  since  VMS  MAILF lets  users  set  up  personal  name  fields  which become part of theF "From:" field of the message --  the  personal  name  is  enclosed  inF quotes  and  appended  to  the  user name.  Depending on personal nameF fields for message handling is not a good idea since some users have aF tendency to change personal names frequently and without warning.  TheF use of the space followed by an asterisk will match any personal  nameF field  a  user  sets  up;  the result is a MAIL.DELIVERY file which is insensitive to personal names.  F If none of the directives in the  file  are  found  to  apply  to  andF process  the  message  in  some  way,  the  message  is just delivered? normally.  The effect is equivalent to the following directive:   
     * * * A D 	 3 Actions F The <action> and <para> items specify what  action  is  taken  when  aF directive  is  applied  to a message.  The first character of <action>F specifies what type of action  to  take.   The  legal  characters  for <action> and what they do are:  ?     A - append the body (or contents) of the message to a file. ?         The <para> item specifies the file name. The file need  A         not already exist: if necessary, it will be created. The  D         recipient must have write access  to the file, if it exists,D         and write access to its directory if it needs to be created;B         DELIVER grants the user no special file access privileges.<     C - copy the body of the message to a file whose name is7         <para>. Write access to the directory where the *         file is to be created is required.>     D - deliver the message normally. Under VMS V5.0 or later,8         this is done using the FOLDER utility. <para> is>         the name of the folder the message is to be placed in.5         If <para> is omitted the message is placed in =         the NEWMAIL folder by default. Under earlier versions ;         of VMS, the message is placed in the NEWMAIL folder 8         using VMS MAIL. <para> is ignored. If <para2> is?         specified it gives the name of the mail file containing >         the specified folder. If <para2> is omitted the user's"         default mail file is used.D     H - append the header (in conventional VMS MAIL format) and the E         body (or contents) of the message to a file.  One blank line  @         is written between the header and the body.  The <para> F         item specifies the file name. The file need not already exist:B         if necessary, it will be created. The recipient must have D         write access to the file, if it exists, and write access to D         its directory if it needs to be created; DELIVER grants the /         user no special file access privileges. =     V - deliver the message normally using system privileges. ;         Under VMS V5.0 or later this action is identical to ;         action "D" above. Under earlier versions of VMS the ;         "From:" field of the message header is set to match >         the name of the original sender instead of the name of>         the user. This action makes use of the DELIVER foreign>         mail interface in incoming mode which in turn requires?         that the user be fully privileged. General users should          use action "D" instead. @     E - execute the specified command. The DCL command specified9         by <para> is executed. The command is executed in ;         the environment of the recipient's own account. Any 9         noninteractive DCL command is valid, including an @         indirect command file specification. Several DCL symbols8         can be used in the command to facilitate message         processing:   7         FROM           - the message's "From:" address. 5         TO             - the message's "To:" address. 2         SUBJECT        - the message's "Subject:".-         CC             - the message's "Cc:". 5         QFROM          - "From:" with quotes doubled. 8         QQFROM         - "From:" with quotes quadrupled.3         QTO            - "To:" with quotes doubled. 6         QQTO           - "To:" with quotes quadrupled.8         QSUBJECT       - "Subject:" with quotes doubled.;         QQSUBJECT      - "Subject:" with quotes quadrupled. 3         QCC            - "Cc:" with quotes doubled. 6         QQCC           - "Cc:" with quotes quadrupled.<         MESSAGE_FILE   - the name of the file containing the:                          body of the message. MESSAGE_FILE3                          is always fully qualified. <         MESSAGE_HEADER - the name of the file containing the?                          headers of the message. MESSAGE_HEADER 3                          is always fully qualified. 8         MESSAGE_DELETE - initially set to "YES", if this>                          symbol is set to "NO" no attempt will<                          be made to delete MESSAGE_FILE and >                          MESSAGE_HEADER after all actions are 6                          complete. The M <action> sets8                          MESSAGE_DELETE to "NO" as well.  ?         The "Q" forms are useful if the symbol must be expanded A         inside a quoted string. The MESSAGE_DELETE flag is useful C         if MESSAGE_FILE and/or MESSAGE_HEADER have to be queued for E         further processing at a later time, or if one of the actions  !         has already deleted them. <     F - forward the message. The message is forwarded to the$         address specified by <para>.@     W - forward the message using system privileges. This action@         is identical to action "F" above except that the "From:"?         field of the message header is set to match the name of A         the original sender instead of the name of the user. This A         action makes use of the DELIVER foreign mail interface in =         incoming mode which in turn requires that the user be >         fully privileged.  General users should use action "F"         instead.    ?     Q - quit; take no action and abort. If this action is taken =         DELIVER stops scanning the MAIL.DELIVERY file at this =         point. No subsequent directives will apply after this =         one. Use this directive with care; it is very easy to 3         lose messages when this action is employed. C     K - save the command file after execution. Normally the command C         file created on behalf of the user is deleted automatically ;         after execution. This action, if used inhibits this          automatic deletion. B     L - save the batch log of the DCL commands executed by DELIVER<         for each message processed in the file <para> in theC         user's login directory. This option is useful for debugging A         MAIL.DELIVERY files and command scripts. If more than one A         L <action> is triggered only the last one has any effect. F     M - save the message and header files after execution of the batchE         job. The message and header files are normally deleted as the >         last step of processing by the batch job. This action B         suppresses the automatic deletion; the same effect can be <         obtained by setting the MESSAGE_DELETE flag to "NO".@     J - Set the batch queue or a queue parameter used to run the@         command file produced by DELIVER. DELIVER uses the queue>         DELIVER_BATCH by default; if this queue not defined or?         inaccessible by the message recipient (the owner of the E         MAIL.DELIVERY file) the queue SYS$BATCH will be used instead. A         The J action provides a way to specify an alternate queue B         and/or a job parameter. If a single <para> is specified it@         is the name of the queue. If both <para> and <para2> areC         specified the former gives the name of the job parameter to C         set and the latter gives the value to set the parameter to. B         Currently the only parameters supported are P1 through P8,C         which set the corresponding positional job parameter to the $         string specified in <para2>.  C         If the queue specified with the J action cannot be used the D         DELIVER_BATCH queue or SYS$BATCH queue will be used instead.  F For example, suppose that BOB  sends  JIM  a  message.   JIM  has  the. following (rather complex) MAIL.DELIVERY file:  =     ! Messages with subject "Loopback" are returned to sender      "JIM *"   * "Loopback" T D@     *         * "Loopback" O F """''F$ELEMENT(0,"" "",QFROM)'"""     *         * "Loopback" T Q#     ! All other messages are logged *     *         * *          A E @LOGALL.COM"     ! Just log messages from TERRY     "TERRY *" * *          T Q+     ! Just log archive messages from myself      "JIM *"   * "Archives" T Q.     ! Save messages from BOB in a special file&     "BOB *"   * *          T A BOB.LOG.     ! Then deliver anything that gets this far     *         * *          A D  1 JIM's LOGALL.COM contains the following commands:   #     $ from    == "From:    " + from !     $ to      == "To:      " + to &     $ subject == "Subject: " + subject.     $ open/append/error=make_one x message.log     $ next:      $ write x ""     $ write x from     $ write x to     $ write x subject      $ write x ""
     $ close x '     $ append 'message_file' message.log 
     $ exit     $ !      $ make_one:      $ create message.log     $ open/append x message.log      $ goto next   6 (The same effect could be achieved now by substituting  *     *         * *          A H MESSAGE.LOG   for   *     *         * *          A E @LOGALL.COM  F and would moreover have the advantage of also logging the "Cc:"  field of the incoming mail.)  F If the subject line of BOB's message is not the string "Loopback", theF message  will be logged with a header in the file MESSAGE.LOG (locatedF in JIM's SYS$LOGIN directory), appended to the  file  BOB.LOG  withoutF any  header and delivered to JIM's NEWMAIL folder.  If subject line isF the string  "Loopback",  JIM's  MAIL.DELIVERY  file  will  bounce  the message right back to BOB.  F As another example, if TERRY sends a message to BOB,  the  message  isF logged  only  in  BOB's  MESSAGE.LOG  file;  BOB  never  receives  anyF notification that the message arrived.  Apparently  TERRY  never  says anything of importance to BOB.  F It is clear that the ability  to  execute  an  arbitrary  set  of  DCLF commands  in  response to a message is a very powerful tool.  It must,F however, be used with care, since processing is initiated  whenever  aF message   is   received   and  operates  in  a  completely  unattended environment.  D Full DELIVER documentation is in DELIVER.MEM. DELIVER was written by Greg Wonderly.  