[Rt-commit] r2537 - in rt/branches/3.4-RELEASE: . etc lib/RT/Interface lib/t/regression

jesse at bestpractical.com jesse at bestpractical.com
Wed Mar 30 09:44:41 EST 2005


Author: jesse
Date: Wed Mar 30 09:44:40 2005
New Revision: 2537

Added:
   rt/branches/3.4-RELEASE/lib/t/regression/19-rtname.t
Modified:
   rt/branches/3.4-RELEASE/   (props changed)
   rt/branches/3.4-RELEASE/etc/RT_Config.pm.in
   rt/branches/3.4-RELEASE/lib/RT/Interface/Email.pm
Log:
 r10696 at hualien:  jesse | 2005-03-30 18:19:21 +0800
 RT-Ticket: 6544
 RT-Status: resolved
 RT-Update: correspond
 
 * More graceful handling for historical $rtname tags
     -- From seph
 


Modified: rt/branches/3.4-RELEASE/etc/RT_Config.pm.in
==============================================================================
--- rt/branches/3.4-RELEASE/etc/RT_Config.pm.in	(original)
+++ rt/branches/3.4-RELEASE/etc/RT_Config.pm.in	Wed Mar 30 09:44:40 2005
@@ -26,6 +26,14 @@
 
 Set($rtname , "example.com");
 
+
+# This s regexp controlls what subject tags RT recognizes as its own.
+# be VERY CAREFUL with it. Note that it overrides $rtname.
+# If you're not dealing with historical $rtname values, you'll likely
+# never have to enable this feature
+#
+# Set($EmailSubjectTagRegex, qr/$rtname/ );
+#
 # You should set this to your organization's DNS domain. For example,
 # fsck.com or asylum.arkham.ma.us. It's used by the linking interface to
 # guarantee that ticket URIs are unique and easy to construct.

Modified: rt/branches/3.4-RELEASE/lib/RT/Interface/Email.pm
==============================================================================
--- rt/branches/3.4-RELEASE/lib/RT/Interface/Email.pm	(original)
+++ rt/branches/3.4-RELEASE/lib/RT/Interface/Email.pm	Wed Mar 30 09:44:40 2005
@@ -437,10 +437,14 @@
 
 # {{{ sub ParseTicketId 
 
+
 sub ParseTicketId {
     my $Subject = shift;
+    my $id;
+
+    my $test_name = $RT::EmailSubjectTagRegex || qr/\Q$RT::rtname\E/;
 
-    if ( $Subject =~ s/\[\Q$RT::rtname\E\s+\#(\d+)\s*\]//i ) {
+    if ( $Subject =~ s/\[$test_name\s+\#(\d+)\s*\]//i ) {
         my $id = $1;
         $RT::Logger->debug("Found a ticket ID. It's $id");
         return ($id);

Added: rt/branches/3.4-RELEASE/lib/t/regression/19-rtname.t
==============================================================================
--- (empty file)
+++ rt/branches/3.4-RELEASE/lib/t/regression/19-rtname.t	Wed Mar 30 09:44:40 2005
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use lib "/opt/rt3.4/lib";
+use lib "/opt/rt3.4/local/lib";
+use Test::More qw/no_plan/;
+
+use_ok("RT");
+
+RT::LoadConfig();
+RT::Init();
+
+use RT::Interface::Email;
+
+# normal use case, regexp set to rtname
+$RT::rtname = "site";
+$RT::EmailSubjectTagRegex = qr/$RT::rtname/ ;
+$RT::rtname = undef;
+is(RT::Interface::Email::ParseTicketId("[site #123] test"), 123);
+is(RT::Interface::Email::ParseTicketId("[othersite #123] test"), undef);
+
+# oops usecase, where the regexp is scragged
+$RT::rtname = "site";
+$RT::EmailSubjectTagRegex = undef;
+is(RT::Interface::Email::ParseTicketId("[site #123] test"), 123);
+is(RT::Interface::Email::ParseTicketId("[othersite #123] test"), undef);
+
+# set to a simple regexp. NOTE: we no longer match "site"
+$RT::rtname = "site";
+$RT::EmailSubjectTagRegex = qr/newsite/;
+is(RT::Interface::Email::ParseTicketId("[site #123] test"), undef);
+is(RT::Interface::Email::ParseTicketId("[newsite #123] test"), 123);
+
+# set to a more complex regexp
+$RT::rtname = "site";
+$RT::EmailSubjectTagRegex = qr/newsite||site/;
+is(RT::Interface::Email::ParseTicketId("[site #123] test"), 123);
+is(RT::Interface::Email::ParseTicketId("[newsite #123] test"), 123);
+is(RT::Interface::Email::ParseTicketId("[othersite #123] test"), undef);
+


More information about the Rt-commit mailing list