[rt-devel] MIME parsing fix

ivan ivan-rt-devel at 420.am
Mon Apr 2 12:21:23 EDT 2001


As part of our data import, I threw that last two years' of mail-abuse.org
mail at RT2.  I found that the is_multipart method is not appropriate for
deciding if a message has parts.  According to the MIME::Entity manpage:

    Does this entity's effective MIME type indicate that it's a multipart
    entity? ... Note that this says nothing about whether or not parts
    were extracted.

What I found was that badly-formed MIME messages that indicated they were
multipart but didn't have parts confused Attachment.pm.  This change
should only insert database records for MIME parts if they could be
parsed, and won't error out on badly-formed messages.

If you need more information please let me know.

Index: Attachment.pm
===================================================================
RCS file: /proj/maps/cvsroot/rt/lib/RT/Attachment.pm,v
retrieving revision 1.1.2.4
retrieving revision 1.17
diff -u -r1.1.2.4 -r1.17
--- Attachment.pm       2000/12/19 00:58:33     1.1.2.4
+++ Attachment.pm       2001/03/21 18:11:13     1.17
@@ -115,7 +119,8 @@
   #Get the filename
   my $Filename = $Attachment->head->recommended_filename;
   
-   if ($Attachment->is_multipart) {
+  #if ($Attachment->is_multipart) {
+  if ($Attachment->parts) {
     $id = $self->SUPER::Create(TransactionId => $args{'TransactionId'},
                               Parent => 0,
                               ContentType  => $Attachment->mime_type,
@@ -123,18 +128,13 @@
                               Subject => $Subject,
        
                              );
+       
+    foreach my $part ( $Attachment->parts ) {
     
-  for (my $Counter = 0; $Counter < $Attachment->parts(); $Counter++) {
       my $SubAttachment = new RT::Attachment($self->CurrentUser);
       $SubAttachment->Create(TransactionId => $args{'TransactionId'},
-                            Parent => "$id",
-
-                            # This was "part", and has always worked
-                            # until I upgraded MIME::Entity.  seems
-                            # like "parts" should work according to
-                            # the doc?
-
-                            Attachment => $Attachment->parts($Counter),
+                            Parent => $id,
+                            Attachment => $part,
                             ContentType  => $Attachment->mime_type,
                             Headers => $Attachment->head->as_string(),
                




-- 
meow
_ivan




More information about the Rt-devel mailing list