[Rt-commit] rt branch, 4.0-trunk, updated. rt-3.9.7-1214-g00e47c2

Alex Vandiver alexmv at bestpractical.com
Sun Jan 23 12:38:16 EST 2011


The branch, 4.0-trunk has been updated
       via  00e47c204aab9ddb91d16e04723f9e1c68614a25 (commit)
      from  f45c11c4aa056747be0d1d01fac9c8f517f5e407 (commit)

Summary of changes:
 etc/upgrade/generate-rtaddressregexp.in |   38 ++++++++++++++++++++++++------
 1 files changed, 30 insertions(+), 8 deletions(-)

- Log -----------------------------------------------------------------
commit 00e47c204aab9ddb91d16e04723f9e1c68614a25
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Sun Jan 23 12:38:11 2011 -0500

    Optimize the generated regular expression slightly, and allow more than 100 queues

diff --git a/etc/upgrade/generate-rtaddressregexp.in b/etc/upgrade/generate-rtaddressregexp.in
index 2e81fb0..ac246b8 100644
--- a/etc/upgrade/generate-rtaddressregexp.in
+++ b/etc/upgrade/generate-rtaddressregexp.in
@@ -67,21 +67,43 @@ if (my $re = RT->Config->Get('RTAddressRegexp')) {
 use RT::Queues;
 my $queues = RT::Queues->new( RT->SystemUser );
 $queues->UnLimit;
-$queues->RowsPerPage(100);
 
-my @addresses = (RT->Config->Get('CorrespondAddress'), RT->Config->Get('CommentAddress'));
+my %merged;
+merge(\%merged, RT->Config->Get('CorrespondAddress'), RT->Config->Get('CommentAddress'));
 while ( my $queue = $queues->Next ) {
-    push @addresses, $queue->CorrespondAddress, $queue->CommentAddress;
+    merge(\%merged, $queue->CorrespondAddress, $queue->CommentAddress);
 }
 
-my %seen;
-my $re = join '|', map "\Q$_\E",
-    grep defined && length && !$seen{ lc $_ }++,
-    @addresses;
+my @domains;
+for my $domain (sort keys %merged) {
+    my @addresses;
+    for my $base (sort keys %{$merged{$domain}}) {
+        my @subbits = keys(%{$merged{$domain}{$base}});
+        if (@subbits > 1) {
+            push @addresses, "\Q$base\E(?:".join("|", at subbits).")";
+        } else {
+            push @addresses, "\Q$base\E$subbits[0]";
+        }
+    }
+    if (@addresses > 1) {
+        push @domains, "(?:".join("|", @addresses).")\Q\@".$domain."\E";
+    } else {
+        push @domains, "$addresses[0]\Q\@$domain\E";
+    }
+}
+my $re = join "|", @domains;
 
 print <<ENDDESCRIPTION;
 You can add the following to RT_SiteConfig.pm, but may want to collapse it into a more efficient regexp.
 Keep in mind that this only contains the email addresses that RT knows about, you should also examine
 your mail system for aliases that reach RT but which RT doesn't know about.
 ENDDESCRIPTION
-print "Set(\$RTAddressRegexp,'^(?:${re})\$');\n";
+print "Set(\$RTAddressRegexp,qr{^(?:${re})\$});\n";
+
+sub merge {
+    my $merged = shift;
+    for my $address (grep {defined and length} @_) {
+        $address =~ /^\s*(.*?)(-comments?)?\@(.*?)\s*$/;
+        $merged->{lc $3}{$1}{$2||''}++;
+    }
+}

-----------------------------------------------------------------------


More information about the Rt-commit mailing list