SA Bugzilla – Bug 5345
address transformation to RE as a function (ENHANCEMENT)
Last modified: 2022-03-06 16:56:41 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}\$"; }
Closing ancient stale bug.