Author: Alexandru Stanoi Date: 2006-09-28 16:16:45 +0200 (Thu, 28 Sep 2006) New Revision: 3612
Log: - Added an optional parameter to listMessages() method in IMAP, to return messages with a certain Content-Type header (eg. "multipart/mixed" to return the list of messages with attachments). Modified: trunk/Mail/ChangeLog trunk/Mail/src/transports/imap/imap_transport.php trunk/Mail/tests/transports/transport_imap_test.php Modified: trunk/Mail/ChangeLog =================================================================== --- trunk/Mail/ChangeLog 2006-09-28 12:02:11 UTC (rev 3611) +++ trunk/Mail/ChangeLog 2006-09-28 14:16:45 UTC (rev 3612) @@ -25,8 +25,9 @@ sending a message without recipients. - Fixed a bug in ezcMailImapTransport: listUniqueIdentifiers() does not hang anymore when supplied parameter is an invalid message number. +- Added an optional parameter to listMessages() method in IMAP, to return + messages with a certain Content-Type header. - 1.1.2 - Monday 28 August 2006 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Modified: trunk/Mail/src/transports/imap/imap_transport.php =================================================================== --- trunk/Mail/src/transports/imap/imap_transport.php 2006-09-28 12:02:11 UTC (rev 3611) +++ trunk/Mail/src/transports/imap/imap_transport.php 2006-09-28 14:16:45 UTC (rev 3612) @@ -305,12 +305,17 @@ * It returns only the messages with the flag \Deleted not set. * The format of the returned array is array(message_id => size). * Eg: ( 2 => 1700, 5 => 1450, 6 => 21043 ) - * + * If $contentType is set, it returns only the messages with + * $contentType in the Content-Type header. + * For example $contentType can be "multipart/mixed" to return only the + * messages with attachments. + * * @throws ezcMailTransportException if there was no connection to the * server or if the server sent a negative response. + * @param string $contentType * @return array(int=>int) */ - public function listMessages() + public function listMessages( $contentType = null ) { if ( $this->state != self::STATE_SELECTED ) { @@ -322,7 +327,12 @@ // get the numbers of the existing messages $tag = $this->getNextTag(); - $this->connection->sendData( "{$tag} SEARCH UNDELETED" ); + $command = "{$tag} SEARCH UNDELETED"; + if ( !is_null( $contentType ) ) + { + $command .= " HEADER \"Content-Type\" \"{$contentType}\""; + } + $this->connection->sendData( $command ); $response = $this->getResponse( '* SEARCH' ); if ( strpos( $response, '* SEARCH' ) !== false ) { @@ -578,7 +588,7 @@ * Fetches $count messages starting from the $offset and returns them as a * ezcMailImapSet. If $count is not specified or if it is 0, it fetches * all messages starting from the $offset. - * + * * @throws ezcMailInvalidLimitException if $count is negative. * @throws ezcMailOffsetOutOfRangeException if $offset is outside of * the existing range of messages. Modified: trunk/Mail/tests/transports/transport_imap_test.php =================================================================== --- trunk/Mail/tests/transports/transport_imap_test.php 2006-09-28 12:02:11 UTC (rev 3611) +++ trunk/Mail/tests/transports/transport_imap_test.php 2006-09-28 14:16:45 UTC (rev 3612) @@ -216,6 +216,15 @@ $this->assertEquals( array( 1 => '1723', 2 => '1694', 3 => '1537', 4 => '64070' ), $list ); } + public function testListMessagesWithAttachments() + { + $imap = new ezcMailImapTransport( "dolly.ez.no" ); + $imap->authenticate( "ezcomponents", "ezcomponents" ); + $imap->selectMailbox( 'inbox' ); + $list = $imap->listMessages( "multipart/mixed" ); + $this->assertEquals( array( 1 => '1723', 2 => '1694', 4 => '64070' ), $list ); + } + public function testFetchByMessageNr1() { $imap = new ezcMailImapTransport( "dolly.ez.no" ); -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components