[Rt-commit] rt branch, 4.2/forward-with-message, created. rt-4.1.19-38-gec4317f
? sunnavy
sunnavy at bestpractical.com
Sat Aug 24 02:08:05 EDT 2013
The branch, 4.2/forward-with-message has been created
at ec4317f238cff012700b9e31eff170210575a30f (commit)
- Log -----------------------------------------------------------------
commit ff036e81e4d23eef54339c336aa52ab74c7f1851
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Jul 26 01:34:45 2012 +0800
definition of $result is too far away, 1 is more clear
diff --git a/lib/RT/Action/SendEmail.pm b/lib/RT/Action/SendEmail.pm
index 53f5c7f..e56e0a7 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -221,7 +221,7 @@ sub Prepare {
'Success';
}
- return $result;
+ return 1;
}
=head2 To
commit a1a4f73efd62693201ea8220ae4218348a9e8571
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Jul 19 02:52:57 2012 +0800
support customized forward message and use scrip to send forwarded message
now we record the forward transaction with customized message and use a scrip
bound to it to actually send the message.
(SendForward action is newly added for it)
diff --git a/etc/initialdata b/etc/initialdata
index 259b8ba..533ce67 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -104,6 +104,9 @@
{ Name => 'Extract Subject Tag', # loc
Description => 'Extract tags from a Transaction\'s subject and add them to the Ticket\'s subject.', # loc
ExecModule => 'ExtractSubjectTag' },
+ { Name => 'Send Forward', # loc
+ Description => 'Send forwarded message', # loc
+ ExecModule => 'SendForward', },
);
@ScripConditions = (
@@ -604,17 +607,21 @@ Content-Type: text/html
},
{ Queue => 0,
Name => "Forward", # loc
- Description => "Heading of a forwarded message", # loc
+ Description => "Forwarded message", # loc
Content => q{
This is a forward of transaction #{$Transaction->id} of ticket #{ $Ticket->id }
+
+{ $ForwardTransaction->Content }
}
},
{ Queue => 0,
Name => "Forward Ticket", # loc
- Description => "Heading of a forwarded Ticket", # loc
+ Description => "Forwarded ticket message", # loc
Content => q{
This is a forward of ticket #{ $Ticket->id }
+
+{ $ForwardTransaction->Content }
}
},
{ Queue => 0,
@@ -767,6 +774,14 @@ Hour: { $SubscriptionObj->SubValue('Hour') }
ScripCondition => 'On Transaction',
ScripAction => 'Extract Subject Tag',
Template => 'Blank' },
+ { Description => 'On Forward Transaction Send forwarded message',
+ ScripCondition => 'On Forward Transaction',
+ ScripAction => 'Send Forward',
+ Template => 'Forward' },
+ { Description => 'On Forward Ticket Send forwarded message',
+ ScripCondition => 'On Forward Ticket',
+ ScripAction => 'Send Forward',
+ Template => 'Forward Ticket' },
);
@ACL = (
diff --git a/lib/RT/Action/SendEmail.pm b/lib/RT/Action/SendEmail.pm
index e56e0a7..8d56827 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -135,13 +135,15 @@ Builds an outgoing email we're going to send using scrip's template.
sub Prepare {
my $self = shift;
- my ( $result, $message ) = $self->TemplateObj->Parse(
- Argument => $self->Argument,
- TicketObj => $self->TicketObj,
- TransactionObj => $self->TransactionObj
- );
- if ( !$result ) {
- return (undef);
+ unless ( $self->TemplateObj->MIMEObj ) {
+ my ( $result, $message ) = $self->TemplateObj->Parse(
+ Argument => $self->Argument,
+ TicketObj => $self->TicketObj,
+ TransactionObj => $self->TransactionObj
+ );
+ if ( !$result ) {
+ return (undef);
+ }
}
my $MIMEObj = $self->TemplateObj->MIMEObj;
diff --git a/lib/RT/Action/SendForward.pm b/lib/RT/Action/SendForward.pm
new file mode 100644
index 0000000..f524095
--- /dev/null
+++ b/lib/RT/Action/SendForward.pm
@@ -0,0 +1,148 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
+# <sales at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+
+#
+package RT::Action::SendForward;
+
+use strict;
+use warnings;
+
+use base qw(RT::Action::SendEmail);
+
+use Email::Address;
+
+=head2 Prepare
+
+=cut
+
+sub Prepare {
+ my $self = shift;
+
+ my $txn = $self->TransactionObj;
+
+ if ( $txn->Type eq 'Forward Transaction' ) {
+ my $forwarded_txn = RT::Transaction->new( $self->CurrentUser );
+ $forwarded_txn->Load( $txn->Field );
+ $self->{ForwardedTransactionObj} = $forwarded_txn;
+ }
+
+ my ( $result, $message ) = $self->TemplateObj->Parse(
+ Argument => $self->Argument,
+ Ticket => $self->TicketObj,
+ Transaction => $self->ForwardedTransactionObj,
+ ForwardTransaction => $self->TransactionObj,
+ );
+
+ if ( !$result ) {
+ return (undef);
+ }
+
+ my $mime = $self->TemplateObj->MIMEObj;
+ $mime->make_multipart unless $mime->is_multipart;
+
+ my $entity;
+ if ( $txn->Type eq 'Forward Transaction' ) {
+ $entity = $self->ForwardedTransactionObj->ContentAsMIME;
+ }
+ else {
+ my $txns = $self->TicketObj->Transactions;
+ $txns->Limit(
+ FIELD => 'Type',
+ VALUE => $_,
+ ) for qw(Create Correspond);
+
+ $entity = MIME::Entity->build(
+ Type => 'multipart/mixed',
+ Description => 'forwarded ticket',
+ );
+ $entity->add_part($_) foreach
+ map $_->ContentAsMIME,
+ @{ $txns->ItemsArrayRef };
+ }
+
+ $mime->add_part($entity);
+
+ unless ( $mime->head->get('Subject') ) {
+ my $subject = '';
+ $subject = $self->ForwardedTransactionObj->Subject
+ if $self->ForwardedTransactionObj;
+ $subject ||= $self->TicketObj->Subject;
+ unless ( RT->Config->Get('ForwardFromUser') ) {
+ $subject =
+ RT::Interface::Email::AddSubjectTag( $subject, $self->TicketObj );
+ }
+ $mime->head->set( Subject => $self->MIMEEncodeString("Fwd: $subject") );
+ }
+
+ my $txn_attachment = $self->TransactionObj->Attachments->First;
+ for my $header (qw/From To Cc Bcc/) {
+ if ( $txn_attachment->GetHeader( $header ) ) {
+ $mime->head->set( $header => $txn_attachment->GetHeader($header) );
+ }
+ }
+
+ if ( RT->Config->Get('ForwardFromUser') ) {
+ $mime->head->set( 'X-RT-Sign' => 0 );
+ }
+
+ $self->SUPER::Prepare();
+}
+
+sub SetSubjectToken {
+
+ # we already take care of this in Prepare.
+}
+
+sub ForwardedTransactionObj {
+ my $self = shift;
+ return $self->{'ForwardedTransactionObj'};
+}
+
+RT::Base->_ImportOverlays();
+
+1;
diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index 34b12d0..b262dd8 100644
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -587,196 +587,56 @@ sub SendEmailUsingTemplate {
return SendEmail( Entity => $mail );
}
-=head2 ForwardTransaction TRANSACTION, To => '', Cc => '', Bcc => ''
-
-Forwards transaction with all attachments as 'message/rfc822'.
-
-=cut
-
-sub ForwardTransaction {
- my $txn = shift;
- my %args = ( To => '', Cc => '', Bcc => '', @_ );
-
- $args{$_} = join ", ", map { $_->format } RT::EmailParser->ParseEmailAddress($args{$_} || '')
- for qw(To Cc Bcc);
-
- my $entity = $txn->ContentAsMIME;
-
- my ( $ret, $msg ) = SendForward( %args, Entity => $entity, Transaction => $txn );
- if ($ret) {
- my $ticket = $txn->TicketObj;
- my ( $ret, $msg ) = $ticket->_NewTransaction(
- Type => 'Forward Transaction',
- Field => $txn->id,
- Data => join ', ', grep { length } $args{To}, $args{Cc}, $args{Bcc},
- );
- unless ($ret) {
- $RT::Logger->error("Failed to create transaction: $msg");
- }
- }
- return ( $ret, $msg );
-}
-
-=head2 ForwardTicket TICKET, To => '', Cc => '', Bcc => ''
-
-Forwards a ticket's Create and Correspond Transactions and their Attachments as 'message/rfc822'.
-
-=cut
-
-sub ForwardTicket {
- my $ticket = shift;
- my %args = ( To => '', Cc => '', Bcc => '', @_ );
-
- $args{$_} = join ", ", map { $_->format } RT::EmailParser->ParseEmailAddress($args{$_} || '')
- for qw(To Cc Bcc);
-
- my $txns = $ticket->Transactions;
- $txns->Limit(
- FIELD => 'Type',
- VALUE => $_,
- ) for qw(Create Correspond);
-
- my $entity = MIME::Entity->build(
- Type => 'multipart/mixed',
- Description => 'forwarded ticket',
- );
- $entity->add_part( $_ ) foreach
- map $_->ContentAsMIME,
- @{ $txns->ItemsArrayRef };
-
- my ( $ret, $msg ) = SendForward(
- %args,
- Entity => $entity,
- Ticket => $ticket,
- Template => 'Forward Ticket',
- );
-
- if ($ret) {
- my ( $ret, $msg ) = $ticket->_NewTransaction(
- Type => 'Forward Ticket',
- Field => $ticket->id,
- Data => join ', ', grep { length } $args{To}, $args{Cc}, $args{Bcc},
- );
- unless ($ret) {
- $RT::Logger->error("Failed to create transaction: $msg");
- }
- }
-
- return ( $ret, $msg );
-
-}
-
-=head2 SendForward Entity => undef, Ticket => undef, Transaction => undef, Template => undef, To => '', Cc => '', Bcc => ''
+=head2 GetForwardFrom Ticket => undef, Transaction => undef
-Forwards an Entity representing Ticket or Transaction as 'message/rfc822'. Entity is wrapped into Template.
+Resolve the From field to use in forward mail
=cut
-sub SendForward {
- my (%args) = (
- Entity => undef,
- Ticket => undef,
- Transaction => undef,
- Template => 'Forward',
- To => '', Cc => '', Bcc => '',
- @_
- );
-
- my $txn = $args{'Transaction'};
- my $ticket = $args{'Ticket'};
- $ticket ||= $txn->Object if $txn;
-
- my $entity = $args{'Entity'};
- unless ( $entity ) {
- require Carp;
- $RT::Logger->error(Carp::longmess("No entity provided"));
- return (0, $ticket->loc("Couldn't send email"));
- }
-
- my ($template, $msg) = PrepareEmailUsingTemplate(
- Template => $args{'Template'},
- Arguments => {
- Ticket => $ticket,
- Transaction => $txn,
- },
- );
-
- my $mail;
- if ( $template ) {
- $mail = $template->MIMEObj;
- } else {
- $RT::Logger->warning($msg);
- }
- unless ( $mail ) {
- $RT::Logger->warning("Couldn't generate email using template '$args{Template}'");
+sub GetForwardFrom {
+ my %args = ( Ticket => undef, Transaction => undef, @_ );
+ my $txn = $args{Transaction};
+ my $ticket = $args{Ticket} || $txn->Object;
- my $description;
- unless ( $args{'Transaction'} ) {
- $description = 'This is forward of ticket #'. $ticket->id;
- } else {
- $description = 'This is forward of transaction #'
- . $txn->id ." of a ticket #". $txn->ObjectId;
- }
- $mail = MIME::Entity->build(
- Type => 'text/plain',
- Data => $description,
- );
+ if ( RT->Config->Get('ForwardFromUser') ) {
+ return ( $txn || $ticket )->CurrentUser->EmailAddress;
}
-
- $mail->head->set( $_ => EncodeToMIME( String => $args{$_} ) )
- foreach grep defined $args{$_}, qw(To Cc Bcc);
-
- $mail->make_multipart unless $mail->is_multipart;
- $mail->add_part( $entity );
-
- my $from;
- unless (defined $mail->head->get('Subject')) {
- my $subject = '';
- $subject = $txn->Subject if $txn;
- $subject ||= $ticket->Subject if $ticket;
-
- unless ( RT->Config->Get('ForwardFromUser') ) {
- # XXX: what if want to forward txn of other object than ticket?
- $subject = AddSubjectTag( $subject, $ticket );
- }
-
- $mail->head->set( Subject => EncodeToMIME( String => "Fwd: $subject" ) );
+ else {
+ return $ticket->QueueObj->CorrespondAddress
+ || RT->Config->Get('CorrespondAddress');
}
-
- $mail->head->set(
- From => EncodeToMIME(
- String => GetForwardFrom( Transaction => $txn, Ticket => $ticket )
- )
- );
-
- my $status = RT->Config->Get('ForwardFromUser')
- # never sign if we forward from User
- ? SendEmail( %args, Entity => $mail, Sign => 0 )
- : SendEmail( %args, Entity => $mail );
- return (0, $ticket->loc("Couldn't send email")) unless $status;
- return (1, $ticket->loc("Sent email successfully"));
}
-=head2 GetForwardFrom Ticket => undef, Transaction => undef
+=head2 GetForwardAttachments Ticket => undef, Transaction => undef
-Resolve the From field to use in forward mail
+Resolve the Attachments to forward
=cut
-sub GetForwardFrom {
+sub GetForwardAttachments {
my %args = ( Ticket => undef, Transaction => undef, @_ );
my $txn = $args{Transaction};
my $ticket = $args{Ticket} || $txn->Object;
- if ( RT->Config->Get('ForwardFromUser') ) {
- return ( $txn || $ticket )->CurrentUser->EmailAddress;
+ my $attachments = RT::Attachments->new( $ticket->CurrentUser );
+ if ($txn) {
+ $attachments->Limit( FIELD => 'TransactionId', VALUE => $txn->id );
}
else {
- return $ticket->QueueObj->CorrespondAddress
- || RT->Config->Get('CorrespondAddress');
+ my $txns = $ticket->Transactions;
+ $txns->Limit(
+ FIELD => 'Type',
+ VALUE => $_,
+ ) for qw(Create Correspond);
+
+ while ( my $txn = $txns->Next ) {
+ $attachments->Limit( FIELD => 'TransactionId', VALUE => $txn->id );
+ }
}
+ return $attachments;
}
+
=head2 SignEncrypt Entity => undef, Sign => 0, Encrypt => 0
Signs and encrypts message using L<RT::Crypt::GnuPG>, but as well
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 1433900..fc3ef57 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -2980,6 +2980,79 @@ sub ACLEquivalenceObjects {
sub ModifyLinkRight { "ModifyTicket" }
+=head2 Forward Transaction => undef, To => '', Cc => '', Bcc => ''
+
+Forwards transaction with all attachments as 'message/rfc822'.
+
+=cut
+
+sub Forward {
+ my $self = shift;
+ my %args = (
+ Transaction => undef,
+ To => '',
+ Cc => '',
+ Bcc => '',
+ Content => '',
+ ContentType => 'text/plain',
+ DryRun => 0,
+ CommitScrips => 1,
+ @_
+ );
+
+ unless ( $self->CurrentUserHasRight('ForwardMessage') ) {
+ return ( 0, $self->loc("Permission Denied") );
+ }
+
+ $args{$_} = join ", ", map { $_->format } RT::EmailParser->ParseEmailAddress( $args{$_} || '' ) for qw(To Cc Bcc);
+
+ my $mime = MIME::Entity->build(
+ Type => $args{'ContentType'},
+ Data => $args{Content},
+ );
+
+ $mime->head->set(
+ $_ => RT::Interface::Email::EncodeToMIME( String => $args{$_} ) )
+ for grep defined $args{$_}, qw(To Cc Bcc);
+ $mime->head->set(
+ From => RT::Interface::Email::EncodeToMIME(
+ String => RT::Interface::Email::GetForwardFrom(
+ Transaction => $args{Transaction},
+ Ticket => $self,
+ )
+ )
+ );
+
+ if ($args{'DryRun'}) {
+ $RT::Handle->BeginTransaction();
+ $args{'CommitScrips'} = 0;
+ }
+
+ my ( $ret, $msg ) = $self->_NewTransaction(
+ $args{Transaction}
+ ? (
+ Type => 'Forward Transaction',
+ Field => $args{Transaction}->id,
+ )
+ : (
+ Type => 'Forward Ticket',
+ Field => $self->id,
+ ),
+ Data => join( ', ', grep { length } $args{To}, $args{Cc}, $args{Bcc} ),
+ MIMEObj => $mime,
+ CommitScrips => $args{'CommitScrips'},
+ );
+
+ unless ($ret) {
+ $RT::Logger->error("Failed to create transaction: $msg");
+ }
+
+ if ($args{'DryRun'}) {
+ $RT::Handle->Rollback();
+ }
+ return ( $ret, $self->loc('Message recorded') );
+}
+
1;
=head1 AUTHOR
diff --git a/share/html/Ticket/Forward.html b/share/html/Ticket/Forward.html
index 2c20daf..15de800 100644
--- a/share/html/Ticket/Forward.html
+++ b/share/html/Ticket/Forward.html
@@ -72,8 +72,21 @@
<tr><td align="right"><&|/l&>Bcc</&>:</td>
<td><input name="Bcc" size="60" value="<% $ARGS{'Bcc'} || '' %>" /></td></tr>
+<tr>
+<td><&|/l&>Content</&>:</td>
+<td>
+% if (exists $ARGS{Content}) {
+<& /Elements/MessageBox, Default => $ARGS{Content}, IncludeSignature => 0 &>
+% } else {
+<& /Elements/MessageBox &>
+%}
+</td>
+</tr>
+
</table>
+<& /Ticket/Elements/ShowAttachments, Attachments => $attachments &>
+
<& /Elements/Submit, Label => loc('Forward Message and Return'), Name => 'ForwardAndReturn' &>
<& /Elements/Submit, Label => loc('Forward Message'), Name => 'Forward' &>
</form>
@@ -94,10 +107,7 @@ if ( $QuoteTransaction ) {
my @results;
if ( $Forward || $ForwardAndReturn ) {
- require RT::Interface::Email;
- my ($status, $msg) = $txn
- ? RT::Interface::Email::ForwardTransaction( $txn, %ARGS )
- : RT::Interface::Email::ForwardTicket( $TicketObj, %ARGS );
+ my ( $status, $msg ) = $TicketObj->Forward( Transaction => $txn, %ARGS );
push @results, $msg;
if ( $ForwardAndReturn ) {
@@ -119,6 +129,11 @@ my $subject = $TicketObj->Subject;
$subject = RT::Interface::Email::AddSubjectTag( $subject, $TicketObj )
unless RT->Config->Get('ForwardFromUser');
+my $attachments = RT::Interface::Email::GetForwardAttachments(
+ Ticket => $TicketObj,
+ $txn ? ( Transaction => $txn ) : (),
+);
+
</%INIT>
<%ARGS>
diff --git a/t/web/ticket_forward.t b/t/web/ticket_forward.t
index 422be4d..403d71f 100644
--- a/t/web/ticket_forward.t
+++ b/t/web/ticket_forward.t
@@ -42,7 +42,6 @@ diag "Forward Ticket" if $ENV{TEST_VERBOSE};
},
button => 'ForwardAndReturn'
);
- $m->content_contains( 'Sent email successfully', 'sent mail msg' );
$m->content_contains(
'Forwarded Ticket to <rt-to at example.com>, <rt-too at example.com>, <rt-cc at example.com>, root (Enoch Root)',
'txn msg' );
@@ -51,7 +50,7 @@ diag "Forward Ticket" if $ENV{TEST_VERBOSE};
like( $mail, qr!To: .*?rt-to\@example.com!i, 'To field' );
like( $mail, qr!To: .*?rt-too\@example.com!i, 'To field' );
like( $mail, qr!Cc: rt-cc\@example.com!i, 'Cc field' );
- like( $mail, qr!Bcc: "root" <root\@localhost>!i, 'Bcc field' );
+ like( $mail, qr!Bcc: root\@localhost!i, 'Bcc field' );
like( $mail, qr!This is a forward of ticket!, 'content' );
like( $mail, qr!this is an attachment!, 'att content' );
like( $mail, qr!$att_name!, 'att file name' );
@@ -69,7 +68,6 @@ diag "Forward Transaction" if $ENV{TEST_VERBOSE};
},
button => 'ForwardAndReturn'
);
- $m->content_contains( 'Sent email successfully', 'sent mail msg' );
$m->content_like(
qr/Forwarded .*?Transaction #\d+.*? to <rt-to\@example\.com>, <rt-too\@example\.com>, <rt-cc\@example\.com>, root (Enoch Root)/,
'txn msg'
@@ -79,7 +77,7 @@ qr/Forwarded .*?Transaction #\d+.*? to <rt-to\@example\.com>, <rt-too\@
like( $mail, qr!To: .*rt-to\@example.com!i, 'To field' );
like( $mail, qr!To: .*rt-too\@example.com!i, 'To field' );
like( $mail, qr!Cc: rt-cc\@example.com!i, 'Cc field' );
- like( $mail, qr!Bcc: "root" <root\@localhost>!i, 'Bcc field' );
+ like( $mail, qr!Bcc: root\@localhost!i, 'Bcc field' );
like( $mail, qr!This is a forward of transaction!, 'content' );
like( $mail, qr!$att_name!, 'att file name' );
like( $mail, qr!this is an attachment!, 'att content' );
@@ -97,7 +95,6 @@ diag "Forward Ticket without content" if $ENV{TEST_VERBOSE};
fields => { To => 'rt-test at example.com', },
button => 'ForwardAndReturn'
);
- $m->content_contains( 'Sent email successfully', 'sent mail msg' );
my ($mail) = RT::Test->fetch_caught_mails;
like( $mail, qr/Subject: Fwd: \[example\.com #\d\] test forward without content/, 'Subject field' );
like( $mail, qr/To: rt-test\@example\.com/, 'To field' );
@@ -141,7 +138,6 @@ diag "Forward Transaction with attachments but empty content" if $ENV{TEST_VERBO
},
button => 'ForwardAndReturn'
);
- $m->content_contains( 'Sent email successfully', 'sent mail msg' );
$m->content_like( qr/Forwarded .*?Transaction #\d+.*? to <rt-test\@example\.com>/, 'txn msg' );
my ($mail) = RT::Test->fetch_caught_mails;
like( $mail, qr/Subject: test forward, empty content but attachments/, 'Subject field' );
@@ -199,9 +195,8 @@ diag "Forward Transaction with attachments but no 'content' part" if $ENV{TEST_V
},
button => 'ForwardAndReturn'
);
- $m->content_contains( 'Sent email successfully', 'sent mail msg' );
$m->content_like( qr/Forwarded .*?Transaction #\d+.*? to <rt-test\@example\.com>/, 'txn msg' );
-
+
# Forward ticket
$m->follow_link_ok( { text => 'Forward', n => 1 }, 'follow 1st Forward' );
$m->submit_form(
@@ -211,7 +206,6 @@ diag "Forward Transaction with attachments but no 'content' part" if $ENV{TEST_V
},
button => 'ForwardAndReturn'
);
- $m->content_contains( 'Sent email successfully', 'sent mail msg' );
$m->content_like( qr/Forwarded Ticket to <rt-test\@example\.com>/, 'txn msg' );
my ($forward_txn, $forward_ticket) = RT::Test->fetch_caught_mails;
commit 69f5d38408a08228225dac37df57fec646c65535
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Mon Aug 6 21:32:39 2012 -0400
Only add the default "This is a forward..." if no content is supplied
diff --git a/etc/initialdata b/etc/initialdata
index 533ce67..45ec88a 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -609,9 +609,8 @@ Content-Type: text/html
Name => "Forward", # loc
Description => "Forwarded message", # loc
Content => q{
-This is a forward of transaction #{$Transaction->id} of ticket #{ $Ticket->id }
-{ $ForwardTransaction->Content }
+{ $ForwardTransaction->Content =~ /\S/ ? $ForwardTransaction->Content : "This is a forward of transaction #".$Transaction->id." of ticket #". $Ticket->id }
}
},
{ Queue => 0,
@@ -619,9 +618,7 @@ This is a forward of transaction #{$Transaction->id} of ticket #{ $Ticket->id }
Description => "Forwarded ticket message", # loc
Content => q{
-This is a forward of ticket #{ $Ticket->id }
-
-{ $ForwardTransaction->Content }
+{ $ForwardTransaction->Content =~ /\S/ ? $ForwardTransaction->Content : "This is a forward of ticket #". $Ticket->id }
}
},
{ Queue => 0,
commit ac432e68309769f2d2f1700642356e6870083842
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Mon Aug 6 21:36:38 2012 -0400
Allow forwarding to set the subject
diff --git a/lib/RT/Action/SendForward.pm b/lib/RT/Action/SendForward.pm
index f524095..7776a5c 100644
--- a/lib/RT/Action/SendForward.pm
+++ b/lib/RT/Action/SendForward.pm
@@ -107,18 +107,6 @@ sub Prepare {
$mime->add_part($entity);
- unless ( $mime->head->get('Subject') ) {
- my $subject = '';
- $subject = $self->ForwardedTransactionObj->Subject
- if $self->ForwardedTransactionObj;
- $subject ||= $self->TicketObj->Subject;
- unless ( RT->Config->Get('ForwardFromUser') ) {
- $subject =
- RT::Interface::Email::AddSubjectTag( $subject, $self->TicketObj );
- }
- $mime->head->set( Subject => $self->MIMEEncodeString("Fwd: $subject") );
- }
-
my $txn_attachment = $self->TransactionObj->Attachments->First;
for my $header (qw/From To Cc Bcc/) {
if ( $txn_attachment->GetHeader( $header ) ) {
@@ -134,8 +122,9 @@ sub Prepare {
}
sub SetSubjectToken {
-
- # we already take care of this in Prepare.
+ my $self = shift;
+ return if RT->Config->Get('ForwardFromUser');
+ $self->SUPER::SetSubjectToken(@_);
}
sub ForwardedTransactionObj {
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index fc3ef57..2a41074 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -2990,6 +2990,7 @@ sub Forward {
my $self = shift;
my %args = (
Transaction => undef,
+ Subject => '',
To => '',
Cc => '',
Bcc => '',
@@ -3007,13 +3008,14 @@ sub Forward {
$args{$_} = join ", ", map { $_->format } RT::EmailParser->ParseEmailAddress( $args{$_} || '' ) for qw(To Cc Bcc);
my $mime = MIME::Entity->build(
- Type => $args{'ContentType'},
- Data => $args{Content},
+ Subject => $args{Subject},
+ Type => $args{ContentType},
+ Data => $args{Content},
);
$mime->head->set(
$_ => RT::Interface::Email::EncodeToMIME( String => $args{$_} ) )
- for grep defined $args{$_}, qw(To Cc Bcc);
+ for grep defined $args{$_}, qw(Subject To Cc Bcc);
$mime->head->set(
From => RT::Interface::Email::EncodeToMIME(
String => RT::Interface::Email::GetForwardFrom(
diff --git a/share/html/Ticket/Forward.html b/share/html/Ticket/Forward.html
index 15de800..cc3faa1 100644
--- a/share/html/Ticket/Forward.html
+++ b/share/html/Ticket/Forward.html
@@ -61,7 +61,7 @@
<td><% $from %></td></tr>
<tr><td align="right"><&|/l&>Subject</&>:</td>
-<td><% $subject %></td></tr>
+<td><input name="Subject" size="60" value="<% $ARGS{'Subject'} || $subject %>" /></td></tr>
<tr><td align="right"><&|/l&>To</&>:</td>
<td><input name="To" size="60" value="<% $ARGS{'To'} || '' %>" /></td></tr>
@@ -125,9 +125,7 @@ my $Title = $txn
my $from = RT::Interface::Email::GetForwardFrom(
$txn ? ( Transaction => $txn ) : ( Ticket => $TicketObj ) );
-my $subject = $TicketObj->Subject;
-$subject = RT::Interface::Email::AddSubjectTag( $subject, $TicketObj )
- unless RT->Config->Get('ForwardFromUser');
+my $subject = "Fwd: ".($txn || $TicketObj)->Subject;
my $attachments = RT::Interface::Email::GetForwardAttachments(
Ticket => $TicketObj,
commit 2cabf12393c4749979f082c2049f25713c860d1d
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Aug 15 20:11:47 2013 +0800
upgrade content for new customized forward messages
diff --git a/etc/upgrade/4.1.20/content b/etc/upgrade/4.1.20/content
new file mode 100644
index 0000000..5c323b2
--- /dev/null
+++ b/etc/upgrade/4.1.20/content
@@ -0,0 +1,56 @@
+use strict;
+use warnings;
+
+our @ScripActions = (
+ { Name => 'Send Forward',
+ Description => 'Send forwarded message',
+ ExecModule => 'SendForward', },
+);
+
+our @Scrips = (
+ { Description => 'On Forward Transaction Send forwarded message',
+ ScripCondition => 'On Forward Transaction',
+ ScripAction => 'Send Forward',
+ Template => 'Forward' },
+ { Description => 'On Forward Ticket Send forwarded message',
+ ScripCondition => 'On Forward Ticket',
+ ScripAction => 'Send Forward',
+ Template => 'Forward Ticket' },
+);
+
+our @Initial = (
+ sub {
+ my $forward_template = RT::Template->new(RT->SystemUser);
+ $forward_template->Load('Forward');
+ $forward_template->SetDescription('Forwarded message');
+
+ if ( $forward_template->Content eq q{
+This is a forward of transaction #{$Transaction->id} of ticket #{ $Ticket->id }
+} ) {
+ $forward_template->SetContent(q{
+
+{ $ForwardTransaction->Content =~ /\S/ ? $ForwardTransaction->Content : "This is a forward of transaction #".$Transaction->id." of ticket #". $Ticket->id }
+});
+ }
+ else {
+ RT->Logger->error('Current "Forward" template is not the default version, please check docs/4.2-UPGRADING');
+ }
+
+ my $forward_ticket_template = RT::Template->new(RT->SystemUser);
+ $forward_ticket_template->Load('Forward Ticket');
+ $forward_ticket_template->SetDescription('Forwarded ticket message');
+ if ( $forward_ticket_template->Content eq q{
+
+This is a forward of ticket #{ $Ticket->id }
+} ) {
+ $forward_ticket_template->SetContent(q{
+
+{ $ForwardTransaction->Content =~ /\S/ ? $ForwardTransaction->Content : "This is a forward of ticket #". $Ticket->id }
+});
+
+ }
+ else {
+ RT->Logger->error('Current "Forward Ticket" template is not the default version, please check docs/4.2-UPGRADING');
+ }
+ },
+);
commit 4edd7df4acee8d68447c1c071eafc39bbc6429b6
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sat Aug 24 13:41:28 2013 +0800
update tests to reflect new subject changes
subject tag is always prefixed(even before "Fwd:") now.
diff --git a/t/web/ticket_forward.t b/t/web/ticket_forward.t
index 403d71f..a298b3c 100644
--- a/t/web/ticket_forward.t
+++ b/t/web/ticket_forward.t
@@ -96,7 +96,7 @@ diag "Forward Ticket without content" if $ENV{TEST_VERBOSE};
button => 'ForwardAndReturn'
);
my ($mail) = RT::Test->fetch_caught_mails;
- like( $mail, qr/Subject: Fwd: \[example\.com #\d\] test forward without content/, 'Subject field' );
+ like( $mail, qr/Subject: \[example\.com #\d\] Fwd: test forward without content/, 'Subject field' );
like( $mail, qr/To: rt-test\@example\.com/, 'To field' );
like( $mail, qr/This is a forward of ticket #\d/, 'content' );
}
@@ -209,7 +209,7 @@ diag "Forward Transaction with attachments but no 'content' part" if $ENV{TEST_V
$m->content_like( qr/Forwarded Ticket to <rt-test\@example\.com>/, 'txn msg' );
my ($forward_txn, $forward_ticket) = RT::Test->fetch_caught_mails;
- my $tag = qr/Fwd: \[example\.com #\d+\]/;
+ my $tag = qr/\[example\.com #\d+\] Fwd:/;
like( $forward_txn, qr/Subject: $tag attachments for everyone/, 'Subject field is from txn' );
like( $forward_txn, qr/This is a forward of transaction/, 'forward description' );
like( $forward_ticket, qr/Subject: $tag test forward, attachments but no "content"/, 'Subject field is from ticket' );
@@ -257,7 +257,7 @@ diag "Forward Ticket Template with a Subject: line" if $ENV{TEST_VERBOSE};
);
my ($mail) = RT::Test->fetch_caught_mails;
- like($mail, qr/Subject: OVERRIDING SUBJECT/);
+ like($mail, qr/Subject: \[example.com #\d+\] OVERRIDING SUBJECT/);
}
undef $m;
commit ec4317f238cff012700b9e31eff170210575a30f
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sat Aug 24 13:54:35 2013 +0800
document "Forward" and "Forward Ticket" templates updates
diff --git a/docs/UPGRADING-4.2 b/docs/UPGRADING-4.2
index b7e2015..38539d4 100644
--- a/docs/UPGRADING-4.2
+++ b/docs/UPGRADING-4.2
@@ -263,4 +263,16 @@ removed.
=back
+=item *
+
+We updated default "Forward" and "Forward Ticket" templates to support
+customizing messages on forward. They will be updated automatically if you
+didn't change them before.
+
+But in case you have changed them already, you need to update them manually.
+You can use $ForwardTransaction to refer to the customized message in the
+templates, e.g. "Forward" template could be updated to:
+
+{ $ForwardTransaction->Content =~ /\S/ ? $ForwardTransaction->Content : "This is a forward of transaction #".$Transaction->id." of ticket #". $Ticket->id }
+
=cut
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list