procmail
[Top] [All Lists]

Re: Regex help

2003-04-21 11:34:45
On Mon, Apr 21, 2003 at 09:50:09AM -0500, Jim Raney wrote:

I've got this regex here:

^Received:.*\/\[[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\]$sby$smy.host.name

to grab a certain received line of the headers.  What I'd like it
do is also ignore any line where the match is [127.0.0.1] and keep
searching for the next matching line (or find the very last match of
the above).  Can anyone give me any pointers on how to do that?

In addition to the suggestions Don Hammond gave, you should note that
as soon as you say "also," your algorithm in procmail should be to
invoke a second, ANDed, condition.  Since multiple conditions are
ANDed ordinarily, you're in luck.

Btw, I presume you have set $s to be equal to a space?  Think about the
fact that it well might be a tab, especially on Received: headers, which
continue with tabs but which procmail unfolds in order to parse.  It
could contain multiple spaces or a tab.  So you probably want to try
either a space or a tab there.  In my match statement below, I've moved
the match token inside the literal bracket.  (Also, note that you don't
need to quote a literal *close*- bracket, though you do need to quote
its mate.)

If we use weighted scoring, we can descend through the headers and
pick up the bottom one, while also avoiding localhost.  This may
need some further thought with the algorithm:

 SPACE     = " "
 TAB       = "  "
 WS        = "$SPACE$TAB"
 OCTET     = ([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])
 LOCALHOST = 127.0.0.1

 :0
 * $  1^1 ^Received:.*\[\/$OCTET\.$OCTET\.$OCTET\.$OCTET][$WS]+\
                   by[$WS]+my\.host\.name
 * $ -1^1 MATCH ?? $\LOCALHOST
 { some assignment or action here }

If lower-down Received headers aren't likely to contain localhost, then
this might work fine.  If you don't want to make that assumption, then
it will need more work.

-- 
dman

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