procmail
[Top] [All Lists]

Re: Capture MATCH?

2001-07-16 22:14:11
Professional Software Engineering wrote:
At 17:09 2001-07-16 -0400, James Ervin did say:

1.  obviously I can not do a variable assignment inside of a 
recipe........should I write a scribe that would assign the variable and 
pipe it through it......any other ideas?

I don't follow the logic that you cannot perform variable assignment.  As 
for making a script and piping it through, see below..

I *think* James meant that he could not assign inside of a *script*,
rather than a *recipe*.  (Environment variables changed in a child
process are not passed back to the parent process.)

[snip]

2.  my first \/ is grabbing everything after "To: " and not stopping at 
the @ sign, so even if I could capture it, it still contains the wrong data.

Check docs for MATCH - it doesn't work by stopping at the specified text - 
it assigns the match from the beginning of the match to EOL.

Not true; see below.

Which is why you'd pipe the match through sed or something like that.  An 

Better avoid extra processes (such as sed) when possible.

It doesn't assign from beginning of the match to EOL, but rather from
beginning of the match to as far as can be part of the match
(i.e., "greedy.").

Thus, to stop at the @ sign, James could replace:
    * ^To: \/(_dot_)*(_at_)externalserver(_dot_)mysite(_dot_)org
with, for example, something like this (untested):
    :0
    * ^To:.*\/[^        "<>),@]+(_at_)externalserver\(_dot_)mysite\(_dot_)org
    * MATCH ?? ^\/[^(_at_)]+
    * ... other conditions such as Content-* go here ...
    { NAME="$MATCH" }
    :0a
    ... the forwarding part that uses $NAME goes here ...

The first line selects a correct address into MATCH (note there
are both a space and a tab inside the []), and the second line
gets the part of that before the "@" into another variable, and
no external process is required.  (I used NAME instead of USER
just to avoid confusion with a variable many UNIX systems set.)

As you noted, two recipes are needed the way James wrote it
(and also the way I wrote it).

Of course, the recipient could be in Cc: rather than To:,
so "(To|Cc):" could replace "To:" above.  However, this won't
work with Bcc at all, and if it goes to more than one user this
will only pick out one (as would the other method).

Cheers,
Stan
_______________________________________________
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>