[Rt-commit] r18707 - in rt/3.8/trunk: . t/mail
falcone at bestpractical.com
falcone at bestpractical.com
Thu Mar 5 11:28:49 EST 2009
Author: falcone
Date: Thu Mar 5 11:28:49 2009
New Revision: 18707
Added:
rt/3.8/trunk/t/mail/extractsubjecttag.t
Modified:
rt/3.8/trunk/ (props changed)
rt/3.8/trunk/lib/RT/Action/ExtractSubjectTag.pm
Log:
r45428 at ketch: falcone | 2009-03-05 11:27:58 -0500
* make ExtractSubjectTag.pm aware of queue Subject Tags so it doesn't
assume a Queue Subject Tag is a remote RT's subject tag
Modified: rt/3.8/trunk/lib/RT/Action/ExtractSubjectTag.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/Action/ExtractSubjectTag.pm (original)
+++ rt/3.8/trunk/lib/RT/Action/ExtractSubjectTag.pm Thu Mar 5 11:28:49 2009
@@ -73,9 +73,14 @@
my $match = RT->Config->Get('ExtractSubjectTagMatch');
my $nomatch = RT->Config->Get('ExtractSubjectTagNoMatch');
- while ( $TransactionSubject =~ /($match)/g ) {
+ TAGLIST: while ( $TransactionSubject =~ /($match)/g ) {
my $tag = $1;
next if $tag =~ /$nomatch/;
+ foreach my $subject_tag ( RT->System->SubjectTag ) {
+ if ($tag =~ /\[\Q$subject_tag\E\s+\#(\d+)\s*\]/) {
+ next TAGLIST;
+ }
+ }
$TicketSubject .= " $tag" unless ( $TicketSubject =~ /\Q$tag\E/ );
}
Added: rt/3.8/trunk/t/mail/extractsubjecttag.t
==============================================================================
--- (empty file)
+++ rt/3.8/trunk/t/mail/extractsubjecttag.t Thu Mar 5 11:28:49 2009
@@ -0,0 +1,101 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use utf8;
+
+use Test::More;
+use RT::Test;
+
+plan tests => 14;
+
+my ($baseurl, $m) = RT::Test->started_ok;
+RT::Test->set_mail_catcher;
+
+my $queue = RT::Test->load_or_create_queue(
+ Name => 'Regression',
+ CorrespondAddress => 'rt-recipient at example.com',
+ CommentAddress => 'rt-recipient at example.com',
+);
+my $subject_tag = 'Windows/Servers-Desktops';
+ok $queue && $queue->id, 'loaded or created queue';
+
+diag "Set Subject Tag" if $ENV{'TEST_VERBOSE'};
+{
+ is(RT->System->SubjectTag($queue), undef, 'No Subject Tag yet');
+ my ($status, $msg) = $queue->SetSubjectTag( $subject_tag );
+ ok $status, "set subject tag for the queue" or diag "error: $msg";
+ is(RT->System->SubjectTag($queue), $subject_tag, "Set Subject Tag to $subject_tag");
+}
+
+my $original_ticket = RT::Ticket->new( $RT::SystemUser );
+diag "Create a ticket and make sure it has the subject tag" if $ENV{'TEST_VERBOSE'};
+{
+ $original_ticket->Create(
+ Queue => $queue->id,
+ Subject => 'test',
+ Requestor => 'root at localhost'
+ );
+ my @mails = RT::Test->fetch_caught_mails;
+ ok @mails, "got some outgoing emails";
+
+ my $status = 1;
+ foreach my $mail ( @mails ) {
+ my $entity = parse_mail( $mail );
+ my $subject = $entity->head->get('Subject');
+ $subject =~ /\[\Q$subject_tag\E #\d+\]/
+ or do { $status = 0; diag "wrong subject: $subject" };
+ }
+ ok $status, "Correctly added subject tag to ticket";
+}
+
+
+diag "Test that a reply with a Subject Tag doesn't change the subject" if $ENV{'TEST_VERBOSE'};
+{
+ my $ticketid = $original_ticket->Id;
+ my $text = <<EOF;
+From: root\@localhost
+To: general\@$RT::rtname
+Subject: [$subject_tag #$ticketid] test
+
+reply with subject tag
+EOF
+ diag($text);
+ my ($status, $id) = RT::Test->send_via_mailgate($text, queue => $queue->Name);
+ is ($status >> 8, 0, "The mail gateway exited normally");
+ is ($id, $ticketid, "Replied to ticket $id correctly");
+
+ my $freshticket = RT::Ticket->new( $RT::SystemUser );
+ $freshticket->LoadById($id);
+ is($original_ticket->Subject,$freshticket->Subject,'Stripped Queue Subject Tag correctly');
+
+}
+
+diag "Test that a reply with another RT's subject tag changes the subject" if $ENV{'TEST_VERBOSE'};
+{
+ my $ticketid = $original_ticket->Id;
+ my $text = <<EOF;
+From: root\@localhost
+To: general\@$RT::rtname
+Subject: [$subject_tag #$ticketid] [remote-rt-system #79] test
+
+reply with subject tag and remote rt subject tag
+EOF
+ diag($text);
+ my ($status, $id) = RT::Test->send_via_mailgate($text, queue => $queue->Name);
+ is ($status >> 8, 0, "The mail gateway exited normally");
+ is ($id, $ticketid, "Replied to ticket $id correctly");
+
+ my $freshticket = RT::Ticket->new( $RT::SystemUser );
+ $freshticket->LoadById($id);
+ like($freshticket->Subject,qr/\[remote-rt-system #79\]/,"Kept remote rt's subject tag");
+ unlike($freshticket->Subject,qr/\[\Q$subject_tag\E #$ticketid\]/,'Stripped Queue Subject Tag correctly');
+
+}
+
+sub parse_mail {
+ my $mail = shift;
+ require RT::EmailParser;
+ my $parser = new RT::EmailParser;
+ $parser->ParseMIMEEntityFromScalar( $mail );
+ return $parser->Entity;
+}
More information about the Rt-commit
mailing list