[rt-devel] PATCH: 'Bounce' (re-send) action for data transactions

Ruslan U. Zakirov cubic at acronis.ru
Fri Oct 24 03:24:08 EDT 2003


Victor Danilchenko wrote:
> 	Hi,
> 
> 	This is my first contribution (as well as my first semi-serious
> foray into both RT innards and Mason), so be please gentle...
> 
> 	Summary:
> 	In our RT installation, we have often wished to be able to
> forward a message from RT to an arbitrary address, most often for the
> purpose of e-mailing attachments that came with the message (downloading
> them by hand and then mailing them is a pain). This seems impossible in
> current RT; so I implemented this capability. I have added a third
> action tab ('[Bounce]') to share/html/Ticket/Elements/ShowTransaction,
> and I have created share/html/Ticket/Bounce.html
> 
> 	The code allows you to specify an arbitrary list of To: and Cc:
> recipients, as well as the subject, the latter being initially set from
> the subject of the first attachment of transaction, or the ticket
> subject if the former doesn't exist. It will insert the ticket tag into
> subject if necessary. Once it receives the destination information, it
> will construct a MIME::Entity object, populate it with all the
> attachments for a given transaction, and send it on its way via the
> Action::Mail::SendEmail facility.
> 
> 	Two questions:
> 
> 1) is the patch stylistically OK? is this patch submission? Should I
>    supply any additional info, such as the snapshot of the modified
>    interface?
See below.
> 2) Is it actually useful to anyone besides my group?
Yes. Not often but yes.
> 
> 
> 
> ------------------------------------------------------------------------
> 
> --- share/html/Ticket/Elements/ShowTransaction.orig	2003-10-23 14:19:03.000000000 -0400
> +++ share/html/Ticket/Elements/ShowTransaction	2003-10-23 14:21:02.000000000 -0400
> @@ -164,8 +164,16 @@
>  	     $titlebar_commands .= 
>  	     "[<a href=\"Update.html?id=".$Transaction->Ticket. 
>  	     "&QuoteTransaction=".$Transaction->Id.
> -	     "&Action=Comment\">". loc('Comment') ."</a>]";
> +	     "&Action=Comment\">". loc('Comment') ."</a>]&nbsp;";
>  	}
> +
> +	if ($Transaction->TicketObj->CurrentUserHasRight('ShowTicket')) {
ShowTransaction element called on each transaction. Don't you think that 
  it's very expensive to check this Ticket <-> User right? Also this 
check  must be done before call to this Element and RT do it now. So 
skip it.
> +		$titlebar_commands .= 
> +	  	  "[<a href=\"Bounce.html?id=".
> +		  $Transaction->Ticket . "&QuoteTransaction=".$Transaction->Id.
> +		  "\">". loc('Bounce') ."</a>]";
> +	}
> +
>  }
>  
>  </%INIT>
> --- share/html/Ticket/Bounce.html	2003-10-23 14:41:55.000000000 -0400
> +++ share/html/Ticket/Bounce.html	2003-10-23 14:33:37.000000000 -0400
> @@ -0,0 +1,107 @@
> +%# BEGIN LICENSE BLOCK
> +%# 
> +%# Copyright (c) 1996-2003 Jesse Vincent <jesse at bestpractical.com>
> +%# 
> +%# (Except where explictly superceded by other copyright notices)
> +%# 
> +%# 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.
> +%# 
> +%# Unless otherwise specified, all modifications, corrections or
> +%# extensions to this work which alter its source code become the
> +%# property of Best Practical Solutions, LLC when submitted for
> +%# inclusion in the work.
> +%# 
> +%# 
> +%# END LICENSE BLOCK
> +<& /Elements/Header, Title => loc("Bounce Transaction # [_1] [_2]", $Ticket->Id, $Ticket->Subject) &>
> +<& /Ticket/Elements/Tabs, 
> +    Ticket => $Ticket, current_tab => 'Ticket/Bounce.html?id='.$Ticket->id, 
> +    Title => loc("Bounce Transaction # [_1] [_2]", $Ticket->Id, $Ticket->Subject) &>
> +
> +<% $To && "<h1>Message sent!</h1>" | n %>
> +
> +% if ($To) {
> +%     use RT::Action::SendEmail;
> +%     use MIME::Entity;
> +%     my $sub = $Subject;
> +%     my $tag  = "[$RT::rtname #" . $Ticket->id . "]";
> +%     $sub = "$tag $sub" unless $sub =~ /\Q$tag\E/;
> +%     my $attachments = $Transaction->Attachments; 
> +%     my $MIMEObj = MIME::Entity->build (Type    => "multipart/mixed",
> +%                                        From    => "$RT::CorrespondAddress",
> +%                                        To      => "$To",
> +%                                        Cc      => "$Cc",
> +%                                        Subject => "$sub");
> +%     for (my $attch = $attachments->First; $attch; $attch = $attachments->Next) {
How about something like this?
while (my $attch = $attachment->Next) {
> +%         $MIMEObj->attach(Type => $attch->ContentType,
> +%                          Data => $attch->Content);
> +%     }
> +%
> +%     my $mailer = new RT::Action::SendEmail;
> +%     $mailer->SendMessage($MIMEObj);
> +% }
For such blocks of code use <%perl> </%perl> section instead of comment 
style.
> +
> +<BR>
> +<FORM ACTION="Bounce.html" NAME="TicketBounce" 
> +	METHOD=GET enctype="multipart/form-data">
> +<input type="hidden" name="id" value="<% "$id" %>">
> +<input type="hidden" name="QuoteTransaction" value="<% $Transaction->id %>">
> +
> +<TABLE BORDER=0 cellspacing=0 cellpadding=0>
> +<TR><TD align=right>Subject:</TD>
> +    <TD><input type="text" name="Subject" size=60 value="<% "$Subject" %>"></TD></TR>
> +<TR><TD align=right>To:</TD>
> +    <TD><input type="text" name="To" size=60 value="<% "$To" %>"></TD></TR>
> +<TR><TD align=right>Cc:</TD>
> +    <TD><input type="text" name="Cc" size=60></TD></TR>
> +<TR><TD colspan=2>
> +<& /Elements/Submit, Name => 'SubmitTicket' &>
> +
> +    </TD></TR>
> +</TABLE>
> +
> +<TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=2 BORDER=0>
> +      <& /Ticket/Elements/ShowTransaction, Ticket => $Ticket, Transaction => $Transaction, ShowHeaders => $ARGS{'ShowHeaders'}, ShowTitleBarCommands => $ShowTitleBarCommands, Collapsed => $Collapsed &>
> +</TABLE>
> +</FORM>
> +
> +<%ARGS>
> +$id => undef
> +$ShowTitleBarCommands => 0
> +$Collapsed => 0
> +$To => undef
> +$Cc => undef
> +$Subject => undef
> +</%ARGS>
> +
> +<%INIT>
> +
> +  
> +
> +my $Ticket = LoadTicket ($id);
> +my $Transaction;
> +for (my $trs = $Ticket->Transactions;
> +     $Transaction = $trs->Next;) {
> +    last if $Transaction->id == $ARGS{'QuoteTransaction'};
What about pasting only TransactionId?
my $Transaction = RT::Transaction->new($RT::CurrentUser);
$Transaction->Load($ARGS{'QuoteTransaction'});
my $Ticket = $Transaction->TicketObj;
> +
> +
> +my $header = (grep (/^Subject/i, split (/\n/, $Transaction->Message->First->Headers)))[0];
Wrong way to get Subject it could be multiline. But also it's wrong we 
have allready func for this: $Transaction->Subject();
> +$Subject = $1 if ($header && $header =~ /^subject:\s+(.*)/i);
> +$Subject ||= $Ticket->Subject;
> +
> +unless ($Ticket->CurrentUserHasRight('ShowTicket')) {
> +	Abort("No permission to view ticket");
> +}
Do such test just after you've got $Ticket object in such case you 
economy one select to DB if user don't have rights.
> +</%INIT>
> +
> +
> +
> +





More information about the Rt-devel mailing list