[otrs-cvs] otrs/Kernel/System EmailParser.pm,1.107,1.107.2.1

"CVS commits notifications of OTRS.org" <[email protected]>
Newsgroups gmane.comp.otrs.cvs
Message-ID <[email protected]>
Comments:
Update of /home/cvs/otrs/Kernel/System
In directory lancelot:/tmp/cvs-serv3201/Kernel/System

Modified Files:
      Tag: rel-3_1
	EmailParser.pm 
Log Message:
 - 2012-11-29 Fixed bug#1970 - Email attachments of type .msg (Outlook-Message) are converted.

Author: mg

Index: EmailParser.pm
===================================================================
RCS file: /home/cvs/otrs/Kernel/System/EmailParser.pm,v
retrieving revision 1.107
retrieving revision 1.107.2.1
diff -2 -u -d -r1.107 -r1.107.2.1
--- EmailParser.pm	21 Nov 2011 19:20:34 -0000	1.107
+++ EmailParser.pm	29 Nov 2012 12:42:28 -0000	1.107.2.1
@@ -1,5 +1,5 @@
 # --
 # Kernel/System/EmailParser.pm - the global email parser module
-# Copyright (C) 2001-2011 OTRS AG, http://otrs.org/
+# Copyright (C) 2001-2012 OTRS AG, http://otrs.org/
 # --
 # $Id$
@@ -153,4 +153,7 @@
         my $Parser = MIME::Parser->new();
         $Parser->output_to_core('ALL');
+
+        # Keep nested messages as attachments (see bug#1970).
+        $Parser->extract_nested_messages(0);
         $Self->{ParserParts} = $Parser->parse_data( $Self->{Email}->as_string() );
     }
@@ -718,10 +721,6 @@
     }
 
-    # check if there is no recommended_filename -> add file-NoFilenamePartCounter
-    if ( !$Part->head()->recommended_filename() ) {
-        $Self->{NoFilenamePartCounter}++;
-        $PartData{Filename} = "file-$Self->{NoFilenamePartCounter}";
-    }
-    else {
+    # check if there is no recommended_filename or subject -> add file-NoFilenamePartCounter
+    if ( $Part->head()->recommended_filename() ) {
         $PartData{Filename}           = decode_mimewords( $Part->head()->recommended_filename() );
         $PartData{ContentDisposition} = $Part->head()->get('Content-Disposition');
@@ -756,4 +755,35 @@
     }
 
+    # Guess the filename for nested messages (see bug#1970).
+    elsif ( $PartData{ContentType} eq 'message/rfc822' ) {
+        my ($SubjectString) = $Part->as_string =~ m/^Subject: ([^\n]*(\n[ \t][^\n]*)*)/m;
+        my $Subject;
+        foreach my $Decoded ( decode_mimewords($SubjectString) ) {
+            if ( $Decoded->[0] ) {
+                $Subject .= $Self->{EncodeObject}->Convert2CharsetInternal(
+                    Text  => $Decoded->[0],
+                    From  => $Decoded->[1] || 'us-ascii',
+                    Check => 1,
+                );
+            }
+        }
+
+        # trim whitespace
+        $Subject =~ s/^\s+|\n|\s+$//;
+        if ( length($Subject) > 246 ) {
+            $Subject = substr( $Subject, 0, 246 );
+        }
+
+        if ( $Subject eq '' ) {
+            $Self->{NoFilenamePartCounter}++;
+            $Subject = "Unbenannt-$Self->{NoFilenamePartCounter}";
+        }
+        $PartData{Filename} = $Subject . '.eml';
+    }
+    else {
+        $Self->{NoFilenamePartCounter}++;
+        $PartData{Filename} = "file-$Self->{NoFilenamePartCounter}";
+    }
+
     # parse/get Content-Id and Content-Location for html email attachments
     $PartData{ContentID}       = $Part->head()->get('Content-Id');
---------------------------------------------------------------------
OTRS mailing list: cvs-log - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/cvs-log
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/cvs-log
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.