[Rt-commit] rt branch, 3.8-improve-messagerfc822-handling, created. rt-3.8.7-2-gc4087a5
Kevin Falcone
falcone at bestpractical.com
Wed Apr 21 17:00:28 EDT 2010
The branch, 3.8-improve-messagerfc822-handling has been created
at c4087a58b61926e701199ddf23e210604fb1727a (commit)
- Log -----------------------------------------------------------------
commit 71243f32204ad31814de1e4a9fa7b4bbb0e7aeee
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 96ccf51..2487a43 100755
--- a/lib/RT/Transaction_Overlay.pm
+++ b/lib/RT/Transaction_Overlay.pm
@@ -405,7 +405,7 @@ sub ContentObj {
return undef unless my $Attachment = $self->Attachments->First;
# If it's a textual part, just return the body.
- if ( RT::I18N::IsTextualContentType($Attachment->ContentType) ) {
+ if ( _IsDisplayableTextualContentType($Attachment->ContentType) ) {
return ($Attachment);
}
@@ -425,7 +425,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;
}
@@ -435,6 +435,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 c4087a58b61926e701199ddf23e210604fb1727a
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 2487a43..616e999 100755
--- a/lib/RT/Transaction_Overlay.pm
+++ b/lib/RT/Transaction_Overlay.pm
@@ -399,10 +399,33 @@ sub ContentObj {
my $self = shift;
my %args = ( Type => $PreferredContentType || 'text/plain',
@_ );
+ 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.
- # Get the set of toplevel attachments to this transaction.
- return undef unless my $Attachment = $self->Attachments->First;
+ return undef unless $Attachment;
# If it's a textual part, just return the body.
if ( _IsDisplayableTextualContentType($Attachment->ContentType) ) {
@@ -421,13 +444,17 @@ sub ContentObj {
if ( my $first = $plain_parts->First ) {
return $first;
}
+ }
- # 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;
+ # If this is a message/rfc822 mail, we need to dig into it in order to find
+ # the actual textual content
+
+ elsif ( $Attachment->ContentType =~ '^message/rfc822' ) {
+ my $children = $Attachment->Children;
+ while ( my $child = $children->Next ) {
+ if ( my $content = _FindPreferredContentObj( %args, Attachment => $child ) ) {
+ return $content;
+ }
}
}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list