procmail
[Top] [All Lists]

Re: How to code a simple "if ... then ... endif" in "procmailrc"

1997-10-25 05:31:09
On Fri, 24 Oct 1997 10:19:08 +0200,
"Dr. Rainer Woitok" <woitok(_at_)rrze(_dot_)uni-erlangen(_dot_)de> wrote:
   if $ADMIN == '' && $CLIENT !~ ^cshp|^hp11     # If ADMIN is empty and
   then                           # CLIENT doesn't match then set ADMIN.
      ADMIN = "root-$CLIENT"
   endif                                 # Now ADMIN can still be empty.

This can actually be massaged into "if client doesn't match then set
admin to root-$CLIENT unless it's already set", which is handy
because there is a "set if unset" operator in Procmail:

    :0
    * ! CLIENT ?? ^cshp|^hp11
    { ADMIN="${ADMIN:-root-$CLIENT}" }

This ${VAR:-value} stuff is borrowed from sh(1). (Actually it's not
"set if unset" but rather "value of variable or if that's not set,
this other value", which of course is more general.)

   if $ADMIN != ''                    # If ADMIN now turns out non-empty
   then                          # then re-process the mail by piping it
      formail ... | sendmail ...      # through "formail" and "sendmail"

If you look in the archives for the list, you'll see a recent thread
about how it's significant to make a distinction between ADMIN being
completely unset versus ADMIN containing at least one non-blank
character. I'm assuming the latter but in this case I'd imagine you
would rarely expect to end up with ADMIN containing only blanks. 

    :0  # The brackets contain a caret, a space, and a tab
    * ADMIN ?? [^       ]
    | formail ... | $SENDMAIL ...

The empty vs. nonblank distinction was pointed out by David Tamkin, I
believe. 

   else            # else stuff the mail into the default mailbox as is.
      "Mail -> $DEFAULT"
   endif

This is implicit by how Procmail processes the rc file from top to
bottom. If it falls of the end without having delivered your message,
it delivers to $DEFAULT.

The problem is -- as can be seen from the excerpt of the logfile -- that
the c-flag in the  first recipie causes the  "procmail" program  to fork
(yes, I know this is in accordance with the documentation).  One sibling

You rarely need a :c flag on a non-delivering recipe. Processing will
stop only if the recipe is a delivering one; yours was merely a block
with an assignment, so it's non-delivering. So you only need to lose
the c flag there. But the above snippets should hopefully help you
tighten up your code a little.

Hope this helps,

/* era */

-- 
 Paparazzi of the Net: No matter what you do to protect your privacy,
  they'll hunt you down and spam you. <http://www.iki.fi/~era/spam/>

<Prev in Thread] Current Thread [Next in Thread>