procmail
[Top] [All Lists]

Re: an anti-spam procmail recipe

1997-08-19 18:27:27
eristic(_at_)lodz(_dot_)pdi(_dot_)net (Marek Jedlinski) writes:
<<snip the initalization section >>

# E-mails where the To: and From: headers match but it's not To: or From: me
# or somebody from my domain are probably spam.
:0
* ^To:[       ]*\/[^  ].*
{
   TO_VALUE = $MATCH

   :0
   * ^From:[         ]*\/[^  ].*
   {
       FROM_VALUE = $MATCH

       :0:
       * TO_VALUE ?? .

I thought this meant "if TO_VALUE equals any_single_character" but it wouldn't
make sense. So I am assuming it means "if TO_VALUE contains at least one
character" - is this correct?

Yes.  The "var ??" syntax tells procmail to match the rest of the
condition against the value of the variable "var".  It doesn't matter
whether the regexp matches the entire value, just that it matches.  If
you only want the condition to succeed if the regexp matches the entire
value of the variable, you'll need to use the double caret regexp
special to anchor the regexp to both the beginning and end of the value.


       * FROM_VALUE ?? .

As above, but also - why FROM_VALUE and not $FROM_VALUE? 

"FROM_VALUE" is the name of the variable, while "$FROM_VALUE", in some
contexts, interpolates the value of the variable "FROM_VALUE" into that
location.  This interpolation is also known as 'expansion'.  You don't
want procmail to interpolate the value of FROM_VALUE, you want to tell
procmail what variable to match against.  That's what the name of the
variable is for.  Procmail shares this approach with the Bourne shell
and several other scripting languages.

Note that this differs from Perl, where the $, @, and % signs aren't to
indicate interpolation, but rather to indicate the plurality and type
of the named variable.


(Or, a better question: is there a man page that explains such things?)

Well, if you study the "sh" manpage, and then the procmailrc manpage,
that should cover most of it.


       * $ ! ^TO($MY_NAMES)
       * $ ! $FROMHDR($MY_NAMES|[^(_at_)]+@$MY_DOMAINS)
       * $ FROM_VALUE ?? ^^$\TO_VALUE^^

Ok, I understand the last line means "if FROM_VAUE is identical to TO_VALUE",
but what still puzzles me is the necessity of starting the condition with `$' 
in
all the 3 lines above.

Variable expansion is not normally done in the context of conditions.
The leading '$' is what tells procmail to actually do so.  It has
nothing to do with the removal of leading whitespace from the variables.
The removal of the leading whitespace is in regards to skipping whitespace
between the '$' and the rest of the condition.


Philip Guenther

<Prev in Thread] Current Thread [Next in Thread>