Patch for CanonicalizeEmailAddress

Hi,

As of 3.4.2, canonicalizing fails when the Replace string uses backrefs:

RT_SiteConfig.pm snippet

our users like to just CC usernames instead of

typing out the whole username@mycompany.com

e.g. ‘username’ → ‘username@mycompany.com’

Set($CanonicalizeEmailAddressMatch , ‘^([\w-+]+)$’);
Set($CanonicalizeEmailAddressReplace , ‘\1@mycompany.com’);

But this change to User_Overlay.pm will let it work:

682c682,689
< $email =~
s/$RT::CanonicalizeEmailAddressMatch/$RT::CanonicalizeEmailAddressReplace/gi;

    if ($email =~ /$RT::CanonicalizeEmailAddressMatch/) {
        $_ = $email;
        eval {
            eval 

“s/$RT::CanonicalizeEmailAddressMatch/$RT::CanonicalizeEmailAddressReplace/gi”;

        };
        $RT::Logger->crit("Failure in CanonicalizeEmailAddress") 

if $@;

        $email = $_;
    }

Regards,
Phil Lawrence

Hi,

As of 3.4.2, canonicalizing fails when the Replace string uses backrefs:

RT_SiteConfig.pm snippet

our users like to just CC usernames instead of

typing out the whole username@mycompany.com

e.g. ‘username’ → ‘username@mycompany.com’

Set($CanonicalizeEmailAddressMatch , ‘^([\w-+]+)$’);
Set($CanonicalizeEmailAddressReplace , ‘\1@mycompany.com’);

Back references are used in the “match” side of a s/// regexp not the
“replace” side, in that case you should use $1, $2, etc…

If I run a script such as:

#!/usr/bin/perl
use strict;
use warnings;

my $foo = “username”;
$foo =~ s/^([\w-+]+)$/\1@mycompany.com/;
print $foo . “\n”’

I get the output:

username@mycompany.com

but I also get a warning:

\1 better written as $1 at -e line 1.

I hope that helps,

Stephen