[Bps-public-commit] r20142 - RT-BugTracker/lib/RT

ruz at bestpractical.com ruz at bestpractical.com
Tue Nov 24 12:58:39 EST 2009


Author: ruz
Date: Tue Nov 24 12:58:39 2009
New Revision: 20142

Modified:
   RT-BugTracker/lib/RT/BugTracker.pm

Log:
* wrap a few functions to implement subject tags

Modified: RT-BugTracker/lib/RT/BugTracker.pm
==============================================================================
--- RT-BugTracker/lib/RT/BugTracker.pm	(original)
+++ RT-BugTracker/lib/RT/BugTracker.pm	Tue Nov 24 12:58:39 2009
@@ -109,6 +109,27 @@
     );
 }
 
+# XXX: should go with 3.8 port
+sub SubjectTagRE {
+    return qr/[a-z0-9 ._-]/i;
+}
+sub SubjectTag {
+    return (shift)->_AttributeBasedField(
+        SubjectTag => @_
+    ) || '';
+}
+sub SetSubjectTag {
+    my ($self, $value) = (shift, shift);
+    if ( defined $value ) {
+        my $re = $self->SubjectTagRE;
+        return (0, $self->loc("Invalid characters in SubjectTag"))
+            unless $value =~ /^$re*$/;
+    }
+    return $self->_SetAttributeBasedField(
+        SubjectTag => $value, @_
+    );
+}
+
 sub _AttributeBasedField {
     my $self = shift;
     my $name = shift;
@@ -146,6 +167,30 @@
     return ( 1, $self->loc("[_1] changed", $self->loc($name)) );
 }
 
+require RT::Action::SendEmail;
+package RT::Action::SendEmail;
+
+my $tag_re = RT::Queue->SubjectTagRE;
+$RT::EmailSubjectTagRegex = qr/\Q$RT::rtname\E(?:\s+$tag_re+)?/;
+
+my $old = \&SetSubjectToken;
+*RT::Action::SendEmail::SetSubjectToken = sub {
+    my $self = shift;
+    $old->($self, @_);
+
+    my $tag = $self->TicketObj->QueueObj->SubjectTag;
+    return unless defined $tag && length $tag;
+
+    my $id = $self->TicketObj->id;
+    my $head = $self->TemplateObj->MIMEObj->head;
+    my $subject = $head->get('Subject');
+    my $tmp = $subject;
+    $tmp =~ s{\[\Q$RT::rtname\E\s+#$id\]}{[$RT::rtname $tag #$id]}i;
+    return if $tmp eq $subject;
+
+    $head->replace( Subject => $tmp );
+};
+
 =head1 SEE ALSO
 
 L<RT::BugTracker::Public>, L<RT::Extension::rt_cpan_org>



More information about the Bps-public-commit mailing list