From 852cd06ec099f9a75b6c19e94435ec45aa13b9b1 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 26 Apr 2010 15:27:19 -0600 Subject: [PATCH] Add callback function to search charset changing to change any text currently contained in the search --- .../lib/Horde/Imap/Client/Search/Query.php | 28 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Search/Query.php b/framework/Imap_Client/lib/Horde/Imap/Client/Search/Query.php index 56baad6e6..a3b80a813 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Search/Query.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Search/Query.php @@ -27,11 +27,11 @@ class Horde_Imap_Client_Search_Query /** * The charset of the search strings. All text strings must be in - * this charset. + * this charset. By default, this is 'US-ASCII' (see RFC 3501 [6.4.4]). * * @var string */ - protected $_charset = 'US-ASCII'; + protected $_charset = null; /** * The list of defined system flags (see RFC 3501 [2.3.2]). @@ -61,11 +61,29 @@ class Horde_Imap_Client_Search_Query /** * Sets the charset of the search text. * - * @param string $charset The charset to use for the search. + * @param string $charset The charset to use for the search. + * @param callback $callback A callback function to run on all text + * values when the charset changes. It must + * accept three parameters: the text, the old + * charset (will be null if no charset was + * previously given), and the new charset. It + * should return the converted text value. */ - public function charset($charset) + public function charset($charset, $callback = null) { + $oldcharset = $this->_charset; $this->_charset = strtoupper($charset); + if (is_null($callback) || ($oldcharset == $this->_charset)) { + return; + } + + foreach (array('header', 'text') as $item) { + if (isset($this->_search[$item])) { + foreach (array_keys($this->_search[$item]) as $key) { + $this->_search[$item][$key]['text'] = call_user_func_array($callback, array($this->_search[$item][$key]['text'], $oldcharset, $this->_charset)); + } + } + } } /** @@ -305,7 +323,7 @@ class Horde_Imap_Client_Search_Query } return array( - 'charset' => $this->_charset, + 'charset' => (is_null($this->_charset) ? 'US-ASCII' : $this->_charset), 'exts' => $exts_used, 'imap4' => $imap4, 'query' => $cmds -- 2.11.0