From: Michael M Slusarz Date: Mon, 26 Apr 2010 21:03:53 +0000 (-0600) Subject: Add Horde_Imap_Client_Base::validSearchCharset() X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=ef61b34022cc14ebdc8aab7aaa2905a94ba2c2c5;p=horde.git Add Horde_Imap_Client_Base::validSearchCharset() --- diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Base.php b/framework/Imap_Client/lib/Horde/Imap/Client/Base.php index 3340b4c9c..24e988d41 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Base.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Base.php @@ -72,7 +72,8 @@ abstract class Horde_Imap_Client_Base */ protected $_init = array( 'enabled' => array(), - 'namespace' => array() + 'namespace' => array(), + 's_charset' => array() ); /** @@ -2714,7 +2715,7 @@ abstract class Horde_Imap_Client_Base */ abstract protected function _setMetadata($mailbox, $data); - /* Utility functions. */ + /* Public utility functions. */ /** * Returns a unique identifier for the current mailbox status. @@ -3011,6 +3012,58 @@ abstract class Horde_Imap_Client_Base } /** + * Determines if the given charset is valid for search-related queries. + * + * @param string $charset The query charset. + * + * @return boolean True if server supports this charset. + */ + public function validSearchCharset($charset) + { + if (!isset($this->_init['enabled']['s_charset'][$charset])) { + $support = null; + + switch ($charset) { + case 'US-ASCII'; + /* US-ASCII is always supported (RFC 3501 [6.4.4]). */ + $support = true; + break; + + case 'UTF-8': + /* SORT (RFC 5266) & ESORT (RFC 5267) require UTF-8 + * support. */ + if ($this->queryCapability('SORT') || + $this->queryCapability('ESORT')) { + $support = true; + } + break; + } + + /* Use a dummy search query and search for BADCHARSET + * response. */ + if (is_null($support)) { + $query = new Horde_Imap_Client_Search_Query(); + $query->charset($charset); + $query->text('a'); + try { + $this->search('INBOX', $query); + $support = true; + } catch (Horde_Imap_Client_Exception $e) { + /* BADCHARSET is only a MAYBE return - but there is no + * other way of determining charset support. */ + $support = ($e->getCode() != Horde_Imap_Client_Exception::BADCHARSET); + } + } + + $this->_init['enabled']['s_charset'][$charset] = $support; + } + + return $this->_init['enabled']['s_charset'][$charset]; + } + + /* Private utility functions. */ + + /** * Returns UIDs for an ALL search, or for a sequence number -> UID lookup. * * @param mixed $ids If null, return all UIDs for the mailbox. If an diff --git a/framework/Imap_Client/package.xml b/framework/Imap_Client/package.xml index dbe1c2046..d30f63f7e 100644 --- a/framework/Imap_Client/package.xml +++ b/framework/Imap_Client/package.xml @@ -31,7 +31,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> alpha LGPL - * Add Horde_Imap_Client_Base::fetchFromSectionString(). + * Add Horde_Imap_Client_Base::validSearchCharset(). + * Add Horde_Imap_Client_Base::fetchFromSectionString(). * Add support for RFC 4469 (CATENATE). * Correctly output 8-bit strings (RFC 3501 [4.3]). * Add Horde_Imap_Client_Utils::stripNonAtomChars().