Author: Alexandru Stanoi Date: 2007-02-19 17:43:10 +0100 (Mon, 19 Feb 2007) New Revision: 4669
Log: - Fixed issue #10283: ImapSet does not return the trailing parenthesis ')'. Modified: trunk/Mail/ChangeLog trunk/Mail/src/parser/parser.php trunk/Mail/src/transports/imap/imap_set.php trunk/Mail/tests/transports/transport_imap_test.php Modified: trunk/Mail/ChangeLog =================================================================== --- trunk/Mail/ChangeLog 2007-02-19 16:33:02 UTC (rev 4668) +++ trunk/Mail/ChangeLog 2007-02-19 16:43:10 UTC (rev 4669) @@ -36,6 +36,7 @@ attachments. - Fixed bug #010138: Doc of ezcMailMultipartDigest->__construct() incorrect (The documentation was correct, the implementation was wrong.) +- Fixed issue #10283: ImapSet does not return the trailing parenthesis ')'. 1.2 - Monday 18 December 2006 Modified: trunk/Mail/src/parser/parser.php =================================================================== --- trunk/Mail/src/parser/parser.php 2007-02-19 16:33:02 UTC (rev 4668) +++ trunk/Mail/src/parser/parser.php 2007-02-19 16:43:10 UTC (rev 4669) @@ -172,21 +172,14 @@ { $this->partParser = new ezcMailRfc822Parser(); $data = ""; - $lastData = ""; $size = 0; while ( ( $data = $set->getNextLine() ) !== null ) { $this->partParser->parseBody( $data ); $size += strlen( $data ); - $lastData = $data; } $part = $this->partParser->finish( $class ); $part->size = $size; - if ( trim( $lastData ) === ')' ) - { - // IMAP: don't consider the last line: ) CR LF - $part->size = $part->size - 3; - } $mail[] = $part; } while ( $set->nextMail() ); return $mail; Modified: trunk/Mail/src/transports/imap/imap_set.php =================================================================== --- trunk/Mail/src/transports/imap/imap_set.php 2007-02-19 16:33:02 UTC (rev 4668) +++ trunk/Mail/src/transports/imap/imap_set.php 2007-02-19 16:43:10 UTC (rev 4669) @@ -41,6 +41,13 @@ private $currentMessage = null; /** + * Holds the line that will be read-ahead in order to determine the trailing paranthesis. + * + * @var string + */ + private $nextData = null; + + /** * This variable is true if there is more data in the mail that is being fetched. * * It is false if there is no mail being fetched currently or if all the data of the current mail @@ -76,7 +83,7 @@ * @throws ezcMailTransportException * if the server send a negative response. * @param ezcMailTransportConnection $connection - * @param array(ezcMail) $messages + * @param array(int) $messages * @param bool $deleteFromServer */ public function __construct( ezcMailTransportConnection $connection, array $messages, $deleteFromServer = false ) @@ -84,7 +91,7 @@ $this->connection = $connection; $this->messages = $messages; $this->deleteFromServer = $deleteFromServer; - $this->nextMail(); + $this->nextData = null; } /** @@ -107,21 +114,32 @@ */ public function getNextLine() { + if ( $this->currentMessage === null ) + { + // Instead of calling $this->nextMail() in the constructor, it is called + // here, to avoid sending commands to the server when creating the set, and + // instead send the server commands when parsing the set (see ezcMailParser). + $this->nextMail(); + } if ( $this->hasMoreMailData ) { - $data = $this->connection->getLine(); - if ( strpos( $data, $this->currentTag ) !== false && strpos( $data, $this->currentTag ) == 0 ) + $data = ( $this->nextData === null ) ? $this->connection->getLine() : $this->nextData; + if ( strpos( $data, $this->currentTag ) === false ) { - $this->hasMoreMailData = false; - // remove the mail if required by the user. - if ( $this->deleteFromServer === true ) + $this->nextData = $this->connection->getLine(); + if ( trim( $data ) === ')' && strpos( $this->nextData, $this->currentTag ) === 0 ) { - $tag = $this->getNextTag(); - $this->connection->sendData( "{$tag} STORE {$this->currentMessage} +FLAGS (\\Deleted)" ); - // skip OK response ("{$tag} OK Store completed.") - $response = $this->getResponse( $tag ); + $this->hasMoreMailData = false; + // remove the mail if required by the user. + if ( $this->deleteFromServer === true ) + { + $tag = $this->getNextTag(); + $this->connection->sendData( "{$tag} STORE {$this->currentMessage} +FLAGS (\\Deleted)" ); + // skip OK response ("{$tag} OK Store completed.") + $response = $this->getResponse( $tag ); + } + return null; } - return null; } return $data; } @@ -147,6 +165,7 @@ { $this->currentMessage = next( $this->messages ); } + $this->nextData = null; if ( $this->currentMessage !== false ) { $tag = $this->getNextTag(); Modified: trunk/Mail/tests/transports/transport_imap_test.php =================================================================== --- trunk/Mail/tests/transports/transport_imap_test.php 2007-02-19 16:33:02 UTC (rev 4668) +++ trunk/Mail/tests/transports/transport_imap_test.php 2007-02-19 16:43:10 UTC (rev 4669) @@ -1263,6 +1263,11 @@ $imap->delete( 1 ); $imap->expunge(); $this->assertEquals( 3, $imap->countByFlag( "ALL" ) ); + $set = $imap->fetchByMessageNr( 2, true ); + $parser = new ezcMailParser(); + $mail = $parser->parseMail( $set ); + $imap->expunge(); + $this->assertEquals( 2, $imap->countByFlag( "ALL" ) ); $imap->selectMailbox( "Inbox" ); $imap->deleteMailbox( "Guybrush" ); } @@ -1370,7 +1375,7 @@ $this->assertEquals( false, isset( $connection->no_such_property ) ); $options = $connection->options; - $connection->options = new ezcMailTransportOptions(); + $connection->options = new ezcMailImapTransportOptions(); $this->assertEquals( $options, $connection->options ); try @@ -1437,6 +1442,18 @@ } } + public function testFixTrailingParanthesis() + { + $transport = new ezcMailImapTransport( "dolly.ez.no" ); + $transport->authenticate( "ezcomponents", "ezcomponents" ); + $transport->selectMailbox( "Inbox" ); + $parser = new ezcMailParser(); + + $set = $transport->fetchByMessageNr( 3 ); + $mail = $parser->parseMail( $set ); + $this->assertNotEquals( ')', substr( $mail[0]->body->text, strlen( $mail[0]->body->text ) - 3, 3 ) ); + } + public static function suite() { self::$ids = array( 15, 16, 17, 18 ); -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components