procmail
[Top] [All Lists]

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

1997-10-24 01:25:55
Hello folks,

I simply can't get it right :-).  What I want is this (expressed here in
a fictive programming language):

   ADMIN = ...      # This may or may not set ADMIN to the empty string.

   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.

   if $ADMIN != ''                    # If ADMIN now turns out non-empty
   then                          # then re-process the mail by piping it
      formail ... | sendmail ...      # through "formail" and "sendmail"
   else            # else stuff the mail into the default mailbox as is.
      "Mail -> $DEFAULT"
   endif

The corresponding statements in my "procmailrc" file look like this:

   .
   .
   .
NB_ADMINS = $HOME/.NetBackup.admins  # File containing admin mail addrs.
VERBOSE   = yes

:0 HD                            # Check mail concerning normal backups.
* ^From: <root-netbackup(_at_)rrze
* ^Subject: Backup by root on .*\.\.\.$
{

   .
   .
   .

  ADMIN = `egrep "^$CLIENT *:" "$NB_ADMINS" | cut -d ':' -f 2`

  :0 c  # If no admin is found for a local host that isn't maintained by
  * ! ? test -n "$ADMIN"
  * ! ? echo "$CLIENT" | egrep '[._]|^cshp|^hp11'
  { ADMIN = root-$CLIENT }       # myself, prepend "root-" to host name.

  :0                         # If admin of client is known add "Cc:" and
  * ? test -n "$ADMIN"
  | $FORMAIL -A "Cc: $ADMIN" \
             -A 'Reply-To: Woitok(_at_)RRZE(_dot_)Uni-Erlangen(_dot_)DE' \
    | $SENDMAIL -oi -t            # "Reply-To:" headers and resend mail.

  :0:                         # Otherwise let's see the unmodified mail.
  $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
continues with an empty variable ADMIN  and thus delivers the unmodified
mail to the mailbox while the other sibling contains "root-..." in ADMIN
and thus passes the mail to "formail" and "sendmail" as it should.

procmail: Assigning "ADMIN="
procmail: Executing " test -n "$ADMIN""
procmail: Program failure (1) of " test -n "$ADMIN""
procmail: Match on ! " test -n "$ADMIN""
procmail: Executing " echo "$CLIENT" | egrep '[._]|^cshp|^hp11'"
procmail: Program failure (1) of " echo "$CLIENT" | egrep '[._]|^cshp|^hp11'"
procmail: Match on ! " echo "$CLIENT" | egrep '[._]|^cshp|^hp11'"
procmail: Forking "procmail"
procmail: [4415] Tue Oct  7 02:27:40 1997
procmail: Assigning "ADMIN=root-paris"
procmail: Executing " test -n "$ADMIN""
procmail: Executing " test -n "$ADMIN""
procmail: Match on " test -n "$ADMIN""
procmail: Executing " $FORMAIL -A "Cc: $ADMIN" \
             -A 'Reply-To: Woitok(_at_)RRZE(_dot_)Uni-Erlangen(_dot_)DE' \
    | $SENDMAIL -oi -t            # "Reply-To:" headers and resend mail."
procmail: Program failure (1) of " test -n "$ADMIN""
procmail: No match on " test -n "$ADMIN""
procmail: Locking "/mail/rzhome/unrz33.lock"
procmail: Assigning "LASTFOLDER= $FORMAIL -A "Cc: $ADMIN" \
             -A 'Reply-To: Woitok(_at_)RRZE(_dot_)Uni-Erlangen(_dot_)DE' \
    | $SENDMAIL -oi -t            # "Reply-To:" headers and resend mail."

Of course I do not want to receive the additional unmodified copy of the
mail but rather  only  the re-processed  one (this doesn't cause  a loop
since this  part of the  "procmailrc" file is  only executed if the mail
doesn't already contain a "Cc:" header).  What am I supposed to do?  How
do you code  a simple "if ... then  ... endif ... additional  statements
...." in your "procmailrc" file?

Maybe I just don't  see  the forest because of   the trees :-), but  I'm
searching for a solution of this problem for such a long time now that I
thought I might as well ask somebody who might know :-)

Any help appreciated :-)

Oh, and before I forget: please reply privately as I'm not on this list.
For your convenience I'v already added  a "Reply-To:" header pointing my
way, but some lists filter this out, so make sure your reply does really
reach me :-)

Sincerely
 Rainer

 ----------------------------------------------------------------------
| Rainer M Woitok                  | Phone: (+49-9131) 85-7811, -7031  |
| Regionales Rechenzentrum         |                                   |
| Friedrich-Alexander-Universitaet | Fax  : (+49-9131) 30 29 41        |
| Martens-Strasse 1                | Telex: d 629 755 tf erl           |
| D-91058 Erlangen                 |                                   |
| Germany                          | Mail: 
Woitok(_at_)RRZE(_dot_)Uni-Erlangen(_dot_)DE |
 ----------------------------------------------------------------------

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