procmail
[Top] [All Lists]

Re: Variables on Conditions

2001-02-08 12:47:49
"Carlos Eduardo R. L. de Miranda" <consultor(_at_)linuxbr(_dot_)com(_dot_)br> 
writes:
I would like to now if it is possible to have VARIABLES on conditions.
On the example bellow, if I replace $LOGIN(_at_)$DOMAIN w/ 
test(_at_)tamclick(_dot_)com(_dot_)br,
it works as expected.

# File: .procmailrc
<deleted>
LOGIN=test
DOMAIN=tamclick.com.br
PMDIR=$HOME/procmail
INCLUDERC=$PMDIR/setmessage.rc

# File: setmessage.rc
:0 b
* From(_dot_)$LOGIN(_at_)$DOMAIN
* Subject: setmessage
  | cat > $PMDIR/iamin.msg

As Don Hammond has already answered, you need the '$' condition special
to tell procmail to expand variables in the regexp.  I just wanted to add
that you probably want to tighten up those regexps slightly by requiring
them to match against the beginning of the line, and to match the "From:"
header and not the "From " pseudo-header.

        :0 b
        * $ ^From:(_dot_)*$\LOGIN(_at_)$\DOMAIN
        *   ^Subject: *setmessage
        | cat > $PMDIR/iamin.msg

You'll note two other changes: I added a '*' to the second condition so
that it'll still match if there's more than one space after the colon,
or even if there are no space there.  The other change is from "$LOGIN"
to "$\LOGIN" and "$DOMAIN" to "$\DOMAIN".  Putting a backslash between
the '$' and the variable name tell procmail to escape any characters            
special to the regexp engine, such that the literal value stored in the
variable will be matched, instead of what it represents as a regexp.
While that probably doesn't change anything in the case of $LOGIN,
it'll force the periods in $DOMAIN to match actual periods instead of
matching any character.


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

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