[Rt-commit] r4140 - in rt/branches/3.7-EXPERIMENTAL: . etc html/Ticket/Elements lib/RT

ruz at bestpractical.com ruz at bestpractical.com
Tue Nov 22 23:55:27 EST 2005


Author: ruz
Date: Tue Nov 22 23:55:27 2005
New Revision: 4140

Modified:
   rt/branches/3.7-EXPERIMENTAL/   (props changed)
   rt/branches/3.7-EXPERIMENTAL/etc/RT_Config.pm.in
   rt/branches/3.7-EXPERIMENTAL/html/Ticket/Elements/ShowMessageHeaders
   rt/branches/3.7-EXPERIMENTAL/html/Ticket/Elements/ShowTransactionAttachments
   rt/branches/3.7-EXPERIMENTAL/lib/RT/Attachment_Overlay.pm
Log:


Modified: rt/branches/3.7-EXPERIMENTAL/etc/RT_Config.pm.in
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/etc/RT_Config.pm.in	(original)
+++ rt/branches/3.7-EXPERIMENTAL/etc/RT_Config.pm.in	Tue Nov 22 23:55:27 2005
@@ -424,7 +424,7 @@
 
 # $MaxInlineBody is the maximum attachment size that we want to see
 # inline when viewing a transaction. 13456 is a random sane-sounding
-# default.
+# default. RT inline any text if value is undefined or 0.
 
 Set($MaxInlineBody, 13456);
 

Modified: rt/branches/3.7-EXPERIMENTAL/html/Ticket/Elements/ShowMessageHeaders
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Ticket/Elements/ShowMessageHeaders	(original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Ticket/Elements/ShowMessageHeaders	Tue Nov 22 23:55:27 2005
@@ -45,46 +45,44 @@
 %# END BPS TAGGED BLOCK }}}
 <table>
 % foreach my $header (@headers) {
-%     next unless $display_headers{_all}
-%           or ($display_headers{ lc $header->{Tag} }
-%                 and length $header->{Value});
   <tr>
-    <td align="right" class="message-header-key"><%$header->{'Tag'}%>:</td>
-    <td class="message-header-value"><%$header->{'Value'} | n%></td>
+    <td align="right" class="message-header-key"><% $header->{'Tag'} %>:</td>
+    <td class="message-header-value"><% $header->{'Value'} | n %></td>
   </tr>
 % }
 </table>
 <%INIT>
-my $content = $Headers;
-$m->comp('/Elements/Callback', content => \$content, %ARGS);
+my @headers;
+foreach my $field( $Message->SplitHeaders ) {
+    my ($tag, $value) = split /:/, $field, 2;
+    next unless $tag && $value;
+    push @headers, { Tag => $tag, Value => $value };
+}
 
 # apply html escaping on the original content
 # we'll display the value without escaping later (for MakeClicky et al.)
-$content = $m->interp->apply_escapes($content, 'h');
-
-my @lines = split /\n/, $content;
-my $in_header = 0;
-my @headers;
-
-for (@lines) {
-    if (/^(\S+):\s+(.*)$/) {
-        push @headers, { Tag => $1, Value => $2 };
-    }
-    elsif (/^\s+/) {
-        $headers[-1]->{'Value'} .= $_;
-    }
-    else {
-        s/:$//;
-        push @headers, { Tag => $_, Value => '' };
-    }
+foreach ( @headers ) {
+    $_->{'Value'} = $m->interp->apply_escapes( $_->{Value}, 'h' );
 }
 
-my %display_headers = map { lc($_) => 1 } @$DisplayHeaders;
-
-$m->comp('/Elements/Callback', _CallbackName => 'Headers', content => \$content, headers => \@headers, display_headers => \%display_headers, %ARGS);
+my %display_headers = map { lc($_) => 1 } @DisplayHeaders;
 
+$m->comp( '/Elements/Callback',
+          message         => $Message,
+          headers         => \@headers,
+          display_headers => \%display_headers,
+        );
+
+unless ( $display_headers{'_all'} ) {
+    @headers = grep $display_headers{ lc $_->{'Tag'} },
+               @headers;
+}
+if ( $Localize ) {
+    $_->{'Tag'} = loc($_->{'Tag'}) foreach @headers;
+}
 </%INIT>
 <%ARGS>
-$Headers => undef
-$DisplayHeaders => undef
+$Message => undef
+$Localize => 1
+ at DisplayHeaders => ('_all')
 </%ARGS>

Modified: rt/branches/3.7-EXPERIMENTAL/html/Ticket/Elements/ShowTransactionAttachments
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Ticket/Elements/ShowTransactionAttachments	(original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Ticket/Elements/ShowTransactionAttachments	Tue Nov 22 23:55:27 2005
@@ -43,61 +43,38 @@
 %# those contributions and any derivatives thereof.
 %# 
 %# END BPS TAGGED BLOCK }}}
-<%perl>
+<%PERL>
 # Find all the attachments which have parent $Parent
 # For each of these attachments
 foreach my $message ( grep { $_->Parent == $Parent } @$Attachments ) {
+    $m->comp( 'ShowMessageHeaders',
+              Message        => $message,
+              DisplayHeaders => \@DisplayHeaders,
+            );
 
-    # {{{    show the headers
-    my $headers = $message->Headers;
-    chomp $headers;
-
-    # localize the common headers (like 'Subject:'), too.
-    $headers =~ s/^(?!\s)([^:]+)(?=:)/loc($1)/em;
-    $m->comp(
-        'ShowMessageHeaders',
-        Headers        => $headers,
-        Transaction    => $Transaction,
-        DisplayHeaders => \@DisplayHeaders
-    );
-
-    # }}}
-    # {{{ if there's any size at all, show the download link
     my $size = $message->ContentLength;
-    if ($size) {
-
+    if ( $size ) {
 </%PERL>
 <div class="downloadattachment">
-<%PERL>
-
-    # show a download link
-    if ( $size > 1024 ) {
-        $size = loc( "[_1]k", int( $size / 102.4 ) / 10 );
-    }
-    else {
-        $size = loc( "[_1]b", $size );
-    }
-
-</%PERL> 
 <a href="<% $AttachPath %>/<% $Transaction->Id %>/<% $message->Id %>/<% $message->Filename | u%>">
 <&|/l&>Download</&> <% $message->Filename || loc('(untitled)') %></a>
 % if ( !$message->Filename && $message->ContentType =~ /text/ ) {
 <span>[<a href="<% $AttachPath %>/WithHeaders/<% $message->Id %>"><% loc('with headers') %></a>]</span>
 % }
-<span class="downloadcontenttype">[<% $message->ContentType %> <% $size %>]</span>
+<span class="downloadcontenttype">[<% $message->ContentType %> <% $size_to_str->( $size ) %>]</span>
 </div>
-% }
-% # }}}
+%   }
+
 <div class="messagebody">
-<%perl>
-# {{{   if it has a content-disposition: attachment, don't show inline
+<%PERL>
+# {{{ if it has a content-disposition: attachment, don't show inline
 unless ( $message->GetHeader('Content-Disposition') =~ /attachment/i ) {
 
     my $content;
 
     # If it's text
     if (   $message->ContentType =~ m{^(text|message)}i
-        && $size <= $RT::MaxInlineBody )
+        && (!$RT::MaxInlineBody || $size <= $RT::MaxInlineBody) )
     {
 
         if (
@@ -130,13 +107,11 @@
 
             # if it's a text/html clean the body and show it
             if ( $message->ContentType =~ m{^text/(?:html|enriched)$}i ) {
-                $content =
-                  $m->comp( '/Elements/ScrubHTML', Content => $content );
-                $m->out($content);
+                $m->out( $m->comp( '/Elements/ScrubHTML', Content => $content ) );
             }
 
             # if it's a text/plain show the body
-            elsif ( $message->ContentType =~ m{^(text|message|text)}i ) {
+            elsif ( $message->ContentType =~ m{^(text|message)}i ) {
 
                 eval { $content = Text::Quoted::extract($content); };
                 if ($@) { 1; }
@@ -149,7 +124,6 @@
                 );
             }
         }
-
     }
 
     # if it's an image, show it as an image
@@ -184,14 +158,13 @@
 $UpdatePath => $RT::WebPath."/Ticket/Update.html"
 $EmailRecordPath => $RT::WebPath."/Ticket/ShowEmailRecord.html"
 $Attachments => undef
-$AttachmentContent => undef
+$AttachmentContent => {}
 $ShowBody => 1
 $Parent => 0
-$ParentObj => 0
+$ParentObj => undef
 </%ARGS>
 <%INIT>
 my @DisplayHeaders=qw( _all);
-
 if ( $Transaction->Type =~ /EmailRecord$/ ) {
     @DisplayHeaders = qw(To Cc Bcc);
 }
@@ -200,4 +173,19 @@
 elsif (!$ShowHeaders)  {
         @DisplayHeaders = qw(To From RT-Send-Cc Cc Bcc Date Subject);
 }
+
+my $size_to_str = sub {
+    my $size = shift;
+    # show a download link
+    if ( $size > 1024*1024 ) {
+        $size = loc( "[_1]b", int( $size / 1024 / 102.4 ) / 10 );
+    }
+    elsif ( $size > 1024 ) {
+        $size = loc( "[_1]k", int( $size / 102.4 ) / 10 );
+    }
+    else {
+        $size = loc( "[_1]b", $size );
+    }
+    return $size;
+};
 </%INIT>

Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/Attachment_Overlay.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/Attachment_Overlay.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/Attachment_Overlay.pm	Tue Nov 22 23:55:27 2005
@@ -428,11 +428,7 @@
 =cut
 
 sub Headers {
-    my $self = shift;
-    my $hdrs="";
-    my @headers =  grep { !/^RT-Send-Bcc/i } $self->_SplitHeaders;
-    return join("\n", at headers);
-
+    return join("\n", $_[0]->SplitHeaders);
 }
 
 
@@ -451,9 +447,10 @@
     my $self = shift;
     my $tag = shift;
     foreach my $line ($self->_SplitHeaders) {
-        if ($line =~ /^\Q$tag\E:\s+(.*)$/si) { #if we find the header, return its value
-            return ($1);
-        }
+        next unless $line =~ /^\Q$tag\E:\s+(.*)$/si;
+
+        #if we find the header, return its value
+        return ($1);
     }
     
     # we found no header. return an empty string
@@ -528,6 +525,20 @@
 
 # }}}
 
+=head2 SplitHeaders
+
+Returns an array of this attachment object's headers, with one header 
+per array entry. Multiple lines are folded.
+
+B<Never> returns C<RT-Send-Bcc> field.
+
+=cut
+
+sub SplitHeaders {
+    my $self = shift;
+    return (grep !/^RT-Send-Bcc/i, $self->_SplitHeaders(@_) );
+}
+
 =head2 _SplitHeaders
 
 Returns an array of this attachment object's headers, with one header 


More information about the Rt-commit mailing list