[Rt-commit] rt branch, 4.0/emailparser-false-positives, created. rt-4.0.3-17-gab43428

Jason May jasonmay at bestpractical.com
Tue Nov 8 14:51:51 EST 2011


The branch, 4.0/emailparser-false-positives has been created
        at  ab4342873056f060f42132b95e6c0c054746d56c (commit)

- Log -----------------------------------------------------------------
commit ab4342873056f060f42132b95e6c0c054746d56c
Author: Jason May <jasonmay at bestpractical.com>
Date:   Tue Nov 8 14:47:18 2011 -0500

    Do not count an empty string as a valid RT email address
    
    Though technically it maps to a user of that value, it is technically
    not a valid email address and happens often, so it's worth making an
    special case to skip these.

diff --git a/lib/RT/EmailParser.pm b/lib/RT/EmailParser.pm
index fc25f57..9260af4 100644
--- a/lib/RT/EmailParser.pm
+++ b/lib/RT/EmailParser.pm
@@ -344,10 +344,10 @@ sub IsRTAddress {
 
     my $queue = RT::Queue->new( RT->SystemUser );
     $queue->LoadByCols( CorrespondAddress => $address );
-    return 1 if $queue->id;
+    return 1 if length($address) && $queue->id;
 
     $queue->LoadByCols( CommentAddress => $address );
-    return 1 if $queue->id;
+    return 1 if length($address) && $queue->id;
 
     return undef;
 }
diff --git a/t/api/emailparser.t b/t/api/emailparser.t
index 7903146..bc81e7c 100644
--- a/t/api/emailparser.t
+++ b/t/api/emailparser.t
@@ -2,13 +2,21 @@
 use strict;
 use warnings;
 
-use RT::Test nodb => 1, tests => 10;
-
-RT->Config->Set( RTAddressRegexp => qr/^rt\@example.com$/i );
+use RT::Test tests => 11;
 
+# create a user with a blank email address
+RT::Test->load_or_create_user(
+    Name => 'testuser',
+    EmailAddress => '',
+);
 
 ok(require RT::EmailParser);
 
+RT->Config->Set( RTAddressRegexp => undef );
+is(RT::EmailParser::IsRTAddress("",""),undef, "Empty emails don't match users without email addresses" );
+
+RT->Config->Set( RTAddressRegexp => qr/^rt\@example.com$/i );
+
 is(RT::EmailParser::IsRTAddress("","rt\@example.com"),1, "Regexp matched rt address" );
 is(RT::EmailParser::IsRTAddress("","frt\@example.com"),undef, "Regexp didn't match non-rt address" );
 

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


More information about the Rt-commit mailing list