[Rt-commit] rt branch, trs/one-two-three-check, created. rt-4.0.1-396-g976c265

Thomas Sibley trs at bestpractical.com
Mon Dec 19 20:10:22 EST 2011


The branch, trs/one-two-three-check has been created
        at  976c26502e1918827749f93f4cc62b09f7bb4fc0 (commit)

- Log -----------------------------------------------------------------
commit 976c26502e1918827749f93f4cc62b09f7bb4fc0
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Nov 7 10:44:31 2011 -0500

    WIP of inline images in HTML mail
    
    Needs some corner case proofing and bullet proofing and maybe some
    profiling to make sure it's not absurd.  An option would be great too.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index cb22847..6c6f9b7 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -2847,6 +2847,13 @@ sub _NewScrubber {
     $scrubber->allow(
         qw[A B U P BR I HR BR SMALL EM FONT SPAN STRONG SUB SUP STRIKE H1 H2 H3 H4 H5 H6 DIV UL OL LI DL DT DD PRE BLOCKQUOTE]
     );
+    $scrubber->rules(
+        img => {
+            '*' => 0,
+            alt => 1,
+            src => qr/^cid:/i,
+        },
+    );
     $scrubber->comment(0);
 
     return $scrubber;
diff --git a/share/html/Ticket/Elements/ShowTransactionAttachments b/share/html/Ticket/Elements/ShowTransactionAttachments
index ccf35fd..21c5887 100644
--- a/share/html/Ticket/Elements/ShowTransactionAttachments
+++ b/share/html/Ticket/Elements/ShowTransactionAttachments
@@ -139,6 +139,8 @@ my $size_to_str = sub {
     return $size;
 };
 
+my %displayed;
+
 my $render_attachment = sub {
     my $message = shift;
 
@@ -213,6 +215,29 @@ my $render_attachment = sub {
                     ticket  => $Ticket,
                 );
 
+                use HTML::RewriteAttributes::Resources;
+                $content = HTML::RewriteAttributes::Resources->rewrite($content, sub {
+                    my $cid  = shift;
+                    my %meta = @_;
+                    return $cid unless    lc $meta{tag}  eq 'img'
+                                      and lc $meta{attr} eq 'src'
+                                      and $cid =~ s/^cid://i;
+
+                    if (@$Attachments) {
+                        for my $attach (@$Attachments) {
+                            if (($attach->GetHeader('Content-ID') || '') eq "<$cid>") {
+                                $displayed{$attach->Id}++;
+                                return "$AttachPath/" . $Transaction->Id . '/' . $attach->Id;
+                            }
+                        }
+                    } else {
+                        # XXX TODO: build a collection and limit here
+                        return "cid:$cid";
+                    }
+
+                    return "";
+                });
+
                 require HTML::Quoted;
                 $content = HTML::Quoted->extract($content)
                   unless $message->Filename;
@@ -250,7 +275,11 @@ my $render_attachment = sub {
 
     # if it's an image, show it as an image
     elsif ( RT->Config->Get('ShowTransactionImages') and  $message->ContentType =~ /^image\//i ) {
-        if ( $disposition ne 'inline' ) {
+        if ( $displayed{$message->Id} ) {
+            $m->out('<p><i>'. loc( 'Image displayed inline above' ) .'</i></p>');
+            return;
+        }
+        elsif ( $disposition ne 'inline' ) {
             $m->out('<p>'. loc( 'Message body is not shown because sender requested not to inline it.' ) .'</p>');
             return;
         }

-----------------------------------------------------------------------


More information about the Rt-commit mailing list