Author: Alexandru Stanoi
Date: 2007-01-25 14:24:32 +0100 (Thu, 25 Jan 2007)
New Revision: 4576

Log:
- Added get/set/isset methods for the options property.

Modified:
   trunk/Mail/src/parser/parser.php
   trunk/Mail/src/transports/imap/imap_transport.php
   trunk/Mail/src/transports/pop3/pop3_transport.php
   trunk/Mail/src/transports/smtp/transport_smtp.php
   trunk/Mail/src/transports/transport_connection.php
   trunk/Mail/tests/transports/transport_imap_test.php
   trunk/Mail/tests/transports/transport_pop3_test.php
   trunk/Mail/tests/transports/transport_smtp_test.php

Modified: trunk/Mail/src/parser/parser.php
===================================================================
--- trunk/Mail/src/parser/parser.php    2007-01-25 13:16:39 UTC (rev 4575)
+++ trunk/Mail/src/parser/parser.php    2007-01-25 13:24:32 UTC (rev 4576)
@@ -66,47 +66,48 @@
     }
 
     /**
-     * Returns the value of the property $name.
+     * Sets the property $name to $value.
      *
      * @throws ezcBasePropertyNotFoundException
      *         if the property $name does not exist
+     * @throws ezcBaseValueException
+     *         if $value is not accepted for the property $name
      * @param string $name
+     * @param mixed $value
      * @ignore
      */
-    public function __get( $name )
+    public function __set( $name, $value )
     {
         switch ( $name )
         {
             case 'options':
-                return $this->options;
+                if ( !( $value instanceof ezcMailParserOptions ) )
+                {
+                    throw new ezcBaseValueException( 'options', $value, 
'instanceof ezcMailParserOptions' );
+                }
+                $this->options = $value;
                 break;
+
+            default:
+                throw new ezcBasePropertyNotFoundException( $name );
         }
-        throw new ezcBasePropertyNotFoundException( $name );
     }
 
     /**
-     * Sets the property $name to $value.
+     * Returns the value of the property $name.
      *
      * @throws ezcBasePropertyNotFoundException
      *         if the property $name does not exist
-     * @throws ezcBaseValueException
-     *         if $value is not accepted for the property $name
      * @param string $name
-     * @param mixed $value
      * @ignore
      */
-    public function __set( $name, $value )
+    public function __get( $name )
     {
         switch ( $name )
         {
             case 'options':
-                if ( !( $value instanceof ezcMailParserOptions ) )
-                {
-                    throw new ezcBaseValueException( 'options', $value, 
'instanceof ezcMailParserOptions' );
-                }
-                $this->options = $value;
-                break;
-
+                return $this->options;
+            
             default:
                 throw new ezcBasePropertyNotFoundException( $name );
         }
@@ -121,11 +122,14 @@
      */
     public function __isset( $name )
     {
-        if ( $name === "options" )
+        switch ( $name )
         {
-            return true;
+            case 'options':
+                return true;
+
+            default:
+                return false;
         }
-        return false;
     }
 
     /**

Modified: trunk/Mail/src/transports/imap/imap_transport.php
===================================================================
--- trunk/Mail/src/transports/imap/imap_transport.php   2007-01-25 13:16:39 UTC 
(rev 4575)
+++ trunk/Mail/src/transports/imap/imap_transport.php   2007-01-25 13:24:32 UTC 
(rev 4576)
@@ -21,6 +21,9 @@
  * @todo listUniqueIdentifiers(): add UIVALIDITY value to UID (like in POP3).
  *       (if necessary).
  *
+ * @property ezcMailImapTransportOptions $options
+ *           Holds the options you can set to the IMAP transport.
+ *
  * @package Mail
  * @version //autogen//
  * @mainclass
@@ -29,62 +32,84 @@
 {
     /**
      * Internal state when the IMAP transport is not connected to a server.
+     *
+     * @access private
      */
     const STATE_NOT_CONNECTED = 1;
 
     /**
      * Internal state when the IMAP transport is connected to a server,
      * but no successful authentication has been performed.
+     *
+     * @access private
      */
     const STATE_NOT_AUTHENTICATED = 2;
 
     /**
      * Internal state when the IMAP transport is connected to a server
      * and authenticated, but no mailbox is selected yet.
+     *
+     * @access private
      */
     const STATE_AUTHENTICATED = 3;
 
     /**
      * Internal state when the IMAP transport is connected to a server,
      * authenticated, and a mailbox is selected.
+     *
+     * @access private
      */
     const STATE_SELECTED = 4;
 
     /**
      * Internal state when the IMAP transport is connected to a server,
      * authenticated, and a mailbox is selected read only.
+     *
+     * @access private
      */
     const STATE_SELECTED_READONLY = 5;
 
     /**
      * Internal state when the LOGOUT command has been issued to the IMAP
      * server, but before the disconnect has taken place.
+     *
+     * @access private
      */
     const STATE_LOGOUT = 6;
 
     /**
      * The response sent from the IMAP server is "OK".
+     *
+     * @access private
      */
     const RESPONSE_OK = 1;
 
     /**
      * The response sent from the IMAP server is "NO".
+     *
+     * @access private
      */
     const RESPONSE_NO = 2;
 
     /**
      * The response sent from the IMAP server is "BAD".
+     *
+     * @access private
      */
     const RESPONSE_BAD = 3;
 
     /**
      * The response sent from the IMAP server is untagged (starts with "*").
+     *
+     * @access private
      */
     const RESPONSE_UNTAGGED = 4;
 
     /**
      * The response sent from the IMAP server requires the client to send
      * information (starts with "+").
+     *
+     * @access private
      */
     const RESPONSE_FEEDBACK = 5;
 
@@ -96,7 +121,7 @@
      *     FLAGGED    Message is "flagged" for urgent/special attention
      *     SEEN       Message has been read
      *
-     * @var array(int=>string)
+     * @var array(string)
      */
     private static $basicFlags = array( 'ANSWERED', 'DELETED', 'DRAFT', 
'FLAGGED', 'SEEN' );
 
@@ -113,7 +138,7 @@
      *     NEW        Equivalent to RECENT + UNSEEN
      *     ALL        All the messages
      *
-     * @var array(int=>string)
+     * @var array(string)
      */
     private static $extendedFlags = array( 'ALL', 'ANSWERED', 'DELETED', 
'DRAFT', 'FLAGGED', 'NEW', 'OLD', 'RECENT', 'SEEN', 'UNANSWERED', 'UNDELETED', 
'UNDRAFT', 'UNFLAGGED', 'UNRECENT', 'UNSEEN' );
 
@@ -197,6 +222,73 @@
     }
 
     /**
+     * Sets the property $name to $value.
+     *
+     * @throws ezcBasePropertyNotFoundException
+     *         if the property $name does not exist
+     * @throws ezcBaseValueException
+     *         if $value is not accepted for the property $name
+     * @param string $name
+     * @param mixed $value
+     * @ignore
+     */
+    public function __set( $name, $value )
+    {
+        switch ( $name )
+        {
+            case 'options':
+                if ( !( $value instanceof ezcMailImapTransportOptions ) )
+                {
+                    throw new ezcBaseValueException( 'options', $value, 
'instanceof ezcMailImapTransportOptions' );
+                }
+                $this->options = $value;
+                break;
+
+            default:
+                throw new ezcBasePropertyNotFoundException( $name );
+        }
+    }
+
+    /**
+     * Returns the value of the property $name.
+     *
+     * @throws ezcBasePropertyNotFoundException
+     *         if the property $name does not exist
+     * @param string $name
+     * @ignore
+     */
+    public function __get( $name )
+    {
+        switch ( $name )
+        {
+            case 'options':
+                return $this->options;
+            
+            default:
+                throw new ezcBasePropertyNotFoundException( $name );
+        }
+    }
+
+    /**
+     * Returns true if the property $name is set, otherwise false.
+     *
+     * @param string $name
+     * @return bool
+     * @ignore
+     */
+    public function __isset( $name )
+    {
+        switch ( $name )
+        {
+            case 'options':
+                return true;
+
+            default:
+                return false;
+        }
+    }
+
+    /**
      * Disconnects the transport from the IMAP server.
      */
     public function disconnect()

Modified: trunk/Mail/src/transports/pop3/pop3_transport.php
===================================================================
--- trunk/Mail/src/transports/pop3/pop3_transport.php   2007-01-25 13:16:39 UTC 
(rev 4575)
+++ trunk/Mail/src/transports/pop3/pop3_transport.php   2007-01-25 13:24:32 UTC 
(rev 4576)
@@ -22,6 +22,9 @@
  * @todo // add support for SSL?
  * @todo // support for signing?
  *
+ * @property ezcMailPop3TransportOptions $options
+ *           Holds the options you can set to the POP3 transport.
+ *
  * @package Mail
  * @version //autogen//
  * @mainclass
@@ -30,24 +33,32 @@
 {
     /**
      * Internal state set when the POP3 transport is not connected to a server.
+     *
+     * @access private
      */
     const STATE_NOT_CONNECTED = 1;
 
     /**
      * Internal state set when the POP3 transport is connected to the server
      * but no successful authentication has been performed.
+     *
+     * @access private
      */
     const STATE_AUTHORIZATION = 2;
 
     /**
      * Internal state set when the POP3 transport is connected to the server
      * and authenticated.
+     *
+     * @access private
      */
     const STATE_TRANSACTION = 3;
 
     /**
      * Internal state set when the QUIT command has been issued to the POP3 
server
      * but before the disconnect has taken place.
+     *
+     * @access private
      */
     const STATE_UPDATE = 4;
 
@@ -134,6 +145,73 @@
     }
 
     /**
+     * Sets the property $name to $value.
+     *
+     * @throws ezcBasePropertyNotFoundException
+     *         if the property $name does not exist
+     * @throws ezcBaseValueException
+     *         if $value is not accepted for the property $name
+     * @param string $name
+     * @param mixed $value
+     * @ignore
+     */
+    public function __set( $name, $value )
+    {
+        switch ( $name )
+        {
+            case 'options':
+                if ( !( $value instanceof ezcMailPop3TransportOptions ) )
+                {
+                    throw new ezcBaseValueException( 'options', $value, 
'instanceof ezcMailPop3TransportOptions' );
+                }
+                $this->options = $value;
+                break;
+
+            default:
+                throw new ezcBasePropertyNotFoundException( $name );
+        }
+    }
+
+    /**
+     * Returns the value of the property $name.
+     *
+     * @throws ezcBasePropertyNotFoundException
+     *         if the property $name does not exist
+     * @param string $name
+     * @ignore
+     */
+    public function __get( $name )
+    {
+        switch ( $name )
+        {
+            case 'options':
+                return $this->options;
+            
+            default:
+                throw new ezcBasePropertyNotFoundException( $name );
+        }
+    }
+
+    /**
+     * Returns true if the property $name is set, otherwise false.
+     *
+     * @param string $name
+     * @return bool
+     * @ignore
+     */
+    public function __isset( $name )
+    {
+        switch ( $name )
+        {
+            case 'options':
+                return true;
+
+            default:
+                return false;
+        }
+    }
+
+    /**
      * Disconnects the transport from the POP3 server.
      */
     public function disconnect()

Modified: trunk/Mail/src/transports/smtp/transport_smtp.php
===================================================================
--- trunk/Mail/src/transports/smtp/transport_smtp.php   2007-01-25 13:16:39 UTC 
(rev 4575)
+++ trunk/Mail/src/transports/smtp/transport_smtp.php   2007-01-25 13:24:32 UTC 
(rev 4576)
@@ -12,7 +12,7 @@
  * This class implements the Simple Mail Transfer Protocol (SMTP)
  * with authentication support.
  *
- * See for further information the RFC's:
+ * See for further information the RFCs:
  * - [EMAIL PROTECTED] http://www.faqs.org/rfcs/rfc821.html}
  * - [EMAIL PROTECTED] http://www.faqs.org/rfcs/rfc2554.html}
  *
@@ -31,6 +31,8 @@
  * @property string $senderHost
  *           The hostname of the computer that sends the mail. The default is
  *           'localhost'.
+ * @property ezcMailSmtpTransportOptions $options
+ *           Holds the options you can set to the SMTP transport.
  *
  * @package Mail
  * @version //autogen//
@@ -45,18 +47,21 @@
 
     /**
      * We are not connected to a server.
+     *
      * @access private
      */
     const STATUS_NOT_CONNECTED = 1;
 
     /**
      * We are connected to the server, but not authenticated.
+     *
      * @access private
      */
     const STATUS_CONNECTED = 2;
 
     /**
      * We are connected to the server and authenticated.
+     *
      * @access private
      */
     const STATUS_AUTHENTICATED = 3;
@@ -163,7 +168,9 @@
      * Sets the property $name to $value.
      *
      * @throws ezcBasePropertyNotFoundException
-     *         if the property does not exist.
+     *         if the property $name does not exist
+     * @throws ezcBaseValueException
+     *         if $value is not accepted for the property $name
      * @param string $name
      * @param mixed $value
      * @ignore
@@ -181,16 +188,24 @@
                 $this->properties[$name] = $value;
                 break;
 
+            case 'options':
+                if ( !( $value instanceof ezcMailSmtpTransportOptions ) )
+                {
+                    throw new ezcBaseValueException( 'options', $value, 
'instanceof ezcMailSmtpTransportOptions' );
+                }
+                $this->options = $value;
+                break;
+
             default:
                 throw new ezcBasePropertyNotFoundException( $name );
         }
     }
 
     /**
-     * Returns the property $name.
+     * Returns the value of the property $name.
      *
      * @throws ezcBasePropertyNotFoundException
-     *         if the property does not exist.
+     *         if the property $name does not exist
      * @param string $name
      * @return mixed
      * @ignore
@@ -207,6 +222,9 @@
             case 'timeout':
                 return $this->properties[$name];
 
+            case 'options':
+                return $this->options;
+
             default:
                 throw new ezcBasePropertyNotFoundException( $name );
         }
@@ -231,6 +249,9 @@
             case 'timeout':
                 return isset( $this->properties[$name] );
 
+            case 'options':
+                return true;
+
             default:
                 return false;
         }

Modified: trunk/Mail/src/transports/transport_connection.php
===================================================================
--- trunk/Mail/src/transports/transport_connection.php  2007-01-25 13:16:39 UTC 
(rev 4575)
+++ trunk/Mail/src/transports/transport_connection.php  2007-01-25 13:24:32 UTC 
(rev 4576)
@@ -13,6 +13,9 @@
  * ezcMailTransportConnection is an internal class used to connect to
  * a server and have line based communication with.
  *
+ * @property ezcMailTransportOptions $options
+ *           Holds the options you can set to the transport connection.
+ *
  * @package Mail
  * @version //autogen//
  * @access private
@@ -72,6 +75,73 @@
     }
 
     /**
+     * Sets the property $name to $value.
+     *
+     * @throws ezcBasePropertyNotFoundException
+     *         if the property $name does not exist
+     * @throws ezcBaseValueException
+     *         if $value is not accepted for the property $name
+     * @param string $name
+     * @param mixed $value
+     * @ignore
+     */
+    public function __set( $name, $value )
+    {
+        switch ( $name )
+        {
+            case 'options':
+                if ( !( $value instanceof ezcMailTransportOptions ) )
+                {
+                    throw new ezcBaseValueException( 'options', $value, 
'instanceof ezcMailTransportOptions' );
+                }
+                $this->options = $value;
+                break;
+
+            default:
+                throw new ezcBasePropertyNotFoundException( $name );
+        }
+    }
+
+    /**
+     * Returns the value of the property $name.
+     *
+     * @throws ezcBasePropertyNotFoundException
+     *         if the property $name does not exist
+     * @param string $name
+     * @ignore
+     */
+    public function __get( $name )
+    {
+        switch ( $name )
+        {
+            case 'options':
+                return $this->options;
+
+            default:
+                throw new ezcBasePropertyNotFoundException( $name );
+        }
+    }
+
+    /**
+     * Returns true if the property $name is set, otherwise false.
+     *
+     * @param string $name
+     * @return bool
+     * @ignore
+     */
+    public function __isset( $name )
+    {
+        switch ( $name )
+        {
+            case 'options':
+                return true;
+
+            default:
+                return false;
+        }
+    }
+
+    /**
      * Send $data to the server through the connection.
      *
      * This method appends one line-break at the end of $data.

Modified: trunk/Mail/tests/transports/transport_imap_test.php
===================================================================
--- trunk/Mail/tests/transports/transport_imap_test.php 2007-01-25 13:16:39 UTC 
(rev 4575)
+++ trunk/Mail/tests/transports/transport_imap_test.php 2007-01-25 13:24:32 UTC 
(rev 4576)
@@ -1319,6 +1319,91 @@
         $this->assertEquals( '45177', $parts[1]->size );
     }
 
+    public function testTransportProperties()
+    {
+        $imap = new ezcMailImapTransport( "dolly.ez.no" );
+        $this->assertEquals( true, isset( $imap->options ) );
+        $this->assertEquals( false, isset( $imap->no_such_property ) );
+
+        $options = $imap->options;
+        $imap->options = new ezcMailImapTransportOptions();
+        $this->assertEquals( $options, $imap->options );
+
+        try
+        {
+            $imap->options = 'xxx';
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            $this->assertEquals( "The value 'xxx' that you were trying to 
assign to setting 'options' is invalid. Allowed values are: instanceof 
ezcMailImapTransportOptions.", $e->getMessage() );
+        }
+
+        try
+        {
+            $imap->no_such_property = 'xxx';
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {
+            $this->assertEquals( "No such property name 'no_such_property'.", 
$e->getMessage() );
+        }
+
+        try
+        {
+            $value = $imap->no_such_property;
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {
+            $this->assertEquals( "No such property name 'no_such_property'.", 
$e->getMessage() );
+        }
+    }
+
+    public function testTransportConnectionProperties()
+    {
+        $imap = new ezcMailImapTransport( "dolly.ez.no" );
+
+        // hack to get the connection property as it is private
+        $connection = $this->getAttribute( $imap, 'connection' );
+        $this->assertEquals( true, isset( $connection->options ) );
+        $this->assertEquals( false, isset( $connection->no_such_property ) );
+
+        $options = $connection->options;
+        $connection->options = new ezcMailTransportOptions();
+        $this->assertEquals( $options, $connection->options );
+
+        try
+        {
+            $connection->options = 'xxx';
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            $this->assertEquals( "The value 'xxx' that you were trying to 
assign to setting 'options' is invalid. Allowed values are: instanceof 
ezcMailTransportOptions.", $e->getMessage() );
+        }
+
+        try
+        {
+            $connection->no_such_property = 'xxx';
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {
+            $this->assertEquals( "No such property name 'no_such_property'.", 
$e->getMessage() );
+        }
+
+        try
+        {
+            $value = $connection->no_such_property;
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {
+            $this->assertEquals( "No such property name 'no_such_property'.", 
$e->getMessage() );
+        }
+    }
+
     public static function suite()
     {
         self::$ids = array( 15, 16, 17, 18 );

Modified: trunk/Mail/tests/transports/transport_pop3_test.php
===================================================================
--- trunk/Mail/tests/transports/transport_pop3_test.php 2007-01-25 13:16:39 UTC 
(rev 4575)
+++ trunk/Mail/tests/transports/transport_pop3_test.php 2007-01-25 13:24:32 UTC 
(rev 4576)
@@ -400,9 +400,51 @@
         $this->assertEquals( '45177', $parts[1]->size );
     }
 
+    public function testTransportProperties()
+    {
+        $pop3 = new ezcMailPop3Transport( "dolly.ez.no" );
+        $this->assertEquals( true, isset( $pop3->options ) );
+        $this->assertEquals( false, isset( $pop3->no_such_property ) );
+
+        $options = $pop3->options;
+        $pop3->options = new ezcMailPop3TransportOptions();
+        $this->assertEquals( $options, $pop3->options );
+        $this->assertEquals( ezcMailPop3Transport::AUTH_PLAIN_TEXT, 
$pop3->options->authenticationMethod );
+        $this->assertEquals( 5, $pop3->options->timeout );
+
+        try
+        {
+            $pop3->options = 'xxx';
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            $this->assertEquals( "The value 'xxx' that you were trying to 
assign to setting 'options' is invalid. Allowed values are: instanceof 
ezcMailPop3TransportOptions.", $e->getMessage() );
+        }
+
+        try
+        {
+            $pop3->no_such_property = 'xxx';
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {
+            $this->assertEquals( "No such property name 'no_such_property'.", 
$e->getMessage() );
+        }
+
+        try
+        {
+            $value = $pop3->no_such_property;
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {
+            $this->assertEquals( "No such property name 'no_such_property'.", 
$e->getMessage() );
+        }
+    }
+
     public static function suite()
     {
-        // small hack because the message IDs keep increasing everyday by 4 on 
the server
         self::$ids = array( '0000000f4420e93a', '000000104420e93a', 
'000000114420e93a', '000000124420e93a' );
         return new PHPUnit_Framework_TestSuite( "ezcMailTransportPop3Test" );
     }

Modified: trunk/Mail/tests/transports/transport_smtp_test.php
===================================================================
--- trunk/Mail/tests/transports/transport_smtp_test.php 2007-01-25 13:16:39 UTC 
(rev 4575)
+++ trunk/Mail/tests/transports/transport_smtp_test.php 2007-01-25 13:24:32 UTC 
(rev 4576)
@@ -222,9 +222,50 @@
         $this->assertEquals( true, isset( $this->transport->serverHost ) );
         $this->assertEquals( true, isset( $this->transport->serverPort ) );
         $this->assertEquals( true, isset( $this->transport->timeout ) );
+        $this->assertEquals( true, isset( $this->transport->options ) );
         $this->assertEquals( false, isset( $this->transport->no_such_property 
) );
     }
 
+    public function testTransportProperties()
+    {
+        $smtp = new ezcMailSmtpTransport( ezcMailTransportSmtpTest::HOST, '', 
'', ezcMailTransportSmtpTest::PORT );
+
+        $options = $smtp->options;
+        $smtp->options = new ezcMailSmtpTransportOptions();
+        $this->assertEquals( $options, $smtp->options );
+        $this->assertEquals( 5, $smtp->options->timeout );
+
+        try
+        {
+            $smtp->options = 'xxx';
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            $this->assertEquals( "The value 'xxx' that you were trying to 
assign to setting 'options' is invalid. Allowed values are: instanceof 
ezcMailSmtpTransportOptions.", $e->getMessage() );
+        }
+
+        try
+        {
+            $smtp->no_such_property = 'xxx';
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {
+            $this->assertEquals( "No such property name 'no_such_property'.", 
$e->getMessage() );
+        }
+
+        try
+        {
+            $value = $smtp->no_such_property;
+            $this->fail( "Expected exception was not thrown" );
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {
+            $this->assertEquals( "No such property name 'no_such_property'.", 
$e->getMessage() );
+        }
+    }
+
     public static function suite()
     {
          return new PHPUnit_Framework_TestSuite( "ezcMailTransportSmtpTest" );

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

Reply via email to