% if (keys %documents) {
<tr>
  <td class="label" valign="top"><&|/l&>Include attachments</&>:</td>
  <td>
% foreach my $key (sort { lc($a) cmp lc($b) } keys %documents) {
<dl>
<dt><%$key%></dt>
% foreach my $rev (@{$documents{$key}}) {
<dd>
<input type="checkbox" class="checkbox" name="AttachExisting" value="<% $rev->Id %>" />
<font size="-2">
<a href="<%RT->Config->Get('WebPath')%>/Ticket/Attachment/<%$rev->TransactionId%>/<%$rev->Id%>/<%$rev->Filename | un %>">
% my $desc = loc("[_1] ([_2]) by [_3]", $rev->CreatedAsString, $rev->FriendlyContentLength, $m->scomp('/Elements/ShowUser', User => $rev->CreatorObj));
<% $desc |n%>
</a>
</font>
</dd>
% }
</dl>
% }
  </td>
</tr>
% }
<%init>
return unless $TicketObj;

# NOTE: we can't use here $m->comp_exists('/Ticket/Elements/FindAttachments')
#       because if you upgrade RT 4.0 to 4.2 then the component still exists
#       but is unused by RT 4.2
my $Attachments = $TicketObj->can('Attachments')
    ? $TicketObj->Attachments                                             # RT 4.2
    : $m->comp('/Ticket/Elements/FindAttachments', Ticket => $TicketObj); # RT 4.0

my %documents;
while ( my $attach = $Attachments->Next() ) {
    next unless defined $attach->Filename && length $attach->Filename;
    unshift( @{ $documents{ $attach->Filename } }, $attach );
}
</%init>

<%args>
$TicketObj => undef
</%args>
