[Rt-commit] rt branch, 3.8/improve-messagerfc822-handling, created. rt-3.8.10-3-g91d96dd

Kevin Falcone falcone at bestpractical.com
Thu Jun 2 10:17:46 EDT 2011


The branch, 3.8/improve-messagerfc822-handling has been created
        at  91d96ddff85ecb3bbee06815a7cca71b1f0d3db3 (commit)

- Log -----------------------------------------------------------------
commit afa0eb0f85c3600209b9df508af9184d9deeb6ad
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Wed Apr 21 16:10:43 2010 -0400

    RT::I18N::IsTextualContentType thinks message/rfc822 parts have content

diff --git a/lib/RT/Transaction_Overlay.pm b/lib/RT/Transaction_Overlay.pm
index b8ea938..e44342b 100755
--- a/lib/RT/Transaction_Overlay.pm
+++ b/lib/RT/Transaction_Overlay.pm
@@ -427,7 +427,7 @@ sub ContentObj {
     return undef unless ($Attachment);
 
     # If it's a textual part, just return the body.
-    if ( RT::I18N::IsTextualContentType($Attachment->ContentType) ) {
+    if ( _IsDisplayableTextualContentType($Attachment->ContentType) ) {
         return ($Attachment);
     }
 
@@ -456,7 +456,7 @@ sub ContentObj {
         # If that fails, return the first textual part which has some content.
         my $all_parts = $self->Attachments;
         while ( my $part = $all_parts->Next ) {
-            next unless RT::I18N::IsTextualContentType($part->ContentType)
+            next unless _IsDisplayableTextualContentType($part->ContentType)
                         && $part->Content;
             return $part;
         }
@@ -466,6 +466,19 @@ sub ContentObj {
     return (undef);
 }
 
+=head2 _IsDisplayableTextualContentType
+
+We may need to pull this out to another module later, but for now, this
+is better than RT::I18N::IsTextualContentType because that believes that
+a message/rfc822 email is displayable, despite it having no content
+
+=cut
+
+sub _IsDisplayableTextualContentType {
+    my $type = shift;
+    ($type =~ m{^text/(?:plain|html)\b}i) ? 1 : 0;
+}
+
 # }}}
 
 # {{{ sub Subject

commit 84d4bcaea0d3388dcce65b2354bf760ba5c5d447
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Wed Apr 21 16:13:35 2010 -0400

    Actually recurse into message/rfc822 parts looking for content
    
    We want to become better about recursing into multipart/ too, but
    this is better than the previous RT behavior which simply returned
    blank content

diff --git a/lib/RT/Transaction_Overlay.pm b/lib/RT/Transaction_Overlay.pm
index e44342b..62736a7 100755
--- a/lib/RT/Transaction_Overlay.pm
+++ b/lib/RT/Transaction_Overlay.pm
@@ -426,6 +426,34 @@ sub ContentObj {
 
     return undef unless ($Attachment);
 
+    my $Attachments = $self->Attachments;
+    while ( my $Attachment = $Attachments->Next ) {
+        if ( my $content = _FindPreferredContentObj( %args, Attachment => $Attachment ) ) {
+            return $content;
+        }
+    }
+
+    # If that fails, return the first top-level textual part which has some content.
+    # We probably really want this to become "recurse, looking for the other type of
+    # displayable".  For now, this maintains backcompat
+    my $all_parts = $self->Attachments;
+    while ( my $part = $all_parts->Next ) {
+        next unless _IsDisplayableTextualContentType($part->ContentType)
+        && $part->Content;
+        return $part;
+    }
+
+    return;
+}
+
+
+sub _FindPreferredContentObj {
+    my %args = @_;
+    my $Attachment = $args{Attachment};
+
+    # If we don't have any content, return undef now.
+    return undef unless $Attachment;
+
     # If it's a textual part, just return the body.
     if ( _IsDisplayableTextualContentType($Attachment->ContentType) ) {
         return ($Attachment);
@@ -437,7 +465,7 @@ sub ContentObj {
     elsif ( $Attachment->ContentType =~ qr|^multipart/mixed|i ) {
         my $kids = $Attachment->Children;
         while (my $child = $kids->Next) {
-            my $ret =  $self->ContentObj(%args, Attachment => $child);
+            my $ret =  _FindPreferredContentObj(%args, Attachment => $child);
             return $ret if ($ret);
         }
     }
@@ -452,13 +480,17 @@ sub ContentObj {
                 return $first;
             }
         }
+    }
+
+    # If this is a message/rfc822 mail, we need to dig into it in order to find 
+    # the actual textual content
 
-        # If that fails, return the first textual part which has some content.
-        my $all_parts = $self->Attachments;
-        while ( my $part = $all_parts->Next ) {
-            next unless _IsDisplayableTextualContentType($part->ContentType)
-                        && $part->Content;
-            return $part;
+    elsif ( $Attachment->ContentType =~ '^message/rfc822' ) {
+        my $children = $Attachment->Children;
+        while ( my $child = $children->Next ) {
+            if ( my $content = _FindPreferredContentObj( %args, Attachment => $child ) ) {
+                return $content;
+            }
         }
     }
 

commit 91d96ddff85ecb3bbee06815a7cca71b1f0d3db3
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Wed Jun 1 20:38:47 2011 -0400

    Work with our new multipart handling
    
    As part of our outlook handling code, we started recursing into
    multipart/alternative.  However, if you were multipart/multipart or
    something else, and the code doesn't express a preference for text/plain
    vs text/html we had a bail out to start at the top again looking for
    textual.  Instead, we'll look at the children of this multipart for
    anything textual, since that seems to make more sense and leave the
    "Search for something textual from the top" for later in the code path.

diff --git a/lib/RT/Transaction_Overlay.pm b/lib/RT/Transaction_Overlay.pm
index 62736a7..6d74310 100755
--- a/lib/RT/Transaction_Overlay.pm
+++ b/lib/RT/Transaction_Overlay.pm
@@ -479,6 +479,16 @@ sub _FindPreferredContentObj {
             if ( my $first = $plain_parts->First ) {
                 return $first;
             }
+        } else {
+            my $parts = $Attachment->Children;
+            $parts->LimitNotEmpty;
+
+            # If we actully found a part, return its content
+            while (my $part = $parts->Next) {
+                next unless _IsDisplayableTextualContentType($part->ContentType);
+                return $part;
+            }
+
         }
     }
 

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


More information about the Rt-commit mailing list