Author: Alexandru Stanoi Date: 2007-01-23 11:02:29 +0100 (Tue, 23 Jan 2007) New Revision: 4545
Log: - Implemented feature request #9068: added support for filename language and filename charset support for the Content-Disposition header. Modified: trunk/Mail/ChangeLog trunk/Mail/src/composer.php trunk/Mail/src/interfaces/part.php trunk/Mail/src/parts/file.php trunk/Mail/src/structs/content_disposition_header.php trunk/Mail/tests/composer_test.php Modified: trunk/Mail/ChangeLog =================================================================== --- trunk/Mail/ChangeLog 2007-01-23 07:24:24 UTC (rev 4544) +++ trunk/Mail/ChangeLog 2007-01-23 10:02:29 UTC (rev 4545) @@ -8,9 +8,12 @@ - Added walkParts() to ezcMail and the class ezcMailPartWalkContext which can be used to walk through all the parts in a mail and execute a callback function on each part (for example save mail parts to disk or a database). -- Added support for multipart/report and message/delivery-status mail parts - (connected to issue #8694). +- Added support for multipart/report and message/delivery-status mail parts, + connected to issue #8694. +- Implemented feature request #9068: added support for filename language and + filename charset support for the Content-Disposition header. + 1.2.1 - [RELEASEDATE] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Modified: trunk/Mail/src/composer.php =================================================================== --- trunk/Mail/src/composer.php 2007-01-23 07:24:24 UTC (rev 4544) +++ trunk/Mail/src/composer.php 2007-01-23 10:02:29 UTC (rev 4545) @@ -162,6 +162,10 @@ * If $content is specified, $fileName is not checked if it exists. * $this->attachments will also contain in this case the $content, * $contentType and $mimeType. + * If $contentDisposition is specified, the attached file will have its + * Content-Disposition header set according to the $contentDisposition object + * and the filename of the attachment in the generated mail will be the one from + * the $contentDisposition object. * * @throws ezcBaseFileNotFoundException * if $fileName does not exists. @@ -171,14 +175,15 @@ * @param string $content * @param string $contentType * @param string $mimeType + * @param ezcMailContentDispositionHeader $contentDisposition */ - public function addAttachment( $fileName, $content = null, $contentType = null, $mimeType = null ) + public function addAttachment( $fileName, $content = null, $contentType = null, $mimeType = null, ezcMailContentDispositionHeader $contentDisposition = null ) { if ( is_null( $content ) ) { if ( is_readable( $fileName ) ) { - $this->attachments[] = array( $fileName, null, $contentType, $mimeType ); + $this->attachments[] = array( $fileName, null, $contentType, $mimeType, $contentDisposition ); } else { @@ -194,7 +199,7 @@ } else { - $this->attachments[] = array( $fileName, $content, $contentType, $mimeType ); + $this->attachments[] = array( $fileName, $content, $contentType, $mimeType, $contentDisposition ); } } @@ -252,6 +257,7 @@ { $mainPart = new ezcMailFile( $this->attachments[0][0], $this->attachments[0][2], $this->attachments[0][3] ); } + $mainPart->contentDisposition = $this->attachments[0][4]; } else if ( count( $this->attachments ) > 0 ) { @@ -266,17 +272,19 @@ { if ( is_resource( $attachment[1] ) ) { - $mainPart->appendPart( new ezcMailStreamFile( $attachment[0], $attachment[1], $attachment[2], $attachment[3] ) ); + $part = new ezcMailStreamFile( $attachment[0], $attachment[1], $attachment[2], $attachment[3] ); } else { - $mainPart->appendPart( new ezcMailVirtualFile( $attachment[0], $attachment[1], $attachment[2], $attachment[3] ) ); + $part = new ezcMailVirtualFile( $attachment[0], $attachment[1], $attachment[2], $attachment[3] ); } } else { - $mainPart->appendPart( new ezcMailFile( $attachment[0], $attachment[2], $attachment[3] ) ); + $part = new ezcMailFile( $attachment[0], $attachment[2], $attachment[3] ); } + $part->contentDisposition = $attachment[4]; + $mainPart->appendPart( $part ); } } Modified: trunk/Mail/src/interfaces/part.php =================================================================== --- trunk/Mail/src/interfaces/part.php 2007-01-23 07:24:24 UTC (rev 4544) +++ trunk/Mail/src/interfaces/part.php 2007-01-23 10:02:29 UTC (rev 4545) @@ -29,7 +29,6 @@ * headers of this part. Can be retreived for reasons of * extending this class and its derivals. * - * * @package Mail * @version //autogen// */ @@ -89,7 +88,6 @@ default: throw new ezcBasePropertyNotFoundException( $name ); } - } /** @@ -225,7 +223,23 @@ $cd = "{$cdHeader->disposition}"; if ( $cdHeader->fileName !== null ) { - $cd .= "; filename=\"{$cdHeader->fileName}\""; + $fileInfo = null; + if ( $cdHeader->fileNameCharSet !== null ) + { + $fileInfo .= "*0*=\"{$cdHeader->fileNameCharSet}"; + if ( $cdHeader->fileNameLanguage !== null ) + { + $fileInfo .= "'{$cdHeader->fileNameLanguage}'"; + } + } + if ( $fileInfo !== null ) + { + $cd .= "; filename{$fileInfo}{$cdHeader->fileName}\""; + } + else + { + $cd .= "; filename=\"{$cdHeader->fileName}\""; + } } if ( $cdHeader->creationDate !== null ) Modified: trunk/Mail/src/parts/file.php =================================================================== --- trunk/Mail/src/parts/file.php 2007-01-23 07:24:24 UTC (rev 4544) +++ trunk/Mail/src/parts/file.php 2007-01-23 10:02:29 UTC (rev 4545) @@ -197,9 +197,12 @@ } /** - * Sets the Content-Disposition header. + * Sets the Content-Disposition header based on the properties $dispositionType and $fileName. * - * Based on the properties $dispositionType and $fileName. + * Does not set the fileNameCharSet and fileNameLanguage properties of the + * Content-Disposition header. For this purpose set directly + * $this->contentDisposition with an object of class ezcMailContentDispositionHeader. + * */ private function setHeaderContentDisposition() { @@ -209,9 +212,6 @@ } $this->contentDisposition->disposition = $this->dispositionType; $this->contentDisposition->fileName = basename( $this->fileName ); - - // $this->setHeader( 'Content-Disposition', - // $this->dispositionType .'; ' . 'filename="' . basename( $this->fileName ) . '"' ); } } ?> Modified: trunk/Mail/src/structs/content_disposition_header.php =================================================================== --- trunk/Mail/src/structs/content_disposition_header.php 2007-01-23 07:24:24 UTC (rev 4544) +++ trunk/Mail/src/structs/content_disposition_header.php 2007-01-23 10:02:29 UTC (rev 4545) @@ -11,9 +11,10 @@ * A container to store a Content-Disposition header as described in http://www.faqs.org/rfcs/rfc2183. * * This container is used on the contentDisposition property on mail parts. - * It should primarily be used for reading. + * Use it for reading and setting the Content-Disposition header. * * @package Mail + * @version //autogentag// */ class ezcMailContentDispositionHeader extends ezcBaseStruct { Modified: trunk/Mail/tests/composer_test.php =================================================================== --- trunk/Mail/tests/composer_test.php 2007-01-23 07:24:24 UTC (rev 4544) +++ trunk/Mail/tests/composer_test.php 2007-01-23 10:02:29 UTC (rev 4545) @@ -8,7 +8,6 @@ * @subpackage Tests */ - /** * @package Mail * @subpackage Tests @@ -285,6 +284,7 @@ . "/parts/data/fly.jpg\">file.</a></html>"; $this->mail->addAttachment( dirname( __FILE__) . "/parts/data/fly.jpg" ); $this->mail->build(); + $this->removeTempDir(); // $transport = new ezcMailTransportSmtp( "smtp.ez.no" ); } @@ -498,7 +498,7 @@ $this->mail->addAttachment( "fly.jpg", $file ); $this->mail->build(); } - + public function testIsSet() { $mail = new ezcMailComposer(); @@ -508,6 +508,102 @@ $this->assertEquals( false, isset( $mail->no_such_property ) ); } + public function testContentDisposition() + { + $mail = new ezcMail(); + $mail->from = new ezcMailAddress( '[EMAIL PROTECTED]' ); + $mail->subject = "ÑвеÑаÑÑÄîţâÅåæøåöä"; + $mail->addTo( new ezcMailAddress( '[EMAIL PROTECTED]' ) ); + $file = new ezcMailFile( dirname( __FILE__) . "/parts/data/fly.jpg" ); + $file->contentDisposition = new ezcMailContentDispositionHeader( + 'attachment', + 'ÑвеÑаÑÑÄîţâÅåæøåöä.jpg', + null, + null, + null, + null, + array(), + 'no', + 'iso-8859-1' ); + $mail->body = new ezcMailMultipartMixed( + new ezcMailText( 'xxx' ), + $file ); + $msg = $mail->generate(); + $set = new ezcMailVariableSet( $msg ); + $parser = new ezcMailParser(); + $mail = $parser->parseMail( $set ); + $parts = $mail[0]->fetchParts(); + $this->assertEquals( $file->contentDisposition, $parts[1]->contentDisposition ); + } + + public function testContentDispositionSimple() + { + $mail = new ezcMail(); + $mail->from = new ezcMailAddress( '[EMAIL PROTECTED]' ); + $mail->subject = "ÑвеÑаÑÑÄîţâÅåæøåöä"; + $mail->addTo( new ezcMailAddress( '[EMAIL PROTECTED]' ) ); + $file = new ezcMailFile( dirname( __FILE__) . "/parts/data/fly.jpg" ); + $file->contentDisposition = new ezcMailContentDispositionHeader( + 'attachment', + 'ÑвеÑаÑÑÄîţâÅåæøåöä.jpg' ); + $mail->body = new ezcMailMultipartMixed( + new ezcMailText( 'xxx' ), + $file ); + $msg = $mail->generate(); + $set = new ezcMailVariableSet( $msg ); + $parser = new ezcMailParser(); + $mail = $parser->parseMail( $set ); + $parts = $mail[0]->fetchParts(); + $this->assertEquals( $file->contentDisposition, $parts[1]->contentDisposition ); + } + + public function testContentDispositionAttach() + { + $mail = new ezcMailComposer(); + $mail->from = new ezcMailAddress( '[EMAIL PROTECTED]' ); + $mail->subject = "ÑвеÑаÑÑÄîţâÅåæøåöä"; + $mail->addTo( new ezcMailAddress( '[EMAIL PROTECTED]' ) ); + $contentDisposition = new ezcMailContentDispositionHeader( + 'attachment', + 'ÑвеÑаÑÑÄîţâÅåæøåöä.jpg', + null, + null, + null, + null, + array(), + 'no', + 'iso-8859-1' ); + $mail->plainText = 'xxx'; + $mail->addAttachment( dirname( __FILE__) . "/parts/data/fly.jpg", null, null, null, $contentDisposition ); + $mail->build(); + $msg = $mail->generate(); + $set = new ezcMailVariableSet( $msg ); + $parser = new ezcMailParser(); + $mail = $parser->parseMail( $set ); + $parts = $mail[0]->fetchParts(); + $this->assertEquals( $contentDisposition, $parts[1]->contentDisposition ); + } + + public function testContentDispositionSimpleAttach() + { + $mail = new ezcMailComposer(); + $mail->from = new ezcMailAddress( '[EMAIL PROTECTED]' ); + $mail->subject = "ÑвеÑаÑÑÄîţâÅåæøåöä"; + $mail->addTo( new ezcMailAddress( '[EMAIL PROTECTED]' ) ); + $contentDisposition = new ezcMailContentDispositionHeader( + 'attachment', + 'ÑвеÑаÑÑÄîţâÅåæøåöä.jpg' ); + $mail->plainText = 'xxx'; + $mail->addAttachment( dirname( __FILE__) . "/parts/data/fly.jpg", null, null, null, $contentDisposition ); + $mail->build(); + $msg = $mail->generate(); + $set = new ezcMailVariableSet( $msg ); + $parser = new ezcMailParser(); + $mail = $parser->parseMail( $set ); + $parts = $mail[0]->fetchParts(); + $this->assertEquals( $contentDisposition, $parts[1]->contentDisposition ); + } + public static function suite() { return new PHPUnit_Framework_TestSuite( "ezcMailComposerTest" ); -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components