From 65127b3349f124ec44e8f82d2222cc8a67739bcb Mon Sep 17 00:00:00 2001 From: Alex Vandiver <alexmv@bestpractical.com> Date: Wed, 27 Jun 2012 22:19:32 -0400 Subject: [PATCH] Empty emails should not match empty Correspond addresses on Queues The value stored in the database for "the default global Correspond address" is the empty string. This caused the IsRTAddress code to false-positive when passed the empty string, such as from a user with no email address set. While such addresses should indeed be removed, catching them in IsRTAddress caused unnecessary warnings in the logs. See issue #18380. --- lib/RT/EmailParser.pm | 2 ++ t/api/emailparser.t | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/RT/EmailParser.pm b/lib/RT/EmailParser.pm index 4cf4184a44..af4e396a55 100644 --- a/lib/RT/EmailParser.pm +++ b/lib/RT/EmailParser.pm @@ -330,6 +330,8 @@ sub IsRTAddress { my $self = shift; my $address = shift; + return undef unless defined($address) and $address =~ /\S/; + if ( my $address_re = RT->Config->Get('RTAddressRegexp') ) { return $address =~ /$address_re/i ? 1 : undef; } diff --git a/t/api/emailparser.t b/t/api/emailparser.t index 7903146030..a58cb3623f 100644 --- a/t/api/emailparser.t +++ b/t/api/emailparser.t @@ -2,12 +2,14 @@ use strict; use warnings; -use RT::Test nodb => 1, tests => 10; +use RT::Test tests => 11; -RT->Config->Set( RTAddressRegexp => qr/^rt\@example.com$/i ); +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" ); -ok(require RT::EmailParser); +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" ); -- GitLab