Better logging framework for imap client lib
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 7 Sep 2010 06:50:14 +0000 (00:50 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 7 Sep 2010 07:13:26 +0000 (01:13 -0600)
Instead of using static variable, define a logger for each client object
instance, and ensure that this logger will survive serialization.

framework/Imap_Client/lib/Horde/Imap/Client.php
framework/Imap_Client/lib/Horde/Imap/Client/Base.php
framework/Imap_Client/lib/Horde/Imap/Client/Cclient.php
framework/Imap_Client/lib/Horde/Imap/Client/Cclient/Pop3.php
framework/Imap_Client/lib/Horde/Imap/Client/Exception.php
framework/Imap_Client/lib/Horde/Imap/Client/Mock.php
framework/Imap_Client/lib/Horde/Imap/Client/Socket.php
framework/Imap_Client/lib/Horde/Imap/Client/Socket/Pop3.php
framework/Imap_Client/package.xml
imp/lib/Imap.php

index 2e1706a..4b8099c 100644 (file)
@@ -161,6 +161,10 @@ class Horde_Imap_Client
      * lang - (array) A list of languages (in priority order) to be used to
      *        display human readable messages.
      *        DEFAULT: Messages output in IMAP server default language
+     * log - (array) A callback to a function that receives a single
+     *       parameter: a Horde_Imap_Client_Exception object. This callback
+     *       function MUST be static.
+     *       DEFAULT: No logging
      * port - (integer) The server port to which we will connect.
      *         DEFAULT: 143 (imap or imap w/TLS) or 993 (imaps)
      * secure - (string) Use SSL or TLS to connect.
index c1d0972..7a10b7f 100644 (file)
@@ -121,6 +121,7 @@ abstract class Horde_Imap_Client_Base implements Serializable
         $params = array_merge(array(
             'encryptKey' => null,
             'hostspec' => 'localhost',
+            'log' => null,
             'port' => ((isset($params['secure']) && ($params['secure'] == 'ssl')) ? 993 : 143),
             'secure' => false,
             'timeout' => 30
@@ -165,7 +166,31 @@ abstract class Horde_Imap_Client_Base implements Serializable
             return call_user_func($this->_params['encryptKey']);
         }
 
-        throw new Horde_Imap_Client_Exception('encryptKey parameter is not a valid callback.');
+        $this->_exception('encryptKey parameter is not a valid callback.');
+    }
+
+    /**
+     * Exception wrapper - logs an error message before throwing exception.
+     *
+     * @param string $msg           Error message.
+     * @param integer|string $code  Error code. If string, will convert from
+     *                              the Exception constant of the same name.
+     *
+     * @throws Horde_Imap_Client_Exception
+     */
+    protected function _exception($msg, $code = 0)
+    {
+        if (!is_integer($code)) {
+            $code = constant('Horde_Imap_Client_Exception::' . $code);
+        }
+
+        $e = new Horde_Imap_Client_Exception($msg, $code);
+
+        if (is_callable($this->_params['log'])) {
+            call_user_func($this->_params['log'], $e);
+        }
+
+        throw $e;
     }
 
     /**
@@ -566,7 +591,7 @@ abstract class Horde_Imap_Client_Base implements Serializable
     public function sendID($info = null)
     {
         if (!$this->queryCapability('ID')) {
-            throw new Horde_Imap_Client_Exception('The IMAP server does not support the ID extension.', Horde_Imap_Client_Exception::NOSUPPORTIMAPEXT);
+            $this->_exception('The IMAP server does not support the ID extension.', 'NOSUPPORTIMAPEXT');
         }
 
         $this->_sendID(is_null($info) ? (empty($this->_params['id']) ? array() : $this->_params['id']) : $info);
@@ -591,7 +616,7 @@ abstract class Horde_Imap_Client_Base implements Serializable
     public function getID()
     {
         if (!$this->queryCapability('ID')) {
-            throw new Horde_Imap_Client_Exception('The IMAP server does not support the ID extension.', Horde_Imap_Client_Exception::NOSUPPORTIMAPEXT);
+            $this->_exception('The IMAP server does not support the ID extension.', 'NOSUPPORTIMAPEXT');
         }
 
         return $this->_getID();
@@ -1611,7 +1636,7 @@ abstract class Horde_Imap_Client_Base implements Serializable
 
         $i18n = $this->queryCapability('I18NLEVEL');
         if (empty($i18n) || (max($i18n) < 2)) {
-            throw new Horde_Imap_Client_Exception('The IMAP server does not support changing SEARCH/SORT comparators.', Horde_Imap_Client_Exception::NOSUPPORTIMAPEXT);
+            $this->_exception('The IMAP server does not support changing SEARCH/SORT comparators.', 'NOSUPPORTIMAPEXT');
         }
 
         $this->_setComparator($comp);
@@ -2104,7 +2129,7 @@ abstract class Horde_Imap_Client_Base implements Serializable
             (!$qresync ||
              $seq ||
              empty($options['changedsince']))) {
-            throw new Horde_Imap_Client_Exception('The vanished FETCH modifier is missing a pre-requisite.');
+            $this->_exception('The vanished FETCH modifier is missing a pre-requisite.');
         }
 
         $this->openMailbox($mailbox, Horde_Imap_Client::OPEN_AUTO);
@@ -2428,7 +2453,7 @@ abstract class Horde_Imap_Client_Base implements Serializable
 
         if (!empty($options['unchangedsince']) &&
             !isset($this->_init['enabled']['CONDSTORE'])) {
-            throw new Horde_Imap_Client_Exception('Server does not support the CONDSTORE extension.', Horde_Imap_Client_Exception::NOSUPPORTIMAPEXT);
+            $this->_exception('Server does not support the CONDSTORE extension.', 'NOSUPPORTIMAPEXT');
         }
 
         return $this->_store($options);
@@ -2507,7 +2532,7 @@ abstract class Horde_Imap_Client_Base implements Serializable
     public function setQuota($root, $options = array())
     {
         if (!$this->queryCapability('QUOTA')) {
-            throw new Horde_Imap_Client_Exception('Server does not support the QUOTA extension.', Horde_Imap_Client_Exception::NOSUPPORTIMAPEXT);
+            $this->_exception('Server does not support the QUOTA extension.', 'NOSUPPORTIMAPEXT');
         }
 
         if (isset($options['messages']) || isset($options['storage'])) {
@@ -2540,7 +2565,7 @@ abstract class Horde_Imap_Client_Base implements Serializable
     public function getQuota($root)
     {
         if (!$this->queryCapability('QUOTA')) {
-            throw new Horde_Imap_Client_Exception('Server does not support the QUOTA extension.', Horde_Imap_Client_Exception::NOSUPPORTIMAPEXT);
+            $this->_exception('Server does not support the QUOTA extension.', 'NOSUPPORTIMAPEXT');
         }
 
         return $this->_getQuota(Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap($root));
@@ -2573,7 +2598,7 @@ abstract class Horde_Imap_Client_Base implements Serializable
     public function getQuotaRoot($mailbox)
     {
         if (!$this->queryCapability('QUOTA')) {
-            throw new Horde_Imap_Client_Exception('Server does not support the QUOTA extension.', Horde_Imap_Client_Exception::NOSUPPORTIMAPEXT);
+            $this->_exception('Server does not support the QUOTA extension.', 'NOSUPPORTIMAPEXT');
         }
 
         return $this->_getQuotaRoot(Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap($mailbox));
@@ -2637,7 +2662,7 @@ abstract class Horde_Imap_Client_Base implements Serializable
     public function setACL($mailbox, $identifier, $options)
     {
         if (!$this->queryCapability('ACL')) {
-            throw new Horde_Imap_Client_Exception('Server does not support the ACL extension.', Horde_Imap_Client_Exception::NOSUPPORTIMAPEXT);
+            $this->_exception('Server does not support the ACL extension.', 'NOSUPPORTIMAPEXT');
         }
 
         return $this->_setACL(Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap($mailbox), Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap($identifier), $options);
@@ -2672,7 +2697,7 @@ abstract class Horde_Imap_Client_Base implements Serializable
     public function listACLRights($mailbox, $identifier)
     {
         if (!$this->queryCapability('ACL')) {
-            throw new Horde_Imap_Client_Exception('Server does not support the ACL extension.', Horde_Imap_Client_Exception::NOSUPPORTIMAPEXT);
+            $this->_exception('Server does not support the ACL extension.', 'NOSUPPORTIMAPEXT');
         }
 
         return $this->_listACLRights(Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap($mailbox), Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap($identifier));
@@ -2701,7 +2726,7 @@ abstract class Horde_Imap_Client_Base implements Serializable
     public function getMyACLRights($mailbox)
     {
         if (!$this->queryCapability('ACL')) {
-            throw new Horde_Imap_Client_Exception('Server does not support the ACL extension.', Horde_Imap_Client_Exception::NOSUPPORTIMAPEXT);
+            $this->_exception('Server does not support the ACL extension.', 'NOSUPPORTIMAPEXT');
         }
 
         return $this->_getMyACLRights(Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap($mailbox));
@@ -3460,7 +3485,7 @@ abstract class Horde_Imap_Client_Base implements Serializable
                 }
 
                 if (is_null($part)) {
-                    throw new Horde_Imap_Client_Exception('Bad IMAP URL given in CATENATE data.', Horde_Imap_Client_Exception::CATENATE_BADURL);
+                    $this->_exception('Bad IMAP URL given in CATENATE data.', 'CATENATE_BADURL');
                 } else {
                     $this->_prepareAppendData($part, $stream);
                 }
index 7eafe5d..b71934b 100644 (file)
@@ -151,7 +151,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         error_reporting($old_error);
 
         if ($res === false) {
-            throw new Horde_Imap_Client_Exception('Received error from IMAP server when sending a NOOP command: ' . imap_last_error());
+            $this->_exception('Received error from IMAP server when sending a NOOP command: ' . imap_last_error());
         }
     }
 
@@ -189,7 +189,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         $res = false;
 
         if (!empty($this->_params['secure']) && !extension_loaded('openssl')) {
-            throw new Horde_Imap_Client_Exception('Secure connections require the PHP openssl extension: http://php.net/openssl.');
+            $this->_exception('Secure connections require the PHP openssl extension: http://php.net/openssl.');
         }
 
         $mask = ($this->_service == 'pop3') ? 0 : OP_HALFOPEN;
@@ -210,7 +210,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         error_reporting($old_error);
 
         if ($res === false) {
-            throw new Horde_Imap_Client_Exception('Could not authenticate to IMAP server: ' . imap_last_error());
+            $this->_exception('Could not authenticate to IMAP server: ' . imap_last_error());
         }
 
         $this->_stream = $res;
@@ -325,7 +325,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         error_reporting($old_error);
 
         if ($res === false) {
-            throw new Horde_Imap_Client_Exception('Could not open mailbox "' . $mailbox . '": ' . imap_last_error());
+            $this->_exception('Could not open mailbox "' . $mailbox . '": ' . imap_last_error());
         }
     }
 
@@ -351,7 +351,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         error_reporting($old_error);
 
         if ($res === false) {
-            throw new Horde_Imap_Client_Exception('Could not create mailbox "' . $mailbox . '": ' . imap_last_error());
+            $this->_exception('Could not create mailbox "' . $mailbox . '": ' . imap_last_error());
         }
     }
 
@@ -371,7 +371,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         error_reporting($old_error);
 
         if ($res === false) {
-            throw new Horde_Imap_Client_Exception('Could not delete mailbox "' . $mailbox . '": ' . imap_last_error());
+            $this->_exception('Could not delete mailbox "' . $mailbox . '": ' . imap_last_error());
         }
     }
 
@@ -392,7 +392,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         error_reporting($old_error);
 
         if ($res === false) {
-            throw new Horde_Imap_Client_Exception('Could not rename mailbox "' . $old . '": ' . imap_last_error());
+            $this->_exception('Could not rename mailbox "' . $old . '": ' . imap_last_error());
         }
     }
 
@@ -417,7 +417,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         error_reporting($old_error);
 
         if ($res === false) {
-            throw new Horde_Imap_Client_Exception('Could not ' . ($subscribe ? 'subscribe' : 'unsubscribe') . ' to mailbox "' . $mailbox . '": ' . imap_last_error());
+            $this->_exception('Could not ' . ($subscribe ? 'subscribe' : 'unsubscribe') . ' to mailbox "' . $mailbox . '": ' . imap_last_error());
         }
     }
 
@@ -674,7 +674,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
                     unset($options['create']);
                     return $this->_append($mailbox, $data, $options);
                 }
-                throw new Horde_Imap_Client_Exception('Could not append message to IMAP server: ' . imap_last_error());
+                $this->_exception('Could not append message to IMAP server: ' . imap_last_error());
             }
         }
 
@@ -695,7 +695,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         error_reporting($old_error);
 
         if ($res === false) {
-            throw new Horde_Imap_Client_Exception('Received error from IMAP server when sending a CHECK command: ' . imap_last_error());
+            $this->_exception('Received error from IMAP server when sending a CHECK command: ' . imap_last_error());
         }
     }
 
@@ -1066,7 +1066,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
                     } else {
                         $label = 'bodypart';
                         if (empty($val['id'])) {
-                            throw new Horde_Imap_Client_Exception('Need a MIME ID when retrieving a MIME body part.');
+                            $this->_exception('Need a MIME ID when retrieving a MIME body part.');
                         }
                         $body_key = $val['id'];
                     }
@@ -1306,7 +1306,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         error_reporting($old_error);
 
         if ($err) {
-            throw new Horde_Imap_Client_Exception('Error when fetching messages: ' . imap_last_error());
+            $this->_exception('Error when fetching messages: ' . imap_last_error());
         }
 
         return $ret;
@@ -1424,7 +1424,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         error_reporting($old_error);
 
         if ($res === false) {
-            throw new Horde_Imap_Client_Exception('Error when flagging messages: ' . imap_last_error());
+            $this->_exception('Error when flagging messages: ' . imap_last_error());
         }
 
         return array();
@@ -1471,7 +1471,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
                 unset($options['create']);
                 return $this->copy($dest, $options);
             }
-            throw new Horde_Imap_Client_Exception('Error when copying/moving messages: ' . imap_last_error());
+            $this->_exception('Error when copying/moving messages: ' . imap_last_error());
         }
 
         return true;
@@ -1500,7 +1500,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         error_reporting($old_error);
 
         if ($res === false) {
-            throw new Horde_Imap_Client_Exception('Error when setting quota: ' . imap_last_error());
+            $this->_exception('Error when setting quota: ' . imap_last_error());
         }
     }
 
@@ -1523,7 +1523,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         error_reporting($old_error);
 
         if ($res === false) {
-            throw new Horde_Imap_Client_Exception('Error when retrieving quota: ' . imap_last_error());
+            $this->_exception('Error when retrieving quota: ' . imap_last_error());
         }
     }
 
@@ -1547,7 +1547,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         error_reporting($old_error);
 
         if ($res === false) {
-            throw new Horde_Imap_Client_Exception('Error when retrieving quotaroot: ' . imap_last_error());
+            $this->_exception('Error when retrieving quotaroot: ' . imap_last_error());
         }
 
         return array($mailbox => $ret);
@@ -1584,7 +1584,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         error_reporting($old_error);
 
         if ($res === false) {
-            throw new Horde_Imap_Client_Exception('Error when setting ACL: ' . imap_last_error());
+            $this->_exception('Error when setting ACL: ' . imap_last_error());
         }
     }
 
@@ -1608,7 +1608,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         error_reporting($old_error);
 
         if ($res === false) {
-            throw new Horde_Imap_Client_Exception('Error when retrieving ACLs: ' . imap_last_error());
+            $this->_exception('Error when retrieving ACLs: ' . imap_last_error());
         }
 
         foreach ($res as $id => $rights) {
index daff1cf..b43223c 100644 (file)
@@ -60,7 +60,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _capability()
     {
-        throw new Horde_Imap_Client_Exception('CAPABILITY command not supported in this POP3 driver.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('CAPABILITY command not supported in this POP3 driver.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -70,7 +70,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _getNamespaces()
     {
-        throw new Horde_Imap_Client_Exception('IMAP namespaces not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP namespaces not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -82,7 +82,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _sendID($info)
     {
-        throw new Horde_Imap_Client_Exception('IMAP ID command not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP ID command not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -92,7 +92,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _getID()
     {
-        throw new Horde_Imap_Client_Exception('IMAP ID command not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP ID command not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -106,7 +106,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _setLanguage($langs)
     {
-        throw new Horde_Imap_Client_Exception('IMAP LANGUAGE extension not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP LANGUAGE extension not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -118,7 +118,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _getLanguage($list)
     {
-        throw new Horde_Imap_Client_Exception('IMAP LANGUAGE extension not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP LANGUAGE extension not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -132,7 +132,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
     protected function _openMailbox($mailbox, $mode)
     {
         if (strcasecmp($mailbox, 'INBOX') !== 0) {
-            throw new Horde_Imap_Client_Exception('Mailboxes other than INBOX not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+            $this->_exception('Mailboxes other than INBOX not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
         }
     }
 
@@ -146,7 +146,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _createMailbox($mailbox, $opts)
     {
-        throw new Horde_Imap_Client_Exception('Creating mailboxes not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Creating mailboxes not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -158,7 +158,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _deleteMailbox($mailbox)
     {
-        throw new Horde_Imap_Client_Exception('Deleting mailboxes not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Deleting mailboxes not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -171,7 +171,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _renameMailbox($old, $new)
     {
-        throw new Horde_Imap_Client_Exception('Renaming mailboxes not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Renaming mailboxes not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -184,7 +184,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _subscribeMailbox($mailbox, $subscribe)
     {
-        throw new Horde_Imap_Client_Exception('Mailboxes other than INBOX not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Mailboxes other than INBOX not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -231,7 +231,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
             ($flags & Horde_Imap_Client::STATUS_PERMFLAGS) ||
             ($flags & Horde_Imap_Client::STATUS_HIGHESTMODSEQ) ||
             ($flags & Horde_Imap_Client::STATUS_UIDNOTSTICKY)) {
-            throw new Horde_Imap_Client_Exception('Improper status request on POP3 server.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+            $this->_exception('Improper status request on POP3 server.', 'POP3_NOTSUPPORTED');
         }
 
         return parent::_status($mailbox, $flags);
@@ -261,7 +261,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
               in_array(Horde_Imap_Client::SORT_REVERSE, $options['sort']) ||
               in_array(Horde_Imap_Client::SORT_DISPLAYFROM, $options['sort']) ||
               in_array(Horde_Imap_Client::SORT_DISPLAYTO, $options['sort'])))) {
-            throw new Horde_Imap_Client_Exception('Unsupported search criteria on POP3 server.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+            $this->_exception('Unsupported search criteria on POP3 server.', 'POP3_NOTSUPPORTED');
         }
 
         return parent::_search($query, $options);
@@ -278,7 +278,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _setComparator($comparator)
     {
-        throw new Horde_Imap_Client_Exception('Search comparators not supported on POP3 server.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Search comparators not supported on POP3 server.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -288,7 +288,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _getComparator()
     {
-        throw new Horde_Imap_Client_Exception('Search comparators not supported on POP3 server.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Search comparators not supported on POP3 server.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -306,7 +306,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
         if (!empty($options['search']) ||
             (!empty($options['criteria']) &&
              $options['criteria'] != Horde_Imap_Client::THREAD_REFERENCES)) {
-            throw new Horde_Imap_Client_Exception('Unsupported threading criteria on POP3 server.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+            $this->_exception('Unsupported threading criteria on POP3 server.', 'POP3_NOTSUPPORTED');
         }
 
         return parent::_thread($options);
@@ -324,7 +324,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _append($mailbox, $data, $options)
     {
-        throw new Horde_Imap_Client_Exception('Appending messages not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Appending messages not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -344,7 +344,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
         reset($criteria);
         while (list($val,) = each($criteria)) {
             if (in_array($val, $nosupport)) {
-                throw new Horde_Imap_Client_Exception('Fetch criteria provided not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+                $this->_exception('Fetch criteria provided not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
             }
         }
 
@@ -394,7 +394,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _copy($dest, $options)
     {
-        throw new Horde_Imap_Client_Exception('Copying messages not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Copying messages not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -407,7 +407,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _setQuota($root, $options)
     {
-        throw new Horde_Imap_Client_Exception('IMAP quotas not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP quotas not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -419,7 +419,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _getQuota($root)
     {
-        throw new Horde_Imap_Client_Exception('IMAP quotas not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP quotas not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -431,7 +431,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _getQuotaRoot($mailbox)
     {
-        throw new Horde_Imap_Client_Exception('IMAP quotas not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP quotas not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -445,7 +445,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _setACL($mailbox, $identifier, $options)
     {
-        throw new Horde_Imap_Client_Exception('IMAP ACLs not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP ACLs not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -457,7 +457,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _getACL($mailbox)
     {
-        throw new Horde_Imap_Client_Exception('IMAP ACLs not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP ACLs not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -470,7 +470,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _listACLRights($mailbox, $identifier)
     {
-        throw new Horde_Imap_Client_Exception('IMAP ACLs not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP ACLs not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -482,7 +482,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _getMyACLRights($mailbox)
     {
-        throw new Horde_Imap_Client_Exception('IMAP ACLs not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP ACLs not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -498,7 +498,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
      protected function _getMetadata($mailbox, $entries, $options)
      {
-        throw new Horde_Imap_Client_Exception('IMAP metadata not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP metadata not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
      }
 
     /**
@@ -513,7 +513,7 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      */
     protected function _setMetadata($mailbox, $data)
     {
-        throw new Horde_Imap_Client_Exception('IMAP metadata not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP metadata not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
 }
index b65e6a0..5ccdad7 100644 (file)
@@ -86,25 +86,4 @@ class Horde_Imap_Client_Exception extends Exception
     // Login requires privacy.
     const LOGIN_PRIVACYREQUIRED = 21;
 
-    /**
-     * Define a callback function used to log the exception. Will be passed
-     * a single parameter - a copy of this object.
-     *
-     * @var callback
-     */
-    static public $logCallback = null;
-
-    /**
-     * Constructor.
-     */
-    public function __construct($message = null, $code = 0)
-    {
-        parent::__construct($message, $code);
-
-        /* Call log function. */
-        if (!is_null(self::$logCallback)) {
-            call_user_func(self::$logCallback, $this);
-        }
-    }
-
 }
index 4218cd3..a2916be 100644 (file)
@@ -161,7 +161,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _noop()
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -172,7 +172,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _getNamespaces()
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -183,7 +183,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     public function alerts()
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -206,7 +206,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _logout()
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -218,7 +218,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _sendID($info)
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -230,7 +230,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _getID()
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -244,7 +244,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _setLanguage($langs)
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -259,7 +259,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _getLanguage($list)
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -273,8 +273,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
     {
         $folder = $this->_parseFolder($mailbox);
         if (!isset(self::$storage[$folder])) {
-            throw new Horde_Imap_Client_Exception(sprintf("IMAP folder %s does not exist!",
-                                                          $folder));
+            $this->_exception(sprintf("IMAP folder %s does not exist!", $folder));
         }
         return $folder;
     }
@@ -308,8 +307,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
     {
         $mailbox = $this->_parseFolder($mailbox);
         if (isset(self::$storage[$mailbox])) {
-            throw new Horde_Imap_Client_Exception(sprintf("IMAP folder %s already exists!",
-                                                          $mailbox));
+            $this->_exception(sprintf("IMAP folder %s already exists!", $mailbox));
         }
         self::$storage[$mailbox] = array(
             'status' => array(
@@ -333,8 +331,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
     {
         $folder = $this->_parseFolder($mailbox);
         if (!isset(self::$storage[$folder])) {
-            throw new Horde_Imap_Client_Exception(sprintf("IMAP folder %s does not exist!",
-                                                          $folder));
+            $this->_exception(sprintf("IMAP folder %s does not exist!", $folder));
         }
         unset(self::$storage[$folder]);
         return true;
@@ -354,12 +351,10 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
         $new = $this->_parseFolder($new);
 
         if (!isset(self::$storage[$old])) {
-            throw new Horde_Imap_Client_Exception(sprintf("IMAP folder %s does not exist!",
-                                                          $old));
+            $this->_exception(sprintf("IMAP folder %s does not exist!", $old));
         }
         if (isset(self::$storage[$new])) {
-            throw new Horde_Imap_Client_Exception(sprintf("IMAP folder %s already exists!",
-                                                          $new));
+            $this->_exception(sprintf("IMAP folder %s already exists!", $new));
         }
         self::$storage[$new] = self::$storage[$old];
         unset(self::$storage[$old]);
@@ -376,7 +371,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _subscribeMailbox($mailbox, $subscribe)
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -473,7 +468,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _check()
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -486,7 +481,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _close($options)
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -539,8 +534,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
                 }
                 break;
             default:
-                throw new Horde_Imap_Client_Exception(sprintf('Search command %s not implemented!',
-                                                                $cmd));
+                $this->_exception(sprintf('Search command %s not implemented!', $cmd));
             }
         }
         return array('match' => $uids, 'count' => count($uids));
@@ -558,7 +552,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _setComparator($comparator)
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -570,7 +564,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _getComparator()
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -597,7 +591,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _thread($options)
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -626,13 +620,13 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
             switch ($type) {
             case Horde_Imap_Client::FETCH_HEADERTEXT:
                 if (!isset($this->_mbox['mails'][$uid])) {
-                    throw new Horde_Imap_Client_Exception(sprintf("No IMAP message %s!", $uid));
+                    $this->_exception(sprintf("No IMAP message %s!", $uid));
                 }
                 $result['headertext'][$uid] = $this->_mbox['mails'][$uid]['header'];
                 break;
             case Horde_Imap_Client::FETCH_BODYTEXT:
                 if (!isset($this->_mbox['mails'][$uid])) {
-                    throw new Horde_Imap_Client_Exception(sprintf("No IMAP message %s!", $uid));
+                    $this->_exception(sprintf("No IMAP message %s!", $uid));
                 }
                 $result['bodytext'][$uid] =  $this->_mbox['mails'][$uid]['body'];
                 break;
@@ -650,7 +644,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
             case Horde_Imap_Client::FETCH_UID:
             case Horde_Imap_Client::FETCH_SEQ:
             case Horde_Imap_Client::FETCH_MODSEQ:
-                throw new Horde_Imap_Client_Exception('Not supported!');
+                $this->_exception('Not supported!');
             }
         }
         return $result;
@@ -670,7 +664,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
         foreach ($options['ids'] as $uid) {
 
             if (!isset($this->_mbox['mails'][$uid])) {
-                throw new Horde_Imap_Client_Exception(sprintf("No IMAP message %s!", $uid));
+                $this->_exception(sprintf("No IMAP message %s!", $uid));
             }
             foreach ($options['add'] as $flag) {
                 $flag = strtoupper($flag);
@@ -679,8 +673,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
                     $this->_mbox['mails'][$uid]['flags'] |= self::FLAG_DELETED;
                     break;
                 default:
-                    throw new Horde_Imap_Client_Exception(sprintf('Flag %s not implemented!',
-                                                                  $flag));
+                    $this->_exception(sprintf('Flag %s not implemented!', $flag));
                 }
             }
         }
@@ -704,7 +697,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
 
         foreach ($options['ids'] as $uid) {
             if (!isset($this->_mbox['mails'][$uid])) {
-                throw new Horde_Imap_Client_Exception(sprintf("No IMAP message %s!", $uid));
+                $this->_exception(sprintf("No IMAP message %s!", $uid));
             }
             $mail = $this->_mbox['mails'][$uid];
             if (!empty($options['move'])) {
@@ -726,7 +719,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _setQuota($root, $options)
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -741,7 +734,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _getQuota($root)
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -757,7 +750,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _getQuotaRoot($mailbox)
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
@@ -809,7 +802,7 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
      */
     protected function _listACLRights($mailbox, $identifier)
     {
-        throw new Horde_Imap_Client_Exception('not implemented');
+        $this->_exception('not implemented');
     }
 
     /**
index 262c93c..aac156f 100644 (file)
@@ -268,7 +268,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
             if (!$this->queryCapability('STARTTLS')) {
                 // We should never hit this - STARTTLS is required pursuant
                 // to RFC 3501 [6.2.1].
-                throw new Horde_Imap_Client_Exception('Server does not support TLS connections.', Horde_Imap_Client_Exception::NOSUPPORTIMAPEXT);
+                $this->_exception('Server does not support TLS connections.', 'NOSUPPORTIMAPEXT');
             }
 
             // Switch over to a TLS connection.
@@ -281,7 +281,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
 
             if (!$res) {
                 $this->logout();
-                throw new Horde_Imap_Client_Exception('Could not open secure TLS connection to the IMAP server.', Horde_Imap_Client_Exception::LOGIN_TLSFAILURE);
+                $this->_exception('Could not open secure TLS connection to the IMAP server.', 'LOGIN_TLSFAILURE');
             }
 
             // Expire cached CAPABILITY information (RFC 3501 [6.2.1])
@@ -319,7 +319,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
             }
 
             if (empty($imap_auth_mech)) {
-                throw new Horde_Imap_Client_Exception('No supported IMAP authentication method could be found.', Horde_Imap_Client_Exception::LOGIN_NOAUTHMETHOD);
+                $this->_exception('No supported IMAP authentication method could be found.', 'LOGIN_NOAUTHMETHOD');
             }
 
             /* Use MD5 authentication first, if available. But no need to use
@@ -334,7 +334,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
         }
 
         /* Default to AUTHENTICATIONFAILED error (see RFC 5530[3]). */
-        $t['loginerr'] = Horde_Imap_Client_Exception::LOGIN_AUTHENTICATIONFAILED;
+        $t['loginerr'] = 'LOGIN_AUTHENTICATIONFAILED';
 
         foreach ($imap_auth_mech as $method) {
             $t['referral'] = null;
@@ -396,7 +396,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
             }
         }
 
-        throw new Horde_Imap_Client_Exception('IMAP server denied authentication.', $t['loginerr']);
+        $this->_exception('IMAP server denied authentication.', $t['loginerr']);
     }
 
     /**
@@ -411,7 +411,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
         }
 
         if (!empty($this->_params['secure']) && !extension_loaded('openssl')) {
-            throw new Horde_Imap_Client_Exception('Secure connections require the PHP openssl extension.', Horde_Imap_Client_Exception::SERVER_CONNECT);
+            $this->_exception('Secure connections require the PHP openssl extension.', 'SERVER_CONNECT');
         }
 
         switch ($this->_params['secure']) {
@@ -433,7 +433,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
         if ($this->_stream === false) {
             $this->_stream = null;
             $this->_isSecure = false;
-            throw new Horde_Imap_Client_Exception('Error connecting to IMAP server: [' . $error_number . '] ' . $error_string, Horde_Imap_Client_Exception::SERVER_CONNECT);
+            $this->_exception('Error connecting to IMAP server: [' . $error_number . '] ' . $error_string, 'SERVER_CONNECT');
         }
 
         stream_set_timeout($this->_stream, $this->_params['timeout']);
@@ -456,7 +456,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
         switch ($ob['response']) {
         case 'BAD':
             // Server is rejecting our connection.
-            throw new Horde_Imap_Client_Exception('Server rejected connection: ' . $ob['line'], Horde_Imap_Client_Exception::SERVER_CONNECT);
+            $this->_exception('Server rejected connection: ' . $ob['line'], 'SERVER_CONNECT');
 
         case 'PREAUTH':
             // The user was pre-authenticated.
@@ -471,7 +471,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
 
         // Check for IMAP4rev1 support
         if (!$this->queryCapability('IMAP4REV1')) {
-            throw new Horde_Imap_Client_Exception('This server does not support IMAP4rev1 (RFC 3501).', Horde_Imap_Client_Exception::SERVER_CONNECT);
+            $this->_exception('This server does not support IMAP4rev1 (RFC 3501).', 'SERVER_CONNECT');
         }
 
         // Set language if not using imapproxy
@@ -511,7 +511,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
             case 'CRAM-MD5':
                 // RFC 2195
                 if (!class_exists('Auth_SASL')) {
-                    throw new Horde_Imap_Client_Exception('The Auth_SASL package is required for CRAM-MD5 authentication');
+                    $this->_exception('The Auth_SASL package is required for CRAM-MD5 authentication');
                 }
                 $auth_sasl = Auth_SASL::factory('crammd5');
                 $response = base64_encode($auth_sasl->getResponse($this->_params['username'], $this->getParam('password'), base64_decode($ob['line'])));
@@ -523,7 +523,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
 
             case 'DIGEST-MD5':
                 if (!class_exists('Auth_SASL')) {
-                    throw new Horde_Imap_Client_Exception('The Auth_SASL package is required for DIGEST-MD5 authentication');
+                    $this->_exception('The Auth_SASL package is required for DIGEST-MD5 authentication');
                 }
                 $auth_sasl = Auth_SASL::factory('digestmd5');
                 $response = base64_encode($auth_sasl->getResponse($this->_params['username'], $this->getParam('password'), base64_decode($ob['line']), $this->_params['hostspec'], 'imap'));
@@ -534,7 +534,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
                 ));
                 $response = base64_decode($ob['line']);
                 if (strpos($response, 'rspauth=') === false) {
-                    throw new Horde_Imap_Client_Exception('Unexpected response from server to Digest-MD5 response.');
+                    $this->_exception('Unexpected response from server to Digest-MD5 response.');
                 }
                 $this->_sendLine('', array(
                     'notag' => true
@@ -1700,7 +1700,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
          * an exception. */
         if (in_array('CONDSTORE', $options['_query']['exts']) &&
             empty($this->_temp['mailbox']['highestmodseq'])) {
-            throw new Horde_Imap_Client_Exception('Mailbox does not support mod-sequences.', Horde_Imap_Client_Exception::MBOXNOMODSEQ);
+            $this->_exception('Mailbox does not support mod-sequences.', 'MBOXNOMODSEQ');
         }
 
         $cmd = array();
@@ -2222,7 +2222,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
 
             case 'REFERENCES':
             case 'REFS':
-                throw new Horde_Imap_Client_Exception('Server does not support ' . $tsort . ' thread sort.', Horde_Imap_Client_Exception::NOSUPPORTIMAPEXT);
+                $this->_exception('Server does not support ' . $tsort . ' thread sort.', 'NOSUPPORTIMAPEXT');
             }
         }
 
@@ -2440,14 +2440,14 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
 
                     case Horde_Imap_Client::FETCH_MIMEHEADER:
                         if (empty($val['id'])) {
-                            throw new Horde_Imap_Client_Exception('Need a non-zero MIME ID when retrieving a MIME header.');
+                            $this->_exception('Need a non-zero MIME ID when retrieving a MIME header.');
                         }
                         $cmd .= 'MIME';
                         break;
 
                     case Horde_Imap_Client::FETCH_BODYPART:
                         if (empty($val['id'])) {
-                            throw new Horde_Imap_Client_Exception('Need a non-zero MIME ID when retrieving a MIME body part.');
+                            $this->_exception('Need a non-zero MIME ID when retrieving a MIME body part.');
                         }
 
                         if (!empty($val['stream'])) {
@@ -2465,9 +2465,9 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
 
                     case Horde_Imap_Client::FETCH_HEADERS:
                         if (empty($val['label'])) {
-                            throw new Horde_Imap_Client_Exception('Need a unique label when doing a headers field search.');
+                            $this->_exception('Need a unique label when doing a headers field search.');
                         } elseif (empty($val['headers'])) {
-                            throw new Horde_Imap_Client_Exception('Need headers to query when doing a headers field search.');
+                            $this->_exception('Need headers to query when doing a headers field search.');
                         }
                         $fp['parseheaders'] = !empty($val['parse']);
 
@@ -2499,7 +2499,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
             case Horde_Imap_Client::FETCH_BODYPARTSIZE:
                 foreach ($c_val as $val) {
                     if (empty($val['id'])) {
-                        throw new Horde_Imap_Client_Exception('Need a non-zero MIME ID when retrieving unencoded MIME body part size.');
+                        $this->_exception('Need a non-zero MIME ID when retrieving unencoded MIME body part size.');
                     }
                     $fetch[] = 'BINARY.SIZE[' . $val['id'] . ']';
                 }
@@ -2538,7 +2538,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
                  * mailbox that doesn't support it will return BAD. Catch that
                  * here and throw an exception. */
                 if (empty($this->_temp['mailbox']['highestmodseq'])) {
-                    throw new Horde_Imap_Client_Exception('Mailbox does not support mod-sequences.', Horde_Imap_Client_Exception::MBOXNOMODSEQ);
+                    $this->_exception('Mailbox does not support mod-sequences.', 'MBOXNOMODSEQ');
                 }
                 $fetch[] = 'MODSEQ';
                 break;
@@ -2561,7 +2561,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
 
         if (!empty($options['changedsince'])) {
             if (empty($this->_temp['mailbox']['highestmodseq'])) {
-                throw new Horde_Imap_Client_Exception('Mailbox does not support mod-sequences.', Horde_Imap_Client_Exception::MBOXNOMODSEQ);
+                $this->_exception('Mailbox does not support mod-sequences.', 'MBOXNOMODSEQ');
             }
             $cmd[] = array(
                 'CHANGEDSINCE',
@@ -2972,7 +2972,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
                 /* RFC 4551 [3.1] - trying to do a UNCHANGEDSINCE STORE on a
                  * mailbox that doesn't support it will return BAD. Catch that
                  * here and throw an exception. */
-                throw new Horde_Imap_Client_Exception('Mailbox does not support mod-sequences.', Horde_Imap_Client_Exception::MBOXNOMODSEQ);
+                $this->_exception('Mailbox does not support mod-sequences.', 'MBOXNOMODSEQ');
             }
         } else {
             if (!empty($options['unchangedsince'])) {
@@ -3406,7 +3406,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
 
         if (!$this->queryCapability('ANNOTATEMORE') &&
             !$this->queryCapability('ANNOTATEMORE2')) {
-            throw new Horde_Imap_Client_Exception('Server does not support the METADATA extension.', Horde_Imap_Client_Exception::NOSUPPORTIMAPEXT);
+            $this->_exception('Server does not support the METADATA extension.', 'NOSUPPORTIMAPEXT');
         }
 
         $queries = array();
@@ -3453,7 +3453,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
             return array(substr($name, 8), 'value.priv');
         }
 
-        throw new Horde_Imap_Client_Exception('Invalid METADATA entry: ' . $name);
+        $this->_exception('Invalid METADATA entry: ' . $name);
     }
 
     /**
@@ -3491,7 +3491,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
 
         if (!$this->queryCapability('ANNOTATEMORE') &&
             !$this->queryCapability('ANNOTATEMORE2')) {
-            throw new Horde_Imap_Client_Exception('Server does not support the METADATA extension.', Horde_Imap_Client_Exception::NOSUPPORTIMAPEXT);
+            $this->_exception('Server does not support the METADATA extension.', 'NOSUPPORTIMAPEXT');
         }
 
         foreach ($data as $md_entry => $value) {
@@ -3536,7 +3536,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
                     break;
 
                 default:
-                    throw new Horde_Imap_Client_Exception('Invalid METADATA value type ' . $type);
+                    $this->_exception('Invalid METADATA value type ' . $type);
                 }
             }
             break;
@@ -3631,7 +3631,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
             /* RFC 3516 - Send literal8 if we have binary data. */
             if (!empty($options['binary'])) {
                 if (!$this->queryCapability('BINARY')) {
-                    throw new Horde_Imap_Client_Exception('Can not send binary data to server that does not support it.', Horde_Imap_Client_Exception::NOSUPPORTIMAPEXT);
+                    $this->_exception('Can not send binary data to server that does not support it.', 'NOSUPPORTIMAPEXT');
                 }
                 $out .= '~';
             }
@@ -3665,7 +3665,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
         if (!empty($options['literal'])) {
             $ob = $this->_getLine();
             if ($ob['type'] != 'continuation') {
-                throw new Horde_Imap_Client_Exception('Unexpected response from IMAP server while waiting for a continuation request: ' . $ob['line']);
+                $this->_exception('Unexpected response from IMAP server while waiting for a continuation request: ' . $ob['line']);
             }
         } elseif (empty($options['noparse'])) {
             $this->_parseResponse($this->_tag, !empty($options['errignore']));
@@ -3762,7 +3762,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
                 } else {
                     $this->_temp['logout'] = true;
                     $this->logout();
-                    throw new Horde_Imap_Client_Exception('IMAP Server closed the connection: ' . implode(' ', array_slice($read, 1)), Horde_Imap_Client_Exception::DISCONNECT);
+                    $this->_exception('IMAP Server closed the connection: ' . implode(' ', array_slice($read, 1)), 'DISCONNECT');
                 }
             }
 
@@ -3848,7 +3848,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
             if ($this->_debug) {
                 fwrite($this->_debug, "[ERROR: IMAP server closed the connection.]\n");
             }
-            throw new Horde_Imap_Client_Exception('IMAP server closed the connection unexpectedly.', Horde_Imap_Client_Exception::DISCONNECT);
+            $this->_exception('IMAP server closed the connection unexpectedly.', 'DISCONNECT');
         }
 
         $data = '';
@@ -3903,7 +3903,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
                 fwrite($this->_debug, "[ERROR: IMAP read/timeout error.]\n");
             }
             $this->logout();
-            throw new Horde_Imap_Client_Exception('IMAP read error or IMAP connection timed out.', Horde_Imap_Client_Exception::SERVER_READERROR);
+            $this->_exception('IMAP read error or IMAP connection timed out.', 'SERVER_READERROR');
         }
 
         if ($this->_debug) {
@@ -4029,10 +4029,10 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
                     $this->_temp['parseresperr'] = $ob;
 
                     if ($ob['response'] == 'BAD') {
-                        throw new Horde_Imap_Client_Exception('Bad IMAP request: ' . $errstr, $errcode);
+                        $this->_exception('Bad IMAP request: ' . $errstr, $errcode);
                     }
 
-                    throw new Horde_Imap_Client_Exception('IMAP error: ' . $errstr, $errcode);
+                    $this->_exception('IMAP error: ' . $errstr, $errcode);
                 }
 
                 /* Update the cache, if needed. */
@@ -4218,7 +4218,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
             /* @todo Store the list of search charsets supported by the server
              * (this is a MAY response, not a MUST response) */
             $this->_temp['parsestatuserr'] = array(
-                Horde_Imap_Client_Exception::BADCHARSET,
+                'BADCHARSET',
                 substr($ob['line'], $end_pos + 2)
             );
             break;
@@ -4231,7 +4231,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
 
         case 'PARSE':
             $this->_temp['parsestatuserr'] = array(
-                Horde_Imap_Client_Exception::PARSEERROR,
+                'PARSEERROR',
                 substr($ob['line'], $end_pos + 2)
             );
             break;
@@ -4271,7 +4271,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
         case 'UNKNOWN-CTE':
             // Defined by RFC 3516
             $this->_temp['parsestatuserr'] = array(
-                Horde_Imap_Client_Exception::UNKNOWNCTE,
+                'UNKNOWNCTE',
                 substr($ob['line'], $end_pos + 2)
             );
             break;
@@ -4307,7 +4307,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
         case 'BADURL':
             // Defined by RFC 4469 [4.1]
             $this->_temp['parsestatuserr'] = array(
-                Horde_Imap_Client_Exception::CATENATE_BADURL,
+                'CATENATE_BADURL',
                 substr($ob['line'], $end_pos + 2)
             );
             break;
@@ -4315,7 +4315,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
         case 'TOOBIG':
             // Defined by RFC 4469 [4.2]
             $this->_temp['parsestatuserr'] = array(
-                Horde_Imap_Client_Exception::CATENATE_TOOBIG,
+                'CATENATE_TOOBIG',
                 substr($ob['line'], $end_pos + 2)
             );
             break;
@@ -4356,34 +4356,34 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
         case 'BADCOMPARATOR':
             // Defined by RFC 5255 [4.9]
             $this->_temp['parsestatuserr'] = array(
-                Horde_Imap_Client_Exception::BADCOMPARATOR,
+                'BADCOMPARATOR',
                 substr($ob['line'], $end_pos + 2)
             );
             break;
 
         case 'UNAVAILABLE':
             // Defined by RFC 5530 [3]
-            $this->_temp['loginerr'] = Horde_Imap_Client_Exception::LOGIN_UNAVAILABLE;
+            $this->_temp['loginerr'] = 'LOGIN_UNAVAILABLE';
             break;
 
         case 'AUTHENTICATIONFAILED':
             // Defined by RFC 5530 [3]
-            $this->_temp['loginerr'] = Horde_Imap_Client_Exception::LOGIN_AUTHENTICATIONFAILED;
+            $this->_temp['loginerr'] = 'LOGIN_AUTHENTICATIONFAILED';
             break;
 
         case 'AUTHORIZATIONFAILED':
             // Defined by RFC 5530 [3]
-            $this->_temp['loginerr'] = Horde_Imap_Client_Exception::LOGIN_AUTHORIZATIONFAILED;
+            $this->_temp['loginerr'] = 'LOGIN_AUTHORIZATIONFAILED';
             break;
 
         case 'EXPIRED':
             // Defined by RFC 5530 [3]
-            $this->_temp['loginerr'] = Horde_Imap_Client_Exception::LOGIN_EXPIRED;
+            $this->_temp['loginerr'] = 'LOGIN_EXPIRED';
             break;
 
         case 'PRIVACYREQUIRED':
             // Defined by RFC 5530 [3]
-            $this->_temp['loginerr'] = Horde_Imap_Client_Exception::LOGIN_PRIVACYREQUIRED;
+            $this->_temp['loginerr'] = 'LOGIN_PRIVACYREQUIRED';
             break;
 
         case 'NOPERM':
index 4815d09..92abb81 100644 (file)
@@ -171,7 +171,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _getNamespaces()
     {
-        throw new Horde_Imap_Client_Exception('IMAP namespaces not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP namespaces not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -199,7 +199,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
             ($this->_params['secure'] == 'tls')) {
             // Switch over to a TLS connection.
             if (!$this->queryCapability('STLS')) {
-                throw new Horde_Imap_Client_Exception('Could not open secure TLS connection to the POP3 server - server does not support TLS.');
+                $this->_exception('Could not open secure TLS connection to the POP3 server - server does not support TLS.');
             }
 
             $this->_sendLine('STLS');
@@ -210,7 +210,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
 
             if (!$res) {
                 $this->logout();
-                throw new Horde_Imap_Client_Exception('Could not open secure TLS connection to the POP3 server.');
+                $this->_exception('Could not open secure TLS connection to the POP3 server.');
             }
 
             // Expire cached CAPABILITY information
@@ -246,7 +246,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
             }
         }
 
-        throw new Horde_Imap_Client_Exception('POP3 server denied authentication.');
+        $this->_exception('POP3 server denied authentication.');
     }
 
     /**
@@ -261,7 +261,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
         }
 
         if (!empty($this->_params['secure']) && !extension_loaded('openssl')) {
-            throw new Horde_Imap_Client_Exception('Secure connections require the PHP openssl extension.');
+            $this->_exception('Secure connections require the PHP openssl extension.');
         }
 
         switch ($this->_params['secure']) {
@@ -283,7 +283,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
         if ($this->_stream === false) {
             $this->_stream = null;
             $this->_isSecure = false;
-            throw new Horde_Imap_Client_Exception('Error connecting to POP3 server: [' . $error_number . '] ' . $error_string, Horde_Imap_Client_Exception::SERVER_CONNECT);
+            $this->_exception('Error connecting to POP3 server: [' . $error_number . '] ' . $error_string, 'SERVER_CONNECT');
         }
 
         stream_set_timeout($this->_stream, $this->_params['timeout']);
@@ -314,7 +314,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
         case 'CRAM-MD5':
             // RFC 5034
             if (!class_exists('Auth_SASL')) {
-                throw new Horde_Imap_Client_Exception('The Auth_SASL package is required for CRAM-MD5 authentication');
+                $this->_exception('The Auth_SASL package is required for CRAM-MD5 authentication');
             }
 
             $challenge = $this->_sendLine('AUTH CRAM-MD5');
@@ -327,7 +327,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
         case 'DIGEST-MD5':
             // RFC 5034
             if (!class_exists('Auth_SASL')) {
-                throw new Horde_Imap_Client_Exception('The Auth_SASL package is required for DIGEST-MD5 authentication');
+                $this->_exception('The Auth_SASL package is required for DIGEST-MD5 authentication');
             }
 
             $challenge = $this->_sendLine('AUTH DIGEST-MD5');
@@ -337,7 +337,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
 
             $sresponse = $this->_sendLine($response, array('debug' => '[DIGEST-MD5 Response]'));
             if (stripos(base64_decode(substr($sresponse['line'], 2)), 'rspauth=') === false) {
-                throw new Horde_Imap_Client_Exception('Unexpected response from server to Digest-MD5 response.');
+                $this->_exception('Unexpected response from server to Digest-MD5 response.');
             }
 
             /* POP3 doesn't use protocol's third step. */
@@ -393,7 +393,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _sendID($info)
     {
-        throw new Horde_Imap_Client_Exception('IMAP ID command not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP ID command not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -421,7 +421,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _setLanguage($langs)
     {
-        throw new Horde_Imap_Client_Exception('IMAP LANGUAGE extension not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP LANGUAGE extension not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -433,7 +433,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _getLanguage($list)
     {
-        throw new Horde_Imap_Client_Exception('IMAP LANGUAGE extension not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP LANGUAGE extension not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -447,7 +447,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
     protected function _openMailbox($mailbox, $mode)
     {
         if (strcasecmp($mailbox, 'INBOX') !== 0) {
-            throw new Horde_Imap_Client_Exception('Mailboxes other than INBOX not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+            $this->_exception('Mailboxes other than INBOX not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
         }
 
         $this->login();
@@ -463,7 +463,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _createMailbox($mailbox, $opts)
     {
-        throw new Horde_Imap_Client_Exception('Creating mailboxes not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Creating mailboxes not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -475,7 +475,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _deleteMailbox($mailbox)
     {
-        throw new Horde_Imap_Client_Exception('Deleting mailboxes not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Deleting mailboxes not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -488,7 +488,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _renameMailbox($old, $new)
     {
-        throw new Horde_Imap_Client_Exception('Renaming mailboxes not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Renaming mailboxes not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -501,7 +501,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _subscribeMailbox($mailbox, $subscribe)
     {
-        throw new Horde_Imap_Client_Exception('Mailboxes other than INBOX not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Mailboxes other than INBOX not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -549,7 +549,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
             ($flags & Horde_Imap_Client::STATUS_PERMFLAGS) ||
             ($flags & Horde_Imap_Client::STATUS_HIGHESTMODSEQ) ||
             ($flags & Horde_Imap_Client::STATUS_UIDNOTSTICKY)) {
-            throw new Horde_Imap_Client_Exception('Improper status request on POP3 server.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+            $this->_exception('Improper status request on POP3 server.', 'POP3_NOTSUPPORTED');
         }
 
         $ret = array();
@@ -592,7 +592,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _append($mailbox, $data, $options)
     {
-        throw new Horde_Imap_Client_Exception('Appending messages not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Appending messages not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -658,7 +658,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
             ($sort &&
              ((count($options['sort']) > 1) ||
               ($sort != Horde_Imap_Client::SORT_SEQUENCE)))) {
-            throw new Horde_Imap_Client_Exception('Server search not supported on POP3 server.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+            $this->_exception('Server search not supported on POP3 server.', 'POP3_NOTSUPPORTED');
         }
 
         $status = $this->status($this->_selected, Horde_Imap_Client::STATUS_MESSAGES);
@@ -708,7 +708,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _setComparator($comparator)
     {
-        throw new Horde_Imap_Client_Exception('Search comparators not supported on POP3 server.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Search comparators not supported on POP3 server.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -718,7 +718,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _getComparator()
     {
-        throw new Horde_Imap_Client_Exception('Search comparators not supported on POP3 server.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Search comparators not supported on POP3 server.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -731,7 +731,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _thread($options)
     {
-        throw new Horde_Imap_Client_Exception('Server threading not supported on POP3 server.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Server threading not supported on POP3 server.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -751,7 +751,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
         if (!empty($options['changedsince']) ||
             !empty($options['vanished']) ||
             (reset($options['ids']) == Horde_Imap_Client::USE_SEARCHRES)) {
-            throw new Horde_Imap_Client_Exception('Fetch options not supported on POP3 server.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+            $this->_exception('Fetch options not supported on POP3 server.', 'POP3_NOTSUPPORTED');
         }
 
         // Ignore 'sequence' - IDs will always be the message number.
@@ -820,7 +820,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
                         $rawtype = 'header';
 
                         if (empty($val['id'])) {
-                            throw new Horde_Imap_Client_Exception('Need a non-zero MIME ID when retrieving a MIME header.');
+                            $this->_exception('Need a non-zero MIME ID when retrieving a MIME header.');
                         }
                         break;
 
@@ -830,7 +830,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
                         $rawtype = 'body';
 
                         if (empty($val['id'])) {
-                            throw new Horde_Imap_Client_Exception('Need a non-zero MIME ID when retrieving a MIME body part.');
+                            $this->_exception('Need a non-zero MIME ID when retrieving a MIME body part.');
                         }
                         break;
                     }
@@ -878,9 +878,9 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
                         $tmp = $ob;
 
                         if (empty($val['label'])) {
-                            throw new Horde_Imap_Client_Exception('Need a unique label when doing a headers field search.');
+                            $this->_exception('Need a unique label when doing a headers field search.');
                         } elseif (empty($val['headers'])) {
-                            throw new Horde_Imap_Client_Exception('Need headers to query when doing a headers field search.');
+                            $this->_exception('Need headers to query when doing a headers field search.');
                         }
 
                         if (empty($val['notsearch'])) {
@@ -1102,7 +1102,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _copy($dest, $options)
     {
-        throw new Horde_Imap_Client_Exception('Copying messages not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('Copying messages not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -1115,7 +1115,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _setQuota($root, $options)
     {
-        throw new Horde_Imap_Client_Exception('IMAP quotas not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP quotas not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -1127,7 +1127,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _getQuota($root)
     {
-        throw new Horde_Imap_Client_Exception('IMAP quotas not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP quotas not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -1139,7 +1139,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _getQuotaRoot($mailbox)
     {
-        throw new Horde_Imap_Client_Exception('IMAP quotas not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP quotas not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -1153,7 +1153,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _setACL($mailbox, $identifier, $options)
     {
-        throw new Horde_Imap_Client_Exception('IMAP ACLs not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP ACLs not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -1165,7 +1165,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _getACL($mailbox)
     {
-        throw new Horde_Imap_Client_Exception('IMAP ACLs not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP ACLs not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -1178,7 +1178,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _listACLRights($mailbox, $identifier)
     {
-        throw new Horde_Imap_Client_Exception('IMAP ACLs not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP ACLs not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -1190,7 +1190,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _getMyACLRights($mailbox)
     {
-        throw new Horde_Imap_Client_Exception('IMAP ACLs not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP ACLs not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /**
@@ -1206,7 +1206,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
      protected function _getMetadata($mailbox, $entries, $options)
      {
-        throw new Horde_Imap_Client_Exception('IMAP metadata not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP metadata not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
      }
 
     /**
@@ -1221,7 +1221,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      */
     protected function _setMetadata($mailbox, $data)
     {
-        throw new Horde_Imap_Client_Exception('IMAP metadata not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
+        $this->_exception('IMAP metadata not supported on POP3 servers.', 'POP3_NOTSUPPORTED');
     }
 
     /* Internal functions. */
@@ -1265,7 +1265,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
 
         if (feof($this->_stream)) {
             $this->logout();
-            throw new Horde_Imap_Client_Exception('POP3 Server closed the connection unexpectedly.', Horde_Imap_Client_Exception::DISCONNECT);
+            $this->_exception('POP3 Server closed the connection unexpectedly.', 'DISCONNECT');
         }
 
         $read = rtrim(fgets($this->_stream));
@@ -1288,7 +1288,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
             break;
 
         case '-ERR':
-            throw new Horde_Imap_Client_Exception('POP3 Error: ' . isset($prefix[1]) ? $prefix[1] : 'no error message');
+            $this->_exception('POP3 Error: ' . isset($prefix[1]) ? $prefix[1] : 'no error message');
 
         case '.':
             $ob['response'] = 'END';
index c694d99..96586af 100644 (file)
@@ -31,7 +31,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
   <api>alpha</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Improved login error reporting (Request #9211).
+ <notes>* Remove static logCallback variable in Horde_Imap_Client_Exception.
+ * Improved login error reporting (Request #9211).
  * Add support for special-use mailboxes (draft-ietf-morg-list-specialuse-02).
  * Add Horde_Imap_Client_Base::validSearchCharset().
  * Add Horde_Imap_Client_Base::fetchFromSectionString().
index 580a2e3..8fafb2c 100644 (file)
@@ -61,9 +61,6 @@ class IMP_Imap
     {
         $this->_serverkey = $serverkey;
 
-        /* Register the logging callback. */
-        Horde_Imap_Client_Exception::$logCallback = array($this, 'logException');
-
         /* Rebuild the Horde_Imap_Client object. */
         $this->_loadImapObject();
 
@@ -142,6 +139,7 @@ class IMP_Imap
             'hostspec' => isset($server['hostspec']) ? $server['hostspec'] : null,
             'id' => empty($server['id']) ? false : $server['id'],
             'lang' => empty($server['lang']) ? false : $server['lang'],
+            'log' => array(__CLASS__, 'logError'),
             'password' => $password,
             'port' => isset($server['port']) ? $server['port'] : null,
             'secure' => isset($server['secure']) ? $server['secure'] : false,
@@ -290,16 +288,6 @@ class IMP_Imap
     }
 
     /**
-     * Logs an exception from Horde_Imap_Client.
-     *
-     * @param object Horde_Imap_Client_Exception $e  The exception object.
-     */
-    public function logException($e)
-    {
-        Horde::logMessage($e, 'ERR');
-    }
-
-    /**
      * Get the namespace list.
      *
      * @return array  An array of namespace information.
@@ -470,4 +458,9 @@ class IMP_Imap
         return $GLOBALS['injector']->getInstance('Horde_Secret')->getKey('imp');
     }
 
+    public function logError($e)
+    {
+        Horde::logMessage($e, 'ERR');
+    }
+
 }