Bug 5345 - address transformation to RE as a function (ENHANCEMENT)
Summary: address transformation to RE as a function (ENHANCEMENT)
Status: NEW
Alias: None
Product: Spamassassin
Classification: Unclassified
Component: Libraries (show other bugs)
Version: unspecified
Hardware: Other other
: P5 enhancement
Target Milestone: Undefined
Assignee: SpamAssassin Developer Mailing List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-21 05:33 UTC by Raul Dias
Modified: 2007-02-21 05:33 UTC (History)
0 users



Attachment Type Modified Status Actions Submitter/CLA Status

Note You need to log in before you can comment on or make changes to this bug.
Description Raul Dias 2007-02-21 05:33:24 UTC
Please note that this is not a BUG, but an ENHANCEMENT (in severity).

The right place for this is probably the dev- ml, but I am not subscribed there
anymore.

There is a code that transform an address used in [white|vlack]list_* rules that
is rewritten in 4 different places of SA:
Mail::SpamAssassin::Conf::Parser::add_to_addrlist() , 
Mail::SpamAssassin::Conf::Parser::add_to_addrlist_rcvd() ,
and twice on Mail::SpamAssassin::Plugin::WhiteListSubject

I have already used this code twice on my Plugins and probably will use more.

Transforming this into a function will prevent that any improvement to the RE is
not available to all parts that use it.

It will also facilitate plugin writters life to search/copy/paste it.  Specially
lazy ones that might start writting there on replacement code (without knowing
this even exists).

That said, here is a suggestion function for the parser:

sub address2re
{
  my ($self, $address) = @_;

  $address =~ s/[\000\\\(]/_/gs;               # paranoia
  $address =~ s/([^\*\?_a-zA-Z0-9])/\\$1/g;    # escape any possible metachars
  $address =~ tr/?/./;                         # "?" -> "."
  $address =~ s/\*+/\.\*/g;                    # "*" -> "any string"
  return "^${address}\$";
}