procmail
[Top] [All Lists]

Re: Matching the nth-to-last occurrence of a header field

2002-04-07 14:30:33
Aaron wrote,

| You can use the fact that procmail will stop matching scored
| conditions once it reaches the supremum score to find an arbitrarily
| numbered occurrence of a header from the bottom.

Interesting approach, and good idea, but something confused me.

| :0
| # The first number here is the header number from the bottom
| # which we wish to match (2 in this case)
| * 2^0
| # Count the total number of the type of header
| * -1^1 ^Received:
| # Get the score appropriately close to the supremum value
| * 2147483646^0

Ah, I see, that figure always has to be max-1 and isn't dependent on the
offset.  Now I get it.  I think your comment confused me; I figured
"appropriately" meant for the particular offset and thought the weight was
supposed to be max-offset+1 or something.

| # Now find the right one
| * 1^1 ^\/Received:.*
| { LOG="$MATCH" }

| If there are less than the desired number of Received: headers $MATCH
| will remain what it was before this recipe.

Best thing is to unset MATCH before the recipe.  You could then add an
unweighted condition at the end:

 * $!${MATCH+!}

so that the logging, or whatever the action is, would be executed only if
there are enough Received: headers.

That was inspired, Aaron.



_______________________________________________
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>