You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by Justin Mason <jm...@jmason.org> on 2007/02/14 11:39:32 UTC

Re: Remember Me? -> RememberMe.pm plugin

hi Raul --

I think you are on the right track with this approach. Note also that you
can give it a better syntax, looking more like a new rule type -- see the
MIMEHeader plugin for an example.  So for instance instead of

   #get the rdns
   header _RM_RELAY_RDNS eval:remember_me_header('rdns', \
  	'X-Spam-Relays-External', '/rdns=(.*?)\s/')
   score  _RM_RELAY_RDNS 0.01
  
   #the checking
   header   RM_RELAY_HELO_MATCHES_RNDS eval:check_remember_me_header \ 
  	('X-Spam-Relays-External', '/helo=%{rdns}\s/')
   describe RM_RELAY_HELO_MATCHES_RNDS Reverse DNS and HELO are the same.
   score -0.1

it could look like:

   #get the rdns
   remember_me   rdns    X-Spam-Relays-External =~ /rdns=(.*?)\s/
  
   #the checking
   remember_me_header   RM_RELAY_HELO_MATCHES_RNDS    X-Spam-Relays-External =~ /helo=%{rdns}\s/
   describe RM_RELAY_HELO_MATCHES_RNDS Reverse DNS and HELO are the same.
   score -0.1


(behind the scenes, those "new rule types" would be implemented as
header evals, similar to how it's done in MIMEHeader.pm -- but it's
a friendlier, more readable format.)

--j.

Raul Dias writes:
> Hi,
> 
> I have been looking (as I described earlier) for a way to use variables
> in the rules for a few days without lucky.
> 
> I tried to hack SA, mix with plugins and got to the conclusion that the
> only way to do this was to reevaluates the rules (REs) on every new
> message, which is a huge draw back.
> 
> So, I took a different approach.  I kept it all on a plugin using 2 eval
> options.
> 
> First is remember_me_header() which takes:
>  - a user defined variable name
>  - a header name (or pseudo header)
>  - a Regular Expression with matching parentheses.
> 
> The header name and the RE will work as header rule:
> 
>    header FOO header_name =~ RE
> 
> The difference is that the parentheses in the RE, if matched, will be
> stored in the user defined variable name.
> 
> E.G.
> 
> header RDNS eval:remember_me_header('rdns', 'X-Spam-Relays-External',
> '/rdns=(.*)\s/')
> 
> will save the rdns value from the last (external) relay into a variable
> named rdns.  This gives the opportunity to reuse this value in a later
> rule.
> 
> Multiples parentheses are supported and the /g modifier will iterate the
> RE until it stops matching.  
> 
> Multiple matchs are stores with a suffix _<match -1>.  So if the example
> above had a /g, the rdns from the second relay (if existed) would be
> rdns_1 .
> 
> In order to use this variables a second eval function is needed.  in
> this case it is check_remember_me_header(), which takes:
>   - a header name
>   - a RE using one or more matched variables
>   - an optional prefix character.
> 
> As before it works in the same way as:
> 
>   header FOO header_name =~ RE
> 
> to especify one or more variables in the RE, use: %{variable_name} .
> the % can be changed to another character optionally.
> 
> So, to match if the helo is the same as the rdns (my client break the
> lines):
> 
>  #get the rdns
>  header _RM_RELAY_RDNS eval:remember_me_header('rdns', \
> 	'X-Spam-Relays-External', '/rdns=(.*?)\s/')
>  score  _RM_RELAY_RDNS 0.01
> 
>  #the checking
>  header   RM_RELAY_HELO_MATCHES_RNDS eval:check_remember_me_header \ 
> 	('X-Spam-Relays-External', '/helo=%{rdns}\s/')
>  describe RM_RELAY_HELO_MATCHES_RNDS Reverse DNS and HELO are the same.
>  score -0.1
> 
> 
> The idea is that this will help some people to write (and share :) rules
> with the need to write plugins (and learn to write or even perl).
> 
> This code is beta and only work on headers right now (if anyone would
> like this on body, let me know).
> 
> I would like to see what do you guys think about the idea, problems,
> enhancements.
> 
> -Raul Dias