On Sat, Jul 30, 2005 at 01:31:50PM +0000, Matthias Haeker wrote:
Ruud [wrote:]
Can you say in words what this should do? I would move the ! to
the start if you meant it to mean 'NOT':
i want to know if X_SENDER_IP not matched because there is no
ip in X_RECEIVED if the first Received: is like Received: (from
filter(_at_)localhost)
[Tip to Matthias: check out "par" for on-the-fly line reformatting
that works like a dream. The unformatted quoted lines in your posts
look pretty awful as-is.]
The canonical way to check for a failed condition is simply
to infer it from a failed descent into the action line, which
diagnosis can be helped along with an "else" recipe below if
desired. Your use of a check for whitespace to tell is perhaps
inventive, but not very intuitive for anybody looking at your code,
and I'm not sure you're accomplishing what you want, anyway, with
it. So, let's look at the general case:
:0
* condition
{ VAR = foo }
If we want to know if the recipe worked, we can test for VAR
(assuming we are sure about what it was *before* the knew recipe,
i.e, we want to have initialized as necessary or, in any case,
to have kept track heuristically of the value of VAR beforehand).
So if this is the first time we've used VAR in this rcfile set,
later we could do this:
* VAR ?? .
or this:
* VAR ?? ^^foo^^
or some other similar things to see.
If our test follows the prior recipe directly, we can just put stuff in
nested braces. We'd have been booted out of the nested braces if there
had not been a match on the original condition.
:0
* condition
{
VAR = foo
[other recipe depending on VAR's having been set]
}
:0 E #lse
[do something with the knowledge that VAR was not set]
Suggest a read through "man procmailex" for starters.
* $ X_RECEIVED ?? [\(]from[$WS]*[^$WS]*[(_at_)]\/localhost
will do the same more simple
You want the regex metachar after the [^$WS] to be a
plus sign, not an asterisk. An asterisk says "zero-or-
more of the previous chars." You want "one-or-more."
Ditto for the "not" cawse that follows.
Also, you don't need both brackets and a quote for the open-paren.
One or the other -- they are alternative ways to get the char
quoted in this case. You are actually saying "a backslash or an
open-paren before 'from'"; not what you intended." Moreover,
you don't need to quote (via the use of a lone char-class)
the asterisk. Very few chars need quoting in procmail.
Good to learn what they are once and be done with it.
* $ X_RECEIVED ?? ()\(from[$WS]+[^$WS]+(_at_)\/localhost
(You might as well also check for 127.0.0.1 where "localhost" is,
too.)
* $ MATCH ?? localhost
Again the reparse-$ at the start is not needed.
there i miss again some basic knowledge i guess
Well, this is just general programming logic, more than it
is procmail in particular. You just matched on localhost.
So it's there, for sure, and we don't need to test again
to see if it's *really* there. If it weren't there, we'd
have left the recipe already, as the first condition would
have declined to match.
[from verbose logs]
procmail: No match on ! "213.244.186.210"
where the last line is the same if i use
* $ X_SENDER_IP ?? !$X_LOCAL_IP
or
* $ ! X_SENDER_IP ?? $X_LOCAL_IP
The alternate syntax you use works, yes. It's not
generally preferred by experienced coders, who typically
want to know about any "not" in a statement early so they
can gear-up their brains for analyzing what they're reading
in the manner that most humans do. ;-)
Dallman
____________________________________________________________
procmail mailing list Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail