[Rt-commit] rt branch, 4.0/emailparser-false-positives, created. rt-4.0.3-19-g6370440
Jason May
jasonmay at bestpractical.com
Mon Dec 5 16:52:45 EST 2011
The branch, 4.0/emailparser-false-positives has been created
at 6370440a1b21f8dfd286789be055f864f0bbc6c0 (commit)
- Log -----------------------------------------------------------------
commit e50515e9291ebc57524bac135fbe0f4291248774
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..d2c84de 100644
--- a/lib/RT/EmailParser.pm
+++ b/lib/RT/EmailParser.pm
@@ -342,6 +342,8 @@ sub IsRTAddress {
return 1 if lc $comment_address eq lc $address;
}
+ return undef unless length($address);
+
my $queue = RT::Queue->new( RT->SystemUser );
$queue->LoadByCols( CorrespondAddress => $address );
return 1 if $queue->id;
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" );
commit f721f586d0c51150ba9615233833797f48ddfe82
Author: Jason May <jasonmay at bestpractical.com>
Date: Mon Dec 5 15:40:19 2011 -0500
Improve the test description for blank emails with EmailParser
User email addresses are not checked in the function; a user's email
address is passed in. Therefore there is no need to make a test user.
The "" email value is checked against email addresses assigned by
queues, and General has a blank email address by default.
diff --git a/t/api/emailparser.t b/t/api/emailparser.t
index bc81e7c..a58cb36 100644
--- a/t/api/emailparser.t
+++ b/t/api/emailparser.t
@@ -4,16 +4,10 @@ use warnings;
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" );
+is(RT::EmailParser::IsRTAddress("",""),undef, "Empty emails from users don't match queues without email addresses" );
RT->Config->Set( RTAddressRegexp => qr/^rt\@example.com$/i );
commit 6370440a1b21f8dfd286789be055f864f0bbc6c0
Author: Jason May <jasonmay at bestpractical.com>
Date: Mon Dec 5 15:44:44 2011 -0500
Ensure that eamils with just whitespace is cuaght by IsRTAddress
diff --git a/lib/RT/EmailParser.pm b/lib/RT/EmailParser.pm
index d2c84de..826989f 100644
--- a/lib/RT/EmailParser.pm
+++ b/lib/RT/EmailParser.pm
@@ -342,7 +342,7 @@ sub IsRTAddress {
return 1 if lc $comment_address eq lc $address;
}
- return undef unless length($address);
+ return undef unless length($address) and $address =~ /\S/;
my $queue = RT::Queue->new( RT->SystemUser );
$queue->LoadByCols( CorrespondAddress => $address );
diff --git a/t/api/emailparser.t b/t/api/emailparser.t
index a58cb36..0a35f52 100644
--- a/t/api/emailparser.t
+++ b/t/api/emailparser.t
@@ -2,13 +2,19 @@
use strict;
use warnings;
-use RT::Test tests => 11;
+use RT::Test tests => 12;
ok(require RT::EmailParser);
RT->Config->Set( RTAddressRegexp => undef );
is(RT::EmailParser::IsRTAddress("",""),undef, "Empty emails from users don't match queues without email addresses" );
+my $queue = RT::Queue->new($RT::SystemUser);
+$queue->Load('General');
+$queue->SetCorrespondAddress(" ");
+is(RT::EmailParser::IsRTAddress(""," "),undef, 'Catch emails with only whitespace' );
+$queue->SetCorrespondAddress("");
+
RT->Config->Set( RTAddressRegexp => qr/^rt\@example.com$/i );
is(RT::EmailParser::IsRTAddress("","rt\@example.com"),1, "Regexp matched rt address" );
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list