procmail
[Top] [All Lists]

Re: help! procmail stops in the middle of my recipe

2002-07-02 12:24:52
On  2 Jul, procmail wrote:
| Given the following recipe, if no value is found - which sometimes will
| be the case - procmail does not continue reading the recipe and never
| gets to the end where the program is triggered using the input values.
| 
| What syntax is necessary in order for procmail to continue reading
| and processing even though it encounters no value for one or more
| fields?
| 
| 
| SHELL=/bin/sh
| PATH=$HOME/bin:/usr/bin:/usr/ucb:/bin:/usr/local/bin:.
| MAILDIR=$HOME/mail      # You'd better make sure it exists
| DEFAULT=$MAILDIR/mbox
| LOGFILE=$MAILDIR/log
| LOG="
| "
| LOGABSTRACT=all
| VERBOSE=yes
| 
| :0
| * ^Subject: ref*
| {
| :0
|   * ^Subject: *\/ref[^ ]+
|   {
|          REF=$MATCH
| 
|          :0B
|          * ^Enter the domain name:\/.+[a-z0-9]
|          {
|                  NEWDOM=$MATCH
| 
|                  :0B
|                  * ^First and last name of contact:\/.+[a-z0-9]
|                  {
|                          CONTACT=$MATCH
| 
| [snip more nested recipes]

This is happening because you've nested each successive recipe. As soon
as any ONE condition does not match, everything else within the braces
will be ignored (i.e. from the opening brace until the matching closing
brace for that recipe). For example, looking above, if the body of the
message doesn't match "^Enter the domain name:\/.+[a-z0-9]", then
nothing between the next brace and it's closing mate (which is at the
bottom AFTER the intended "delivery") will be executed by procmail.

You probably want something like:

:0
* ^Subject: *\/ref[^ ]+
{
  REF="$MATCH"
  :0B
  * ^Enter the domain name:\/.+[a-z0-9]
  {  NEWDOM="$MATCH"  }

  :0B
  * ^First and last name of contact:\/.+[a-z0-9]
  {  CONTACT="$MATCH"  }

  # and so on ... a different recipe for each possible variable

  :0ci
  | /usr/local/adm/build_domain ${NEWDOM:-unknown} ${CONTACT:-unknown} \
    ${EMAIL:-unknown} ${PHONE:-unknown} ${ORG:-unknown} \
    ${NEWHOST:-unknown} ${IPADDRESS:-unknown} ${CNAME:-unknown}
  :0
  $DEFAULT
}

A couple notes:  I changed your variable HOST to NEWHOST.  HOST is used
by procmail and you don't want to change it here.  Some of the
variables, if not matched and set by the body of the message might be
better with something other unknown (e.g. ${NEWHOST:-""}), but you get
the idea.  This does nothing to check that mandatory elements, if there
are any, are actually set.  Your regular expressions might not be doing
what you expect.  ".+" will match any character (except newline) any
number of times, so ".+[a-z0-9]" will enforce an alphanumeric as the
LAST character, but anything will match before that.  For example:

First and last name of contact: ¿¿¿¿ ¿¿ ¿¿  ¿¿¿ abc ¿¿¿

matched against "* ^First and last name of contact:\/.+[a-z0-9]"

would return: " ¿¿¿¿ ¿¿ ¿¿  ¿¿¿ abc".  
   
I suspect that's not what you want, but don't want to speculate what
that might be. Bottom line is, error checking, etc. is left as an
exercise to the reader.

Lastly, I made the pipe to your script a "c"opy|clone recipe with the
original delivered to $DEFAULT.  That would seem prudent under the
circumstances.  At least that way you can recover manually if this
blows up.

-- 
Reply to list please, or append "8" to "procmail" in address if you must.
Spammers' unrelenting address harvesting forces me to this...reluctantly.


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail