[Rt-commit] rt branch, 4.0/rfc822-attachment, updated. rt-4.0.0-222-ge9438ff

Thomas Sibley trs at bestpractical.com
Tue May 17 16:03:42 EDT 2011


The branch, 4.0/rfc822-attachment has been updated
       via  e9438ff93e30c444f4690d76508585f3128f6aaa (commit)
       via  3642a925478113aab0da7c56b885ca0a39f91aa7 (commit)
      from  38ab255dec8fec923e031d6473d2f436d7aa03b6 (commit)

Summary of changes:
 lib/RT/Attachment.pm       |   30 +++++++++++++++++++++++++++---
 t/mail/rfc822-attachment.t |   10 +++++-----
 2 files changed, 32 insertions(+), 8 deletions(-)

- Log -----------------------------------------------------------------
commit 3642a925478113aab0da7c56b885ca0a39f91aa7
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Tue May 17 15:45:35 2011 -0400

    Update the message/rfc822 tests to reflect the current RT::Transaction->ContentAsMIME

diff --git a/t/mail/rfc822-attachment.t b/t/mail/rfc822-attachment.t
index be52c1b..cfac8ba 100644
--- a/t/mail/rfc822-attachment.t
+++ b/t/mail/rfc822-attachment.t
@@ -32,8 +32,7 @@ diag "simple rfc822 attachment";
     my $parsed = content_as_mime($top);
 
     for my $mime ($top, $parsed) {
-        diag $mime->head->get('X-RT-Original-Encoding') ? "reconstructed mail" : "original mail";
-
+        diag "testing mail";
         is $mime->parts, 2, 'two mime parts';
 
         like $mime->head->get('Subject'), qr/this is top/, 'top subject';
@@ -86,8 +85,7 @@ diag "multipart rfc822 attachment";
     my $parsed = content_as_mime($top);
 
     for my $mime ($top, $parsed) {
-        diag $mime->head->get('X-RT-Original-Encoding') ? "reconstructed mail" : "original mail";
-
+        diag "testing mail";
         is $mime->parts, 2, 'two mime parts';
 
         like $mime->head->get('Subject'), qr/this is top/, 'top subject';
@@ -117,7 +115,9 @@ sub content_as_mime {
     my ( $status, $id ) = RT::Test->send_via_mailgate($entity);
     is( $status >> 8, 0, "The mail gateway exited normally" );
     ok( $id, "created ticket" );
-    return RT::Test->last_ticket->Transactions->First->ContentAsMIME;
+    # We can't simply use Txn->ContentAsMIME since that is wrapped in a
+    # message/rfc822 entity
+    return RT::Test->last_ticket->Transactions->First->Attachments->First->ContentAsMIME(Children => 1);
 }
 
 sub headers_like {

commit e9438ff93e30c444f4690d76508585f3128f6aaa
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Tue May 17 15:58:43 2011 -0400

    Reconstruct message/* attachments correctly from their child attachments
    
    OriginalContent now returns the reconstructed message as a string and
    ContentAsMIME never adds child attachments when the parent is a
    message/* subtype.
    
    This commit makes t/mail/rfc822-attachment.t pass.

diff --git a/lib/RT/Attachment.pm b/lib/RT/Attachment.pm
index 1196850..a71e8c0 100644
--- a/lib/RT/Attachment.pm
+++ b/lib/RT/Attachment.pm
@@ -78,6 +78,7 @@ use warnings;
 use RT::Transaction;
 use MIME::Base64;
 use MIME::QuotedPrint;
+use MIME::Body;
 
 sub _OverlayAccessible {
   {
@@ -294,14 +295,27 @@ sub Content {
 =head2 OriginalContent
 
 Returns the attachment's content as octets before RT's mangling.
-Currently, this just means restoring text content back to its
+Generally this just means restoring text content back to its
 original encoding.
 
+If the attachment has a C<message/*> Content-Type, its children attachments
+are reconstructed and returned as a string.
+
 =cut
 
 sub OriginalContent {
     my $self = shift;
 
+    # message/* content types represent raw messages.  Since we break them
+    # apart when they come in, we'll reconstruct their child attachments when
+    # you ask for the OriginalContent of the message/ part.
+    if ($self->IsMessageContentType) {
+        # There shouldn't be more than one "subpart" to a message/* attachment
+        my $child = $self->Children->First;
+        return $self->Content unless $child and $child->id;
+        return $child->ContentAsMIME(Children => 1)->as_string;
+    }
+
     return $self->Content unless RT::I18N::IsTextualContentType($self->ContentType);
     my $enc = $self->OriginalEncoding;
 
@@ -446,12 +460,11 @@ sub ContentAsMIME {
         "Content-Type.charset" => $self->OriginalEncoding )
       if $self->OriginalEncoding;
 
-    use MIME::Body;
     $entity->bodyhandle(
         MIME::Body::Scalar->new( $self->OriginalContent )
     );
 
-    if ($opts{'Children'}) {
+    if ($opts{'Children'} and not $self->IsMessageContentType) {
         my $children = $self->Children;
         while (my $child = $children->Next) {
             $entity->make_multipart unless $entity->is_multipart;
@@ -462,6 +475,17 @@ sub ContentAsMIME {
     return $entity;
 }
 
+=head2 IsMessageContentType
+
+Returns a boolean indicating if the Content-Type of this attachment is a
+C<message/> subtype.
+
+=cut
+
+sub IsMessageContentType {
+    my $self = shift;
+    return $self->ContentType =~ m{^\s*message/}i ? 1 : 0;
+}
 
 =head2 Addresses
 

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


More information about the Rt-commit mailing list