procmail
[Top] [All Lists]

RE: block mail by compairing word in subject

2005-04-29 10:15:54
I wrote:

On Fri, Apr 29, 2005 at 02:01:03PM +0200, Ruud H.G. van Tol wrote:

If a field can be empty, you can do

    H_SUBJ  # unset
    :0
    * ^Subject:.*\/[^  ].*
    { H_SUBJ = "$MATCH" }

Ja.  You wouldn't really even need to bother initializing
the var, in that case.  An empty Subject will return empty
in the action assignment.  An email without a Subject line
will leave H_SUBJ as it was before, i.e., undefined,
which for practical purposes in procmail is as if empty.

The initialization is nonetheless a good habit, as it's
deadly if forgotten when needed.  (And if you're running
complex stuff and can't remember if you previously set
H_SUBJ to something, well, that would be another reason,
but only for emails here that have a Subject header-field
but one that is empty.

Sorry for having to double up my post, but I kind of blew it
here on the last line.  In this example, we'd only care about
a previously set H_SUBJ (that was an incorrect value) for
messages *without* any Subject-line whatsoever.  That's what
I meant to say.

I mean by that: suppose you have a hairy, long procmail setup
and early on you used some imported code that you don't know
all that well, and in it the author set "H_SUBJ = BOGUS" or
something.  Now you're down in some other INCLUDERC or SWITCHRC
file in your out-of-control procmail setup :-) -- "out of control"
because you can't remember what vars you have defined due to
bad coding practices :-) -- and you run the above recipe without
the initialization that unsets the var.  Well, except for
messages without any Subject-line at all, you're always otherwise 
going to have a positive match with the above condition;
so there would be no need to initialize unset.

If you know what's in your own rcfiles, and you know you
haven't somehow otherwise set or imported "H_SUBJ" somewhere
earlier, then you would not need to bother initializing it unset
here.

I repeat what I said earlier, though, that initializing is a
good habit.  It costs nothing, and can save your butt sometimes.
So if you're going to blindly do something, well, that's an
okay thing to have in there even when it isn't needed.  :-)

Dallman (has been bitten by uninitialized vars in the past)


____________________________________________________________
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