Author: Alexandru Stanoi
Date: 2007-02-27 16:54:37 +0100 (Tue, 27 Feb 2007)
New Revision: 4692

Log:
- Fixed issue #10200 (part 1): Content-Disposition header is no longer created
  during parsing if it is missing. Also it's disposition type is no longer
  "attachment" by default (this requires setting $filePart->dispositionType =
  ezcMailFile::DISPLAY_ATTACHMENT or ezcMailFile::DISPLAY_INLINE explicitly).
- Fixed issue #10200 (part 2): The value of the generated Content-ID header
  contains the filename encoded with base64 to avoid problems.

Added:
   stable/Mail/1.2/tests/parser/data/various/default-disposition-header
Modified:
   stable/Mail/1.2/ChangeLog
   stable/Mail/1.2/src/parser/parts/file_parser.php
   stable/Mail/1.2/src/parts/file.php
   stable/Mail/1.2/src/tools.php
   stable/Mail/1.2/tests/composer_test.php
   stable/Mail/1.2/tests/parser/parser_test.php
   stable/Mail/1.2/tests/parts/file_part_test.php
   stable/Mail/1.2/tests/parts/stream_file_part_test.php
   stable/Mail/1.2/tests/parts/virtual_file_part_test.php

Modified: stable/Mail/1.2/ChangeLog
===================================================================
--- stable/Mail/1.2/ChangeLog   2007-02-27 15:30:03 UTC (rev 4691)
+++ stable/Mail/1.2/ChangeLog   2007-02-27 15:54:37 UTC (rev 4692)
@@ -8,6 +8,12 @@
   (The documentation was correct, the implementation was wrong.)
 - Fixed issue #10283: ImapSet does not return the trailing parenthesis ')'.
 - Fixed issue #10312: Fixed the value of ezcMail::QUOTED_PRINTABLE constant.
+- Fixed issue #10200 (part 1): Content-Disposition header is no longer created
+  during parsing if it is missing. Also it's disposition type is no longer
+  "attachment" by default (this requires setting $filePart->dispositionType =
+  ezcMailFile::DISPLAY_ATTACHMENT or ezcMailFile::DISPLAY_INLINE explicitly).
+- Fixed issue #10200 (part 2): The value of the generated Content-ID header
+  contains the filename encoded with base64 to avoid problems.
 
 
 1.2 - Monday 18 December 2006

Modified: stable/Mail/1.2/src/parser/parts/file_parser.php
===================================================================
--- stable/Mail/1.2/src/parser/parts/file_parser.php    2007-02-27 15:30:03 UTC 
(rev 4691)
+++ stable/Mail/1.2/src/parser/parts/file_parser.php    2007-02-27 15:54:37 UTC 
(rev 4692)
@@ -274,7 +274,11 @@
         {
             $filePart->dispositionType = ezcMailFile::DISPLAY_INLINE;
         }
-
+        if ( preg_match( '/^\s*attachment;?/i',
+                        $this->headers['Content-Disposition'], $matches ) )
+        {
+            $filePart->dispositionType = ezcMailFile::DISPLAY_ATTACHMENT;
+        }
         return $filePart;
     }
 }

Modified: stable/Mail/1.2/src/parts/file.php
===================================================================
--- stable/Mail/1.2/src/parts/file.php  2007-02-27 15:30:03 UTC (rev 4691)
+++ stable/Mail/1.2/src/parts/file.php  2007-02-27 15:54:37 UTC (rev 4692)
@@ -91,8 +91,6 @@
         $this->properties['contentId'] = null;
 
         $this->fileName = $fileName;
-        $this->setHeader( 'Content-Transfer-Encoding', 'base64' );
-        $this->dispositionType = self::DISPLAY_ATTACHMENT;
     }
 
     /**
@@ -110,25 +108,25 @@
         {
             case 'fileName':
                 $this->properties['fileName'] = $value;
-                $this->setHeaderContentType();
-                $this->setHeaderContentDisposition();
                 break;
+
             case 'mimeType':
                 $this->properties['mimeType'] = $value;
-                $this->setHeaderContentType();
                 break;
+
             case 'contentType':
                 $this->properties['contentType'] = $value;
-                $this->setHeaderContentType();
                 break;
+
             case 'dispositionType':
                 $this->properties['dispositionType'] = $value;
-                $this->setHeaderContentDisposition();
                 break;
+
             case 'contentId':
                 $this->properties['contentId'] = $value;
                 $this->setHeader( 'Content-ID', '<' . $value . '>' );
                 break;
+
             default:
                 return parent::__set( $name, $value );
                 break;
@@ -203,15 +201,29 @@
      */
     private function setHeaderContentDisposition()
     {
-        if ( $this->contentDisposition == null )
+        if ( isset( $this->dispositionType ) )
         {
-            $this->contentDisposition = new ezcMailContentDispositionHeader();
+            if ( $this->contentDisposition === null )
+            {
+                $this->contentDisposition = new 
ezcMailContentDispositionHeader();
+            }
+            $this->contentDisposition->disposition = $this->dispositionType;
+            $this->contentDisposition->fileName = basename( $this->fileName );
         }
-        $this->contentDisposition->disposition = $this->dispositionType;
-        $this->contentDisposition->fileName = basename( $this->fileName );
+    }
 
-        // $this->setHeader( 'Content-Disposition',
-        //                  $this->dispositionType .'; ' . 'filename="' . 
basename( $this->fileName ) . '"' );
+    /**
+     * Override of the generate() method from ezcMailPart. Used to set headers 
before
+     * generating the part.
+     *
+     * @return string
+     */
+    public function generate()
+    {
+        $this->setHeaderContentType();
+        $this->setHeader( 'Content-Transfer-Encoding', 'base64' );
+        $this->setHeaderContentDisposition();
+        return parent::generate();
     }
 }
 ?>

Modified: stable/Mail/1.2/src/tools.php
===================================================================
--- stable/Mail/1.2/src/tools.php       2007-02-27 15:30:03 UTC (rev 4691)
+++ stable/Mail/1.2/src/tools.php       2007-02-27 15:54:37 UTC (rev 4692)
@@ -274,16 +274,17 @@
      * Returns an unique ID to be used for Content-ID headers.
      *
      * The part $partName is default set to "part". Another value can be used 
to provide,
-     * for example, a file name of a part.
+     * for example, a file name of a part. $partName will be encoded with 
base64 to be
+     * compliant with the RFCs.
      *
-     * The formula used is [$partName]."@".[time].[counter]
+     * The formula used is [base64( $partName )]."@".[time].[counter]
      *
      * @param string $partName
      * @return string
      */
     public static function generateContentId( $partName = "part" )
     {
-        return $partName . '@' .  date( 'Hjs' ) . self::$idCounter++;
+        return str_replace( array( '=', '+', '/' ), '', base64_encode( 
$partName ) ) . '@' .  date( 'His' ) . self::$idCounter++;
     }
 
     /**

Modified: stable/Mail/1.2/tests/composer_test.php
===================================================================
--- stable/Mail/1.2/tests/composer_test.php     2007-02-27 15:30:03 UTC (rev 
4691)
+++ stable/Mail/1.2/tests/composer_test.php     2007-02-27 15:54:37 UTC (rev 
4692)
@@ -508,6 +508,21 @@
         $this->assertEquals( false, isset( $mail->no_such_property ) );
     }
 
+    public function testGeneratedContentIdBug()
+    {
+        $this->mail->from = new ezcMailAddress( '[EMAIL PROTECTED]', 'Frederik 
Holljen' );
+        $this->mail->addTo( new ezcMailAddress( '[EMAIL PROTECTED]', 'Frederik 
Holljen' ) );
+        $this->mail->subject = "HTML only..";
+        $this->mail->htmlText = "<html><i><b>HTML only. Should not have a 
multipart body.</b></i><img src=\"file://"
+                                   . dirname( __FILE__  )
+                                   . "/parts/data/fly.jpg\" /></html>";
+        $this->mail->build();
+
+        $parts = $this->mail->body->getRelatedParts();
+        $filePart = $parts[0];
+        $this->assertEquals( 0, strpos( $filePart->contentId, 'Zmx5LmpwZw@' . 
date( 'His' ) ) );
+    }
+
     public static function suite()
     {
          return new PHPUnit_Framework_TestSuite( "ezcMailComposerTest" );

Added: stable/Mail/1.2/tests/parser/data/various/default-disposition-header
===================================================================
--- stable/Mail/1.2/tests/parser/data/various/default-disposition-header        
2007-02-27 15:30:03 UTC (rev 4691)
+++ stable/Mail/1.2/tests/parser/data/various/default-disposition-header        
2007-02-27 15:54:37 UTC (rev 4692)
@@ -0,0 +1,57 @@
+From [EMAIL PROTECTED]  Fri Feb  9 20:52:57 2007
+Return-Path: <[EMAIL PROTECTED]>
+Received: (qmail 16514 invoked from network); 9 Feb 2007 20:50:01 -0000
+Received: from unknown (HELO TAG2WKS01) ([EMAIL PROTECTED]@86.136.147.243 with 
plain)
+  by smtp811.mail.ird.yahoo.com with SMTP; 9 Feb 2007 20:50:01 -0000
+X-YMail-OSG: 
y2.PldwVM1lFsdsyslNcnQOOQ5xB4ze6fnusXNNJbYqflsf6UVD4UtFigyLL2RtkMH2Ls4AWDIJXaWvBbn8hdIEGAFgU8tguDo4g763TSUzxLA--
+Reply-To: <[EMAIL PROTECTED]>
+From: <[EMAIL PROTECTED]>
+To: "'You'" <[EMAIL PROTECTED]>
+Subject: Test Message
+Date: Fri, 9 Feb 2007 20:49:56 -0000
+Message-ID: <!&!AAAACA5ZWllT5gwAAEAAA==>
+MIME-Version: 1.0
+Content-Type: multipart/related;
+    boundary="----=_NextPart_000_0167_01C74C8B.DC0AD110"
+X-Mailer: Microsoft Office Outlook 12.0
+Content-Language: en-gb
+
+This is a multipart message in MIME format.
+
+------=_NextPart_000_0167_01C74C8B.DC0AD110
+Content-Type: multipart/alternative;
+    boundary="----=_NextPart_001_0168_01C74C8B.DC0AD110"
+
+------=_NextPart_001_0168_01C74C8B.DC0AD110
+Content-Type: text/plain;
+    charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+
+Message text here
+
+------=_NextPart_001_0168_01C74C8B.DC0AD110
+Content-Type: text/html;
+    charset="us-ascii"
+Content-Transfer-Encoding: quoted-printable
+
+<html>
+<head>
+</head>
+
+<body>
+<p>Message text here</p>
+<img src="cid:image001.png@01C74C8B.D91E3870" alt="" />
+</body>
+</html>
+
+------=_NextPart_001_0168_01C74C8B.DC0AD110--
+
+------=_NextPart_000_0167_01C74C8B.DC0AD110
+Content-Type: image/png;
+    name="image001.png"
+Content-Transfer-Encoding: base64
+Content-ID: <[EMAIL PROTECTED]>
+
+--IMAGE DATA REMOVED--
+
+------=_NextPart_000_0167_01C74C8B.DC0AD110-- 

Modified: stable/Mail/1.2/tests/parser/parser_test.php
===================================================================
--- stable/Mail/1.2/tests/parser/parser_test.php        2007-02-27 15:30:03 UTC 
(rev 4691)
+++ stable/Mail/1.2/tests/parser/parser_test.php        2007-02-27 15:54:37 UTC 
(rev 4692)
@@ -920,5 +920,16 @@
         $mail = $mail[0];
         $this->assertEquals( '[EMAIL PROTECTED]', $mail->returnPath->email );
     }
+
+    public function testDefaultDispositionHeaderBug()
+    {
+        $parser = new ezcMailParser();
+        $set = new SingleFileSet( 'various/default-disposition-header' );
+        $mail = $parser->parseMail( $set );
+        $mail = $mail[0];
+        $parts = $mail->body->getRelatedParts();
+        $filePart = $parts[0];
+        $this->assertEquals( null, $filePart->contentDisposition );
+    }
 }
 ?>

Modified: stable/Mail/1.2/tests/parts/file_part_test.php
===================================================================
--- stable/Mail/1.2/tests/parts/file_part_test.php      2007-02-27 15:30:03 UTC 
(rev 4691)
+++ stable/Mail/1.2/tests/parts/file_part_test.php      2007-02-27 15:54:37 UTC 
(rev 4692)
@@ -22,6 +22,7 @@
     {
         $filePart = new ezcMailFile( dirname( __FILE__) . "/data/fly.jpg" );
         $filePart->contentType = ezcMailFile::CONTENT_TYPE_IMAGE;
+        $filePart->dispositionType = ezcMailFile::DISPLAY_ATTACHMENT;
         $filePart->mimeType = "jpeg";
         // file_put_contents( dirname( __FILE__ ) . 
"/data/ezcMailFileTest_testGenerateBase64.data" );
         $this->assertEquals( file_get_contents( dirname( __FILE__ ) . 
"/data/ezcMailFilePartTest_testGenerateBase64.data" ),
@@ -50,7 +51,7 @@
         $this->assertEquals( true, isset( $filePart->fileName ) );
         $this->assertEquals( true, isset( $filePart->mimeType ) );
         $this->assertEquals( true, isset( $filePart->contentType ) );
-        $this->assertEquals( true, isset( $filePart->dispositionType ) );
+        $this->assertEquals( false, isset( $filePart->dispositionType ) );
         $this->assertEquals( false, isset( $filePart->contentId ) );
         $this->assertEquals( false, isset( $filePart->no_such_property ) );
     }

Modified: stable/Mail/1.2/tests/parts/stream_file_part_test.php
===================================================================
--- stable/Mail/1.2/tests/parts/stream_file_part_test.php       2007-02-27 
15:30:03 UTC (rev 4691)
+++ stable/Mail/1.2/tests/parts/stream_file_part_test.php       2007-02-27 
15:54:37 UTC (rev 4692)
@@ -22,6 +22,7 @@
     {
         $filePart = new ezcMailStreamFile( "fly.jpg", fopen( dirname( 
__FILE__) . "/data/fly.jpg", "r" ) );
         $filePart->contentType = ezcMailFile::CONTENT_TYPE_IMAGE;
+        $filePart->dispositionType = ezcMailFile::DISPLAY_ATTACHMENT;
         $filePart->mimeType = "jpeg";
         // file_put_contents( dirname( __FILE__ ) . 
"/data/ezcMailFileTest_testGenerateBase64.data" );
         $this->assertEquals( file_get_contents( dirname( __FILE__ ) . 
"/data/ezcMailFilePartTest_testGenerateBase64.data" ),

Modified: stable/Mail/1.2/tests/parts/virtual_file_part_test.php
===================================================================
--- stable/Mail/1.2/tests/parts/virtual_file_part_test.php      2007-02-27 
15:30:03 UTC (rev 4691)
+++ stable/Mail/1.2/tests/parts/virtual_file_part_test.php      2007-02-27 
15:54:37 UTC (rev 4692)
@@ -22,6 +22,7 @@
     {
         $filePart = new ezcMailVirtualFile( "fly.jpg", file_get_contents( 
dirname( __FILE__) . "/data/fly.jpg" ) );
         $filePart->contentType = ezcMailFile::CONTENT_TYPE_IMAGE;
+        $filePart->dispositionType = ezcMailFile::DISPLAY_ATTACHMENT;
         $filePart->mimeType = "jpeg";
         // file_put_contents( dirname( __FILE__ ) . 
"/data/ezcMailFileTest_testGenerateBase64.data" );
         $this->assertEquals( file_get_contents( dirname( __FILE__ ) . 
"/data/ezcMailFilePartTest_testGenerateBase64.data" ),

-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to