Author: as
Date: Tue Jul 3 16:49:54 2007
New Revision: 5679
Log:
- Implemented feature request #10659: Added the getHierarchyDelimiter() method
to the IMAP transport.
Modified:
trunk/Mail/ChangeLog
trunk/Mail/docs/tutorial/tutorial_imap_extra.php
trunk/Mail/src/transports/imap/imap_transport.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] Tue Jul 3 16:49:54 2007
@@ -5,6 +5,8 @@
methods.
- Implemented feature request #10459: Added the searchMailbox() method to the
IMAP transport. Based on a patch from Sinisa Dukaric.
+- Implemented feature request #10659: Added the getHierarchyDelimiter() method
+ to the IMAP transport.
1.3 - Monday 02 July 2007
Modified: trunk/Mail/docs/tutorial/tutorial_imap_extra.php
==============================================================================
--- trunk/Mail/docs/tutorial/tutorial_imap_extra.php [iso-8859-1] (original)
+++ trunk/Mail/docs/tutorial/tutorial_imap_extra.php [iso-8859-1] Tue Jul 3
16:49:54 2007
@@ -15,6 +15,9 @@
// List existing mailboxes
$mailboxes = $imap->listMailboxes( "", "*" );
+
+// Fetch the hierarchy delimiter character (usually "/")
+ $delimiter = $imap->getHierarchyDelimiter();
// Create a new mailbox
$imap->createMailbox( "Reports 2006" );
Modified: trunk/Mail/src/transports/imap/imap_transport.php
==============================================================================
--- trunk/Mail/src/transports/imap/imap_transport.php [iso-8859-1] (original)
+++ trunk/Mail/src/transports/imap/imap_transport.php [iso-8859-1] Tue Jul 3
16:49:54 2007
@@ -425,6 +425,65 @@
}
/**
+ * Returns the hierarchy delimiter of the IMAP server, useful for handling
+ * nested IMAP folders.
+ *
+ * Example:
+ * <code>
+ * $imap = new ezcMailImapTransport( 'imap.example.com' );
+ * $imap->authenticate( 'username', 'password' );
+ * $delimiter = $imap->getDelimiter();
+ * </code>
+ *
+ * After running the above code, $delimiter should be something like "/".
+ *
+ * Before returning the hierarchy delimiter, the connection state ($state)
+ * must be at least [EMAIL PROTECTED] STATE_AUTHENTICATED} or [EMAIL
PROTECTED] STATE_SELECTED}
+ * or [EMAIL PROTECTED] STATE_SELECTED_READONLY}.
+ *
+ * For more information about the hierarchy delimiter, consult the IMAP
RFCs
+ * [EMAIL PROTECTED] http://www.faqs.org/rfcs/rfc1730.html} or
+ * [EMAIL PROTECTED] http://www.faqs.org/rfcs/rfc2060.html}, section 6.3.8.
+ *
+ * @throws ezcMailMailTransportException
+ * if $state is not accepted
+ * or if the server sent a negative response
+ * @return string
+ */
+ public function getHierarchyDelimiter()
+ {
+ if ( $this->state != self::STATE_AUTHENTICATED &&
+ $this->state != self::STATE_SELECTED &&
+ $this->state != self::STATE_SELECTED_READONLY )
+ {
+ throw new ezcMailTransportException( "Can't call getDelimiter()
when not successfully logged in." );
+ }
+
+ $tag = $this->getNextTag();
+ $this->connection->sendData( "{$tag} LIST \"\" \"\"" );
+
+ // there should be only one * LIST response line from IMAP
+ $response = trim( $this->getResponse( '* LIST' ) );
+ $parts = explode( '"', $response );
+
+ if ( count( $parts ) >= 2 )
+ {
+ $result = $parts[1];
+ }
+ else
+ {
+ throw new ezcMailTransportException( "Could not retrieve the
hierarchy delimiter: {$response}." );
+ }
+
+ $response = $this->getResponse( $tag, $response );
+ if ( $this->responseType( $response ) != self::RESPONSE_OK )
+ {
+ throw new ezcMailTransportException( "Could not retrieve the
hierarchy delimiter: {$response}." );
+ }
+ return $result;
+ }
+
+ /**
* Selects the mailbox $mailbox.
*
* This method should be called after authentication, and before fetching
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] Tue Jul 3
16:49:54 2007
@@ -219,6 +219,53 @@
catch ( ezcMailTransportException $e )
{
$this->assertEquals( "An error occured while sending or receiving
mail. NOOP failed: XXXXX BAD XXXXX.", $e->getMessage() );
+ }
+ $imap->setStatus( ezcMailImapTransport::STATE_NOT_CONNECTED );
+ }
+
+ public function testWrapperMockGetHierarchyDelimiterFail()
+ {
+ $imap = new ezcMailImapTransportWrapper( self::$server, self::$port );
+ $imap = $this->getMock( 'ezcMailImapTransportWrapper', array(
'getResponse' ), array( self::$server, self::$port ) );
+ $imap->expects( $this->any() )
+ ->method( 'getResponse' )
+ ->will( $this->onConsecutiveCalls(
+ $this->returnValue( '* LIST (\Noselect) "/" ""' ),
+ $this->returnValue( 'XXXXX BAD XXXXX' )
+ ) );
+ $imap->authenticate( self::$user, self::$password );
+
+ try
+ {
+ $imap->getHierarchyDelimiter();
+ $this->fail( 'Expected exception was not thrown.' );
+ }
+ catch ( ezcMailTransportException $e )
+ {
+ $this->assertEquals( "An error occured while sending or receiving
mail. Could not retrieve the hierarchy delimiter: XXXXX BAD XXXXX.",
$e->getMessage() );
+ }
+ $imap->setStatus( ezcMailImapTransport::STATE_NOT_CONNECTED );
+ }
+
+ public function testWrapperMockGetHierarchyDelimiterWrongFail()
+ {
+ $imap = new ezcMailImapTransportWrapper( self::$server, self::$port );
+ $imap = $this->getMock( 'ezcMailImapTransportWrapper', array(
'getResponse' ), array( self::$server, self::$port ) );
+ $imap->expects( $this->any() )
+ ->method( 'getResponse' )
+ ->will( $this->onConsecutiveCalls(
+ $this->returnValue( '* LIST (\Noselect)' )
+ ) );
+ $imap->authenticate( self::$user, self::$password );
+
+ try
+ {
+ $imap->getHierarchyDelimiter();
+ $this->fail( 'Expected exception was not thrown.' );
+ }
+ catch ( ezcMailTransportException $e )
+ {
+ $this->assertEquals( "An error occured while sending or receiving
mail. Could not retrieve the hierarchy delimiter: * LIST (\\Noselect).",
$e->getMessage() );
}
$imap->setStatus( ezcMailImapTransport::STATE_NOT_CONNECTED );
}
@@ -1954,6 +2001,29 @@
}
}
+ public function testGetHierarchyDelimiter()
+ {
+ $imap = new ezcMailImapTransport( self::$server );
+ $imap->authenticate( self::$user, self::$password );
+ $delimiter = $imap->getHierarchyDelimiter();
+ $this->assertEquals( '/', $delimiter );
+ }
+
+ public function testGetHierarchyDelimiterFail()
+ {
+ $imap = new ezcMailImapTransport( self::$server );
+
+ try
+ {
+ $imap->getHierarchyDelimiter();
+ $this->fail( 'Expected exception was not thrown.' );
+ }
+ catch ( ezcMailTransportException $e )
+ {
+ $this->assertEquals( "An error occured while sending or receiving
mail. Can't call getDelimiter() when not successfully logged in.",
$e->getMessage() );
+ }
+ }
+
public function testTransportOptionsSetNotExistent()
{
$options = new ezcMailImapTransportOptions();
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components