Author: as
Date: Thu Oct 11 11:18:34 2007
New Revision: 6418

Log:
- Fixed issue #11582: ezcMailImapSet won't be caught in an infinite loop if
  the mail headers or body contain an IMAP tag.

Modified:
    trunk/Mail/ChangeLog
    trunk/Mail/src/transports/imap/imap_set.php
    trunk/Mail/tests/transports/transport_imap_test.php

Modified: trunk/Mail/ChangeLog
==============================================================================
--- trunk/Mail/ChangeLog [iso-8859-1] (original)
+++ trunk/Mail/ChangeLog [iso-8859-1] Thu Oct 11 11:18:34 2007
@@ -1,3 +1,10 @@
+1.4alpha2 - [RELEASEDATE]
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Fixed issue #11582: ezcMailImapSet won't be caught in an infinite loop if
+  the mail headers or body contain an IMAP tag.
+
+
 1.4alpha1 - Tuesday 18 September 2007
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 

Modified: trunk/Mail/src/transports/imap/imap_set.php
==============================================================================
--- trunk/Mail/src/transports/imap/imap_set.php [iso-8859-1] (original)
+++ trunk/Mail/src/transports/imap/imap_set.php [iso-8859-1] Thu Oct 11 
11:18:34 2007
@@ -84,6 +84,22 @@
     private $options;
 
     /**
+     * Holds the number of bytes to read from the IMAP server.
+     *
+     * It is set before starting to read a message from the information
+     * returned by the IMAP server in this form:
+     *
+     * <code>
+     * * 2 FETCH (FLAGS (\Answered \Seen) RFC822 {377}
+     * </code>
+     *
+     * In this example, $this->bytesToRead will be set to 377.
+     *
+     * @var int
+     */
+    private $bytesToRead = false;
+
+    /**
      * Constructs a new IMAP parser set that will fetch the messages $messages.
      *
      * $connection must hold a valid connection to a IMAP server that is ready
@@ -138,9 +154,10 @@
         if ( $this->hasMoreMailData )
         {
             $data = ( $this->nextData === null ) ? 
$this->connection->getLine() : $this->nextData;
-            if ( strpos( $data, $this->currentTag ) === false )
+            if ( $this->bytesToRead !== false && $this->bytesToRead >= 0 )
             {
                 $this->nextData = $this->connection->getLine();
+                $this->bytesToRead -= strlen( $this->nextData );
                 // the next code checks if the current line ends with ')'
                 // and the next line has the command tag (e.g. 'A0034').
                 if ( substr( trim( $data ), strlen( trim( $data ) ) - 1 ) === 
')' && strpos( $this->nextData, $this->currentTag ) === 0 )
@@ -182,6 +199,7 @@
             $this->currentMessage = next( $this->messages );
         }
         $this->nextData = null;
+        $this->bytesToRead = false;
         if ( $this->currentMessage !== false )
         {
             $tag = $this->getNextTag();
@@ -198,6 +216,14 @@
                 if ( strpos( $response, 'FETCH (' ) !== false )
                 {
                     $this->hasMoreMailData = true;
+                    // retrieve the message size from $response, eg. if 
$response is:
+                    // * 2 FETCH (FLAGS (\Answered \Seen) RFC822 {377}
+                    // then $this->bytesToRead will be 377
+                    preg_match( '/\{(.*)\}/', $response, $matches );
+                    if ( count( $matches ) > 0 )
+                    {
+                        $this->bytesToRead = (int) $matches[1];
+                    }
                     return true;
                 }
                 else

Modified: trunk/Mail/tests/transports/transport_imap_test.php
==============================================================================
--- trunk/Mail/tests/transports/transport_imap_test.php [iso-8859-1] (original)
+++ trunk/Mail/tests/transports/transport_imap_test.php [iso-8859-1] Thu Oct 11 
11:18:34 2007
@@ -2135,6 +2135,36 @@
         }
     }
 
+    public function testTagInHeadersAndBody()
+    {
+        $imap = new ezcMailImapTransport( self::$server, self::$port );
+        $imap->authenticate( self::$user, self::$password );
+
+        $imap->createMailbox( "Guybrush" );
+
+        $mail = new ezcMail();
+        $mail->from = new ezcMailAddress( '[EMAIL PROTECTED]', 'From' );
+        $mail->addTo( new ezcMailAddress( '[EMAIL PROTECTED]', 'To' ) );
+        $mail->subject = "A0000 A0001 A0002 A0003 A0004 A0005 A0006 A0007";
+        $mail->body = new ezcMailText( 
"A0000\nA0001\nA0002\nA0003\nA0004\nA0005\nA0006\nA0007" );
+        $data = $mail->generate();
+
+        $imap->append( "Guybrush", $data );
+        $imap->append( "Guybrush", $data, array( 'Answered' ) );
+
+        $imap->selectMailbox( "Guybrush" );
+
+        $set = $imap->fetchAll();
+        $parser = new ezcMailParser();
+        $mail = $parser->parseMail( $set );
+        $mail = $mail[0];
+
+        $imap->selectMailbox( "Inbox" );
+        $imap->deleteMailbox( "Guybrush" );
+
+        $this->assertEquals( 'A0000 A0001 A0002 A0003 A0004 A0005 A0006 
A0007', $mail->subject );
+    }
+
     public function testTransportOptions()
     {
         $options = new ezcMailImapTransportOptions();


-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to