More of the IMP PEAR_Error->Exception rewrite
authorMichael M Slusarz <slusarz@curecanti.org>
Sun, 22 Feb 2009 20:08:13 +0000 (13:08 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 23 Feb 2009 04:25:10 +0000 (21:25 -0700)
25 files changed:
imp/ajax.php
imp/compose-dimp.php
imp/compose-mimp.php
imp/compose.php
imp/config/hooks.php.dist
imp/docs/CHANGES
imp/lib/Compose.php
imp/lib/Crypt/pgp.php
imp/lib/Crypt/smime.php
imp/lib/IMP.php
imp/lib/Maintenance/Task/delete_attachments_monthly.php
imp/lib/Mime/Viewer/itip.php
imp/lib/Mime/Viewer/pgp.php
imp/lib/Mime/Viewer/smime.php
imp/lib/Sentmail.php
imp/lib/Sentmail/sql.php
imp/lib/Session.php
imp/lib/UI/Message.php
imp/mailbox.php
imp/message.php
imp/pgp.php
imp/smime.php
imp/templates/pgp/pgp.html
imp/templates/smime/smime.html
imp/thread.php

index 2adff59..1f99374 100644 (file)
@@ -432,13 +432,13 @@ case 'AddContact':
         break;
     }
 
-    $result = IMP::addAddress($email, $name);
-    if (is_a($result, 'PEAR_Error')) {
-        $notification->push($result, 'horde.error');
-        $result = false;
-    } else {
+    try {
+        IMP::addAddress($email, $name);
         $result = true;
         $notification->push(sprintf(_("%s was successfully added to your address book."), $name ? $name : $email), 'horde.success');
+    } catch (Horde_Exception $e) {
+        $notification->push($e, 'horde.error');
+        $result = false;
     }
     break;
 
index 3c0fe7a..ab26c97 100644 (file)
@@ -255,10 +255,9 @@ case 'forward_attachments':
     break;
 
 case 'resume':
-    $result = $imp_compose->resumeDraft($index . IMP::IDX_SEP . $folder);
-    if (is_a($result, 'PEAR_Error')) {
-        $notification->push($result->getMessage(), 'horde.error');
-    } else {
+    try {
+        $result = $imp_compose->resumeDraft($index . IMP::IDX_SEP . $folder);
+
         if ($result['mode'] == 'html') {
             $show_editor = true;
         }
@@ -268,6 +267,8 @@ case 'resume':
             $identity->setDefault($result['identity']);
         }
         $header = array_merge($header, $result['header']);
+    } catch (IMP_Compose_Exception $e) {
+        $notification->push($e->getMessage(), 'horde.error');
     }
     $get_sig = false;
     break;
index f95fe96..cbc9fed 100644 (file)
@@ -73,10 +73,9 @@ $actionID = Util::getFormData('a');
 switch ($actionID) {
 // 'd' = draft
 case 'd':
-    $result = $imp_compose->resumeDraft($index . IMP::IDX_SEP . $thismailbox);
-    if (is_a($result, 'PEAR_Error')) {
-        $notification->push($result, 'horde.error');
-    } else {
+    try {
+        $result = $imp_compose->resumeDraft($index . IMP::IDX_SEP . $thismailbox);
+
         $msg = $result['msg'];
         $header = array_merge($header, $result['header']);
         if (!is_null($result['identity']) &&
@@ -86,6 +85,8 @@ case 'd':
             $sent_mail_folder = $identity->getValue('sent_mail_folder');
         }
         $resume_draft = true;
+    } catch (IMP_Compose_Exception $e) {
+        $notification->push($e, 'horde.error');
     }
     break;
 
index a43f05a..02f8ee5 100644 (file)
@@ -46,12 +46,14 @@ function &_getIMPContents($index, $mailbox)
     if (empty($index)) {
         return false;
     }
-    $imp_contents = &IMP_Contents::singleton($index . IMP::IDX_SEP . $mailbox);
-    if (is_a($imp_contents, 'PEAR_Error')) {
+
+    try {
+        $imp_contents = &IMP_Contents::singleton($index . IMP::IDX_SEP . $mailbox);
+        return $imp_contents;
+    } catch (Horde_Exception $e) {
         $GLOBALS['notification']->push(_("Could not retrieve the message from the mail server."), 'horde.error');
         return false;
     }
-    return $imp_contents;
 }
 
 
@@ -166,9 +168,10 @@ $imp_compose = &IMP_Compose::singleton(Util::getFormData('composeCache'));
 $imp_compose->pgpAttachPubkey((bool) Util::getFormData('pgp_attach_pubkey'));
 $imp_compose->userLinkAttachments((bool) Util::getFormData('link_attachments'));
 
-$vcard = $imp_compose->attachVCard((bool) Util::getFormData('vcard'), $identity->getValue('fullname'));
-if (is_a($vcard, 'PEAR_Error')) {
-    $notification->push($vcard);
+try {
+    $imp_compose->attachVCard((bool) Util::getFormData('vcard'), $identity->getValue('fullname'));
+} catch (IMP_Compose_Exception $e) {
+    $notification->push($e);
 }
 
 /* Init IMP_UI_Compose:: object. */
@@ -283,10 +286,9 @@ case 'mailto_link':
     break;
 
 case 'draft':
-    $result = $imp_compose->resumeDraft($index . IMP::IDX_SEP . $thismailbox);
-    if (is_a($result, 'PEAR_Error')) {
-        $notification->push($result->getMessage(), 'horde.error');
-    } else {
+    try {
+        $result = $imp_compose->resumeDraft($index . IMP::IDX_SEP . $thismailbox);
+
         if (!is_null($rtemode)) {
             $rtemode = ($result['mode'] == 'html');
         }
@@ -299,6 +301,8 @@ case 'draft':
             $sent_mail_folder = $identity->getValue('sent_mail_folder');
         }
         $resume_draft = true;
+    } catch (IMP_Compose_Exception $e) {
+        $notification->push($e, 'horde.error');
     }
     $get_sig = false;
     break;
@@ -746,15 +750,14 @@ if ($prefs->getValue('use_pgp')) {
             if (!empty($addrs['list'])) {
                 $imp_pgp = &Horde_Crypt::singleton(array('imp', 'pgp'));
                 foreach ($addrs['list'] as $val) {
-                    $res = $imp_pgp->getPublicKey($val);
-                    if (is_a($res, 'PEAR_Error')) {
-                        $notification->push(_("PGP encryption cannot be used by default as public keys cannot be found for all recipients."), 'horde.warning');
-                        $encrypt_options = ($default_encrypt == IMP::PGP_ENCRYPT) ? IMP::ENCRYPT_NONE : IMP::PGP_SIGN;
-                        break;
-                    }
+                    $imp_pgp->getPublicKey($val);
                 }
             }
-        } catch (IMP_Compose_Exception $e) {}
+        } catch (IMP_Compose_Exception $e) {
+        } catch (Horde_Exception $e) {
+            $notification->push(_("PGP encryption cannot be used by default as public keys cannot be found for all recipients."), 'horde.warning');
+            $encrypt_options = ($default_encrypt == IMP::PGP_ENCRYPT) ? IMP::ENCRYPT_NONE : IMP::PGP_SIGN;
+        }
     }
 }
 
index dbaa907..d794299 100644 (file)
 // function should be a valid page within a horde application which will be
 // placed in a "Location" header to redirect the client.  The only parameter
 // is the name of the mailbox which the user has opened.  If an empty string
-// is returned the user is not redirected.
+// is returned the user is not redirected.  Throw a Horde_Exception on error.
 
 // if (!function_exists('_imp_hook_mbox_redirect')) {
 //     function _imp_hook_mbox_redirect($mailbox)
index 0fe896b..8e4a216 100644 (file)
@@ -2,6 +2,7 @@
 v5.0-git
 --------
 
+[mms] All native IMP code now uses exceptions instead of PEAR_Errors.
 [mms] Fix wrong charset on filenames when stripping attachments (Bug #7220).
 [mms] Use effects queue to prevent issues with users clicking on effects
       elements too quickly.
index 190a29a..48c2d2e 100644 (file)
@@ -175,9 +175,6 @@ class IMP_Compose
     {
         /* Set up the base message now. */
         $mime = $this->_createMimeMessage(array(null), $message, $charset, array('html' => $html, 'nofinal' => true, 'noattach' => !$session));
-        if (is_a($mime, 'PEAR_Error')) {
-            return $mime;
-        }
         $base = $mime['msg'];
         $base->isBasePart(true);
 
@@ -268,22 +265,21 @@ class IMP_Compose
      * @param string $index  The IMAP message mailbox/index. The index should
      *                       be in IMP::parseIndicesList() format #1.
      *
-     * @return mixed  PEAR_Error on error, or an array with the following
-     *                keys:
+     * @return mixed  An array with the following keys:
      * <pre>
      * 'msg' - (string) The message text.
      * 'mode' - (string) 'html' or 'text'.
      * 'header' - (array) A list of headers to add to the outgoing message.
      * 'identity' - (integer) The identity used to create the message.
      * </pre>
+     * @throws IMP_Compose_Exception
      */
     public function resumeDraft($index)
     {
         try {
             $contents = IMP_Contents::singleton($index);
         } catch (Horde_Exception $e) {
-            // TODO
-            return $contents;
+            throw new IMP_Compose_Exception($e);
         }
 
         $msg_text = $this->_getMessageText($contents, array('type' => 'draft'));
@@ -387,11 +383,7 @@ class IMP_Compose
         if ($prefs->getValue('use_smime') &&
             in_array($encrypt, array(IMP::SMIME_ENCRYPT, IMP::SMIME_SIGNENC))) {
             foreach ($recip['list'] as $val) {
-                $res = $this->_createMimeMessage(array($val), $body, $charset, $msg_options);
-                if (is_a($res, 'PEAR_Error')) {
-                    return $res;
-                }
-                $send_msgs[] = $res;
+                $send_msgs[] = $this->_createMimeMessage(array($val), $body, $charset, $msg_options);
             }
 
             /* Must target the encryption for the sender before saving message
@@ -404,10 +396,6 @@ class IMP_Compose
             $send_msgs[] = $save_msg = $this->_createMimeMessage($recip['list'], $body, $charset, $msg_options);
         }
 
-        if (is_a($save_msg, 'PEAR_Error')) {
-            return $save_msg;
-        }
-
         /* Initalize a header object for the outgoing message. */
         $headers = new Horde_Mime_Headers();
 
@@ -496,6 +484,10 @@ class IMP_Compose
             }
         }
 
+        if ($conf['sentmail']['driver'] != 'none') {
+            $sentmail = IMP_Sentmail::factory();
+        }
+
         /* Send the messages out now. */
         foreach ($send_msgs as $val) {
             try {
@@ -503,13 +495,16 @@ class IMP_Compose
             } catch (IMP_Compose_Exception $e) {
                 /* Unsuccessful send. */
                 Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
+                if (isset($sentmail)) {
+                    $sentmail->log(empty($opts['reply_type']) ? 'new' : $opts['reply_type'], $headers->getValue('message-id'), $val['recipients'], false);
+                }
+
                 throw new IMP_Compose_Exception(sprintf(_("There was an error sending your message: %s"), $e->getMessage()));
             }
 
             /* Store history information. */
-            if ($conf['sentmail']['driver'] != 'none') {
-                $sentmail = IMP_Sentmail::factory();
-                $sentmail->log(empty($opts['reply_type']) ? 'new' : $opts['reply_type'], $headers->getValue('message-id'), $val['recipients'], !is_a($res, 'PEAR_Error'));
+            if (isset($sentmail)) {
+                $sentmail->log(empty($opts['reply_type']) ? 'new' : $opts['reply_type'], $headers->getValue('message-id'), $val['recipients'], true);
             }
         }
 
@@ -664,9 +659,10 @@ class IMP_Compose
 
         $mail_driver = $this->getMailDriver();
 
-        $res = $message->send($email, $headers, $mail_driver['driver'], $mail_driver['params']);
-        if (is_a($res, 'PEAR_Error')) {
-            throw new IMP_Compose_Exception($res);
+        try {
+            $message->send($email, $headers, $mail_driver['driver'], $mail_driver['params']);
+        } catch (Horde_Mime_Exception $e) {
+            throw new IMP_Compose_Exception($e);
         }
     }
 
@@ -1070,31 +1066,30 @@ class IMP_Compose
             }
 
             /* Do the encryption/signing requested. */
-            switch ($encrypt) {
-            case IMP::PGP_SIGN:
-                $base = $imp_pgp->IMPsignMIMEPart($base);
-                break;
-
-            case IMP::PGP_ENCRYPT:
-            case IMP::PGP_SYM_ENCRYPT:
-                $to_list = empty($options['from'])
-                    ? $to
-                    : array_keys(array_flip(array_merge($to, array($options['from']))));
-                $base = $imp_pgp->IMPencryptMIMEPart($base, $to_list, ($encrypt == IMP::PGP_SYM_ENCRYPT) ? $symmetric_passphrase : null);
-                break;
+            try {
+                switch ($encrypt) {
+                case IMP::PGP_SIGN:
+                    $base = $imp_pgp->IMPsignMIMEPart($base);
+                    break;
 
-            case IMP::PGP_SIGNENC:
-            case IMP::PGP_SYM_SIGNENC:
-                $to_list = empty($options['from'])
-                    ? $to
-                    : array_keys(array_flip(array_merge($to, array($options['from']))));
-                $base = $imp_pgp->IMPsignAndEncryptMIMEPart($base, $to_list, ($encrypt == IMP::PGP_SYM_SIGNENC) ? $symmetric_passphrase : null);
-                break;
-            }
+                case IMP::PGP_ENCRYPT:
+                case IMP::PGP_SYM_ENCRYPT:
+                    $to_list = empty($options['from'])
+                        ? $to
+                        : array_keys(array_flip(array_merge($to, array($options['from']))));
+                    $base = $imp_pgp->IMPencryptMIMEPart($base, $to_list, ($encrypt == IMP::PGP_SYM_ENCRYPT) ? $symmetric_passphrase : null);
+                    break;
 
-            /* Check for errors. */
-            if (is_a($base, 'PEAR_Error')) {
-                throw new IMP_Compose_Exception(_("PGP Error: ") . $base->getMessage(), $base->getCode());
+                case IMP::PGP_SIGNENC:
+                case IMP::PGP_SYM_SIGNENC:
+                    $to_list = empty($options['from'])
+                        ? $to
+                        : array_keys(array_flip(array_merge($to, array($options['from']))));
+                    $base = $imp_pgp->IMPsignAndEncryptMIMEPart($base, $to_list, ($encrypt == IMP::PGP_SYM_SIGNENC) ? $symmetric_passphrase : null);
+                    break;
+                }
+            } catch (Horde_Exception $e) {
+                throw new IMP_Compose_Exception(_("PGP Error: ") . $e->getMessage(), $e->getCode());
             }
         } elseif ($GLOBALS['prefs']->getValue('use_smime') &&
                   in_array($encrypt, array(IMP::SMIME_ENCRYPT, IMP::SMIME_SIGN, IMP::SMIME_SIGNENC))) {
@@ -1111,23 +1106,22 @@ class IMP_Compose
             }
 
             /* Do the encryption/signing requested. */
-            switch ($encrypt) {
-            case IMP::SMIME_SIGN:
-                $base = $imp_smime->IMPsignMIMEPart($base);
-                break;
-
-            case IMP::SMIME_ENCRYPT:
-                $base = $imp_smime->IMPencryptMIMEPart($base, $to[0]);
-                break;
+            try {
+                switch ($encrypt) {
+                case IMP::SMIME_SIGN:
+                    $base = $imp_smime->IMPsignMIMEPart($base);
+                    break;
 
-            case IMP::SMIME_SIGNENC:
-                $base = $imp_smime->IMPsignAndEncryptMIMEPart($base, $to[0]);
-                break;
-            }
+                case IMP::SMIME_ENCRYPT:
+                    $base = $imp_smime->IMPencryptMIMEPart($base, $to[0]);
+                    break;
 
-            /* Check for errors. */
-            if (is_a($base, 'PEAR_Error')) {
-                throw new IMP_Compose_Exception(_("S/MIME Error: ") . $base->getMessage(), $base->getCode());
+                case IMP::SMIME_SIGNENC:
+                    $base = $imp_smime->IMPsignAndEncryptMIMEPart($base, $to[0]);
+                    break;
+                }
+            } catch (Horde_Exception $e) {
+                throw new IMP_Compose_Exception(_("S/MIME Error: ") . $e->getMessage(), $e->getCode());
             }
         }
 
@@ -1963,17 +1957,14 @@ class IMP_Compose
     /**
      * Adds attachments from the IMP_Contents object to the message.
      *
-     * @param IMP_Contents &$contents  An IMP_Contents object.
-     * @param array $options           Additional options:
+     * @param IMP_Contents $contents  An IMP_Contents object.
+     * @param array $options          Additional options:
      * <pre>
      * 'notify' - (boolean) Add notification message on errors?
      * 'skip' - (array) Skip these MIME IDs.
      * </pre>
-     *
-     * @return array  An array of PEAR_Error object on error.
-     *                An empty array if successful.
      */
-    public function attachFilesFromMessage(&$contents, $options = array())
+    public function attachFilesFromMessage($contents, $options = array())
     {
         $mime_message = $contents->getMIMEMessage();
         $dl_list = array_slice(array_keys($mime_message->contentTypeMap()), 1);
@@ -2284,7 +2275,7 @@ class IMP_Compose
      * @param boolean $attach  True if vCard should be attached.
      * @param string $name     The user's name.
      *
-     * @return mixed  True on success, PEAR_Error on error.
+     * @throws IMP_Compose_Exception
      */
     public function attachVCard($attach, $name)
     {
@@ -2294,7 +2285,7 @@ class IMP_Compose
 
         $vcard = $GLOBALS['registry']->call('contacts/ownVCard');
         if (is_a($vcard, 'PEAR_Error')) {
-            return $vcard;
+            throw new IMP_Compose_Exception($vcard);
         }
 
         $part = new Horde_Mime_Part();
@@ -2303,8 +2294,6 @@ class IMP_Compose
         $part->setContents($vcard);
         $part->setName((strlen($name) ? $name : 'vcard') . '.vcf');
         $this->_attachVCard = $part;
-
-        return true;
     }
 
     /**
index 19a3e09..54214b8 100644 (file)
@@ -19,7 +19,7 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
     /**
      * Constructor
      */
-    function __construct()
+    public function __construct()
     {
         parent::__construct(array(
             'program' => $GLOBALS['conf']['utils']['gnupg'],
@@ -36,14 +36,14 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
      * @param string $comment     See Horde_Crypt_pgp::
      * @param string $keylength   See Horde_Crypt_pgp::
      *
-     * @return PEAR_Error  Returns PEAR_Error object on error.
+     * @throws Horde_Exception
      */
     public function generatePersonalKeys($name, $email, $passphrase,
                                          $comment = '', $keylength = 1024)
     {
         $keys = $this->generateKey($name, $email, $passphrase, $comment, $keylength);
         if (is_a($keys, 'PEAR_Error')) {
-            return $keys;
+            throw new Horde_Exception($keys);
         }
 
         /* Store the keys in the user's preferences. */
@@ -128,16 +128,18 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
             /* Check to make sure the key does not already exist in ANY
              * address book and remove the id from the key_info for a correct
              * output. */
-            $result = $this->getPublicKey($sig['email'], null, false);
-            if (!is_a($result, 'PEAR_Error') && !empty($result)) {
-                unset($key_info['signature'][$id]);
-                continue;
-            }
+            try {
+                $result = $this->getPublicKey($sig['email'], null, false);
+                if (!empty($result)) {
+                    unset($key_info['signature'][$id]);
+                    continue;
+                }
+            } catch (Horde_Exception $e) {}
 
             /* Add key to the user's address book. */
             $result = $GLOBALS['registry']->call('contacts/addField', array($sig['email'], $sig['name'], self::PUBKEY_FIELD, $public_key, $GLOBALS['prefs']->getValue('add_source')));
             if (is_a($result, 'PEAR_Error')) {
-                return $result;
+                throw new Horde_Exception($result);
             }
         }
 
@@ -157,8 +159,8 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
      * @param boolean $server      Whether to check the publick key servers for
      *                             the key.
      *
-     * @return string  The PGP public key requested. Returns PEAR_Error object
-     *                 on error.
+     * @return string  The PGP public key requested.
+     * @throws Horde_Exception
      */
     public function getPublicKey($address, $fingerprint = null, $server = true)
     {
@@ -190,12 +192,12 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
 
         /* Try retrieving via a PGP public keyserver. */
         if ($server && is_a($result, 'PEAR_Error')) {
-            $result = $this->getFromPublicKeyserver($fingerprint, $address);
+            $this->getFromPublicKeyserver($fingerprint, $address);
         }
 
         /* Return now, if no public key found at all. */
         if (is_a($result, 'PEAR_Error')) {
-            return $result;
+            throw new Horde_Exception($result);
         }
 
         /* If more than one public key is returned, just return the first in
@@ -217,13 +219,22 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
     /**
      * Retrieves all public keys from a user's address book(s).
      *
-     * @return array  All PGP public keys available. Returns PEAR_Error object
-     *                on error.
+     * @return array  All PGP public keys available.
+     * @throws Horde_Exception
      */
     public function listPublicKeys()
     {
         $params = IMP_Compose::getAddressSearchParams();
-        return (empty($params['sources'])) ? array() : $GLOBALS['registry']->call('contacts/getAllAttributeValues', array(self::PUBKEY_FIELD, $params['sources']));
+        if (empty($params['sources'])) {
+            return array();
+        }
+
+        $res = $GLOBALS['registry']->call('contacts/getAllAttributeValues', array(self::PUBKEY_FIELD, $params['sources']));
+        if (is_a($res, 'PEAR_Error')) {
+            throw new Horde_Exception($res);
+        }
+
+        return $res;
     }
 
     /**
@@ -231,12 +242,17 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
      *
      * @param string $email  The e-mail address to delete.
      *
-     * @return PEAR_Error  Returns PEAR_Error object on error.
+     * @throws Horde_Exception
      */
     public function deletePublicKey($email)
     {
         $params = IMP_Compose::getAddressSearchParams();
-        return $GLOBALS['registry']->call('contacts/deleteField', array($email, self::PUBKEY_FIELD, $params['sources']));
+        $res = $GLOBALS['registry']->call('contacts/deleteField', array($email, self::PUBKEY_FIELD, $params['sources']));
+        if (is_a($res, 'PEAR_Error')) {
+            throw new Horde_Exception($res);
+        }
+
+        return $res;
     }
 
     /**
@@ -246,6 +262,7 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
      * @param string $address      The email address of the requested key.
      *
      * @return string  See Horde_Crypt_pgp::getPublicKeyserver()
+     * @throws Horde_Exception
      */
     public function getFromPublicKeyserver($fingerprint, $address = null)
     {
@@ -258,6 +275,7 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
      * @param string $pubkey  The PGP public key.
      *
      * @return string  See Horde_Crypt_pgp::putPublicKeyserver()
+     * @throws Horde_Exception
      */
     public function sendToPublicKeyserver($pubkey)
     {
@@ -273,6 +291,7 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
      *
      * @return string  See Horde_Crypt_pgp::getPublicKeyserver() -or-
      *                     Horde_Crypt_pgp::putPublicKeyserver().
+     * @throws Horde_Exception
      */
     protected function _keyserverConnect($data, $method, $additional = null)
     {
@@ -284,16 +303,16 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
                 foreach ($conf['utils']['gnupg_keyserver'] as $server) {
                     $result = $this->getPublicKeyserver($data, $server, $timeout, $additional);
                     if (!is_a($result, 'PEAR_Error')) {
-                        return $result;
+                        throw new Horde_Exception($result);
                     }
                 }
                 return $result;
             } else {
                 return $this->putPublicKeyserver($data, $conf['utils']['gnupg_keyserver'][0], $timeout);
             }
-        } else {
-            return PEAR::raiseError(_("Public PGP keyserver support has been disabled."), 'horde.warning');
         }
+
+        throw new Horde_Exception(_("Public PGP keyserver support has been disabled."), 'horde.warning');
     }
 
     /**
@@ -305,6 +324,7 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
      *
      * @return string  See Horde_Crypt_pgp::decryptSignature()  -or-
      *                     Horde_Crypt_pgp::decryptDetachedSignature().
+     * @throws Horde_Exception
      */
     public function verifySignature($text, $address, $signature = '')
     {
@@ -321,9 +341,6 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
         }
 
         $public_key = $this->getPublicKey($address, $fingerprint);
-        if (is_a($public_key, 'PEAR_Error')) {
-            return $public_key;
-        }
 
         if (empty($signature)) {
             $options = array('type' => 'signature');
@@ -333,7 +350,12 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
         $options['pubkey'] = $public_key;
 
         /* decrypt() returns a PEAR_Error object on error. */
-        return $this->decrypt($text, $options);
+        $res = $this->decrypt($text, $options);
+        if (is_a($res, 'PEAR_Error')) {
+            throw new Horde_Exception($res);
+        }
+
+        return $res;
     }
 
     /**
@@ -345,22 +367,30 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
      * @param boolean $passphrase  If $type is 'personal' or 'symmetrical',
      *                             the passphrase to use.
      *
-     * @return string  The decrypted message. Returns PEAR_Error object on
-     *                 error.
+     * @return string  The decrypted message.
+     * @throws Horde_Exception
      */
     public function decryptMessage($text, $type, $passphrase = null)
     {
-        /* decrypt() returns a PEAR_Error object on error. */
         switch ($type) {
         case 'literal':
-            return $this->decrypt($text, array('type' => 'message', 'no_passphrase' => true));
+            $res = $this->decrypt($text, array('type' => 'message', 'no_passphrase' => true));
+            break;
 
         case 'symmetric':
-            return $this->decrypt($text, array('type' => 'message', 'passphrase' => $passphrase));
+            $res = $this->decrypt($text, array('type' => 'message', 'passphrase' => $passphrase));
+            break;
 
         case 'personal':
-            return $this->decrypt($text, array('type' => 'message', 'pubkey' => $this->getPersonalPublicKey(), 'privkey' => $this->getPersonalPrivateKey(), 'passphrase' => $passphrase));
+            $res = $this->decrypt($text, array('type' => 'message', 'pubkey' => $this->getPersonalPublicKey(), 'privkey' => $this->getPersonalPrivateKey(), 'passphrase' => $passphrase));
+            break;
+        }
+
+        if (is_a($res, 'PEAR_Error')) {
+            throw new Horde_Exception($res);
         }
+
+        return $res;
     }
 
     /**
@@ -482,7 +512,7 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
      *                           encrypting. If null, uses the personal key.
      *
      * @return array  The list of parameters needed by encrypt().
-     *                Returns PEAR_Error on error.
+     * @throws Horde_Exception
      */
     protected function _encryptParameters($addresses, $symmetric)
     {
@@ -500,11 +530,7 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
             $key_addr = array_pop($addrOb);
 
             /* Get the public key for the address. */
-            $public_key = $this->getPublicKey($key_addr);
-            if (is_a($public_key, 'PEAR_Error')) {
-                return $public_key;
-            }
-            $addr_list[$key_addr] = $public_key;
+            $addr_list[$key_addr] = $this->getPublicKey($key_addr);
         }
 
         return array('recips' => $addr_list);
@@ -515,12 +541,16 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
      *
      * @param Horde_Mime_Part $mime_part  The object to sign.
      *
-     * @return Horde_Mime_Part  See Horde_Crypt_pgp::signMIMEPart(). Returns
-     *                          PEAR_Error object on error.
+     * @return Horde_Mime_Part  See Horde_Crypt_pgp::signMIMEPart().
+     * @throws Horde_Exception
      */
     public function IMPsignMIMEPart($mime_part)
     {
-        return $this->signMIMEPart($mime_part, $this->_signParameters());
+        $res = $this->signMIMEPart($mime_part, $this->_signParameters());
+        if (is_a($res, 'PEAR_Error')) {
+            throw new Horde_Exception($res);
+        }
+        return $res;
     }
 
     /**
@@ -533,17 +563,17 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
      *                                    use for encrypting. If null, uses
      *                                    the personal key.
      *
-     * @return Horde_Mime_Part  See Horde_Crypt_pgp::encryptMIMEPart(). Returns
-     *                    PEAR_Error object on error.
+     * @return Horde_Mime_Part  See Horde_Crypt_pgp::encryptMIMEPart().
+     * @throws Horde_Exception
      */
     public function IMPencryptMIMEPart($mime_part, $addresses,
                                        $symmetric = null)
     {
-        $params = $this->_encryptParameters($addresses, $symmetric);
-        if (is_a($params, 'PEAR_Error')) {
-            return $params;
+        $res = $this->encryptMIMEPart($mime_part, $this->_encryptParameters($addresses, $symmetric));
+        if (is_a($res, 'PEAR_Error')) {
+            throw new Horde_Exception($res);
         }
-        return $this->encryptMIMEPart($mime_part, $params);
+        return $res;
     }
 
     /**
@@ -557,16 +587,16 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
      *                                    the personal key.
      *
      * @return Horde_Mime_Part  See Horde_Crypt_pgp::signAndencryptMIMEPart().
-     *                          Returns PEAR_Error object on error.
+     * @throws Horde_Exception
      */
     public function IMPsignAndEncryptMIMEPart($mime_part, $addresses,
                                               $symmetric = null)
     {
-        $encrypt_params = $this->_encryptParameters($addresses, $symmetric);
-        if (is_a($encrypt_params, 'PEAR_Error')) {
-            return $encrypt_params;
+        $res = $this->signAndEncryptMIMEPart($mime_part, $this->_signParameters(), $this->_encryptParameters($addresses, $symmetric));
+        if (is_a($res, 'PEAR_Error')) {
+            throw new Horde_Exception($res);
         }
-        return $this->signAndEncryptMIMEPart($mime_part, $this->_signParameters(), $encrypt_params);
+        return $res;
     }
 
     /**
index 491a3a5..450a058 100644 (file)
@@ -19,7 +19,7 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
     /**
      * Constructor.
      */
-    function __construct()
+    public function __construct()
     {
         parent::__construct(array('temp' => Horde::getTempDir()));
     }
@@ -138,7 +138,7 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
      * @param string $address  The e-mail address of the recipient.
      *
      * @return array  The list of parameters needed by encrypt().
-     *                Returns PEAR_Error object on error.
+     * @throws Horde_Exception
      */
     protected function _encryptParameters($address)
     {
@@ -147,9 +147,6 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
         $key_addr = array_pop($addrOb);
 
         $public_key = $this->getPublicKey($key_addr);
-        if (is_a($public_key, 'PEAR_Error')) {
-            return $public_key;
-        }
 
         return array(
             'pubkey' => $public_key,
@@ -164,7 +161,7 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
      * @param string $address  The e-mail address to search for.
      *
      * @return string  The S/MIME public key requested.
-     *                 Returns PEAR_Error object on error.
+     * @throws Horde_Exception
      */
     public function getPublicKey($address)
     {
@@ -179,6 +176,7 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
             if (!empty($personal_pubkey) && $identity->hasAddress($address)) {
                 return $personal_pubkey;
             }
+            throw new Horde_Exception($key);
         }
 
         /* If more than one public key is returned, just return the first in
@@ -191,14 +189,20 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
      * Retrieves all public keys from a user's address book(s).
      *
      * @return array  All PGP public keys available.
-     *                Returns PEAR_Error object on error.
+     * @throws Horde_Exception
      */
     public function listPublicKeys()
     {
         $params = IMP_Compose::getAddressSearchParams();
-        return (empty($params['sources']))
-            ? array()
-            : $GLOBALS['registry']->call('contacts/getAllAttributeValues', array(self::PUBKEY_FIELD, $params['sources']));
+        if (empty($params['sources'])) {
+            return array();
+        }
+        $res = $GLOBALS['registry']->call('contacts/getAllAttributeValues', array(self::PUBKEY_FIELD, $params['sources']));
+        if (is_a($res, 'PEAR_Error')) {
+            throw new Horde_Exception($res);
+        }
+
+        return $res;
     }
 
     /**
@@ -206,12 +210,15 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
      *
      * @param string $email  The e-mail address to delete.
      *
-     * @return PEAR_Error  Returns PEAR_Error object on error.
+     * @throws Horde_Exception
      */
     public function deletePublicKey($email)
     {
         $params = IMP_Compose::getAddressSearchParams();
-        return $GLOBALS['registry']->call('contacts/deleteField', array($email, self::PUBKEY_FIELD, $params['sources']));
+        $res = $GLOBALS['registry']->call('contacts/deleteField', array($email, self::PUBKEY_FIELD, $params['sources']));
+        if (is_a($res, 'PEAR_Error')) {
+            throw new Horde_Exception($res);
+        }
     }
 
     /**
@@ -250,12 +257,17 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
      * @param string $text  The text to decrypt.
      *
      * @return string  See Horde_Crypt_smime::decrypt().
-     *                 Returns PEAR_Error object on error.
+     * @throws Horde_Exception
      */
     public function decryptMessage($text)
     {
         /* decrypt() returns a PEAR_Error object on error. */
-        return $this->decrypt($text, array('type' => 'message', 'pubkey' => $this->getPersonalPublicKey(), 'privkey' => $this->getPersonalPrivateKey(), 'passphrase' => $this->getPassphrase()));
+        $res = $this->decrypt($text, array('type' => 'message', 'pubkey' => $this->getPersonalPublicKey(), 'privkey' => $this->getPersonalPrivateKey(), 'passphrase' => $this->getPassphrase()));
+        if (is_a($res, 'PEAR_Error')) {
+            throw new Horde_Exception($res);
+        }
+
+        return $res;
     }
 
     /**
@@ -341,15 +353,17 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
      * @param mixed $to_address     The e-mail address of the key to use for
      *                              encryption.
      *
-     * @return MIME_Part  See Horde_Crypt_smime::encryptMIMEPart(). Returns
-     *                    PEAR_Error on error.
+     * @return MIME_Part  See Horde_Crypt_smime::encryptMIMEPart().
+     * @throws Horde_Exception
      */
     public function IMPencryptMIMEPart($mime_part, $to_address)
     {
-        $params = $this->_encryptParameters($to_address);
-        return is_a($params, 'PEAR_Error')
-            ? $params
-            : $this->encryptMIMEPart($mime_part, $params);
+        $res = $this->encryptMIMEPart($mime_part, $this->_encryptParameters($to_address));
+        if (is_a($res, 'PEAR_Error')) {
+            throw new Horde_Exception($res);
+        }
+
+        return $res;
     }
 
     /**
@@ -357,12 +371,17 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
      *
      * @param MIME_Part $mime_part  The MIME_Part object to sign.
      *
-     * @return MIME_Part  See Horde_Crypt_smime::signMIMEPart(). Returns
-     *                    PEAR_Error on error.
+     * @return MIME_Part  See Horde_Crypt_smime::signMIMEPart().
+     * @throws Horde_Exception
      */
     public function IMPsignMIMEPart($mime_part)
     {
-        return $this->signMIMEPart($mime_part, $this->_signParameters());
+        $res = $this->signMIMEPart($mime_part, $this->_signParameters());
+        if (is_a($res, 'PEAR_Error')) {
+            throw new Horde_Exception($res);
+        }
+
+        return $res;
     }
 
     /**
@@ -373,15 +392,16 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
      *                              encryption.
      *
      * @return MIME_Part  See Horde_Crypt_smime::signAndencryptMIMEPart().
-     *                    Returns PEAR_Error on error.
+     * @throws Horde_Exception
      */
     public function IMPsignAndEncryptMIMEPart($mime_part, $to_address)
     {
-        $encrypt_params = $this->_encryptParameters($to_address);
-        if (is_a($encrypt_params, 'PEAR_Error')) {
-            return $encrypt_params;
+        $res = $this->signAndEncryptMIMEPart($mime_part, $this->_signParameters(), $this->_encryptParameters($to_address));
+        if (is_a($res, 'PEAR_Error')) {
+            throw new Horde_Exception($res);
         }
-        return $this->signAndEncryptMIMEPart($mime_part, $this->_signParameters(), $encrypt_params);
+
+        return $res;
     }
 
     /**
@@ -392,13 +412,13 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
      * @param string $password  The password of the PKCS 12 file.
      * @param string $pkpass    The password to use to encrypt the private key.
      *
-     * @return boolean  True on success, PEAR_Error on error.
+     * @throws Horde_Exception
      */
     public function addFromPKCS12($pkcs12, $password, $pkpass = null)
     {
         $openssl = $this->checkForOpenSSL();
         if (is_a($openssl, 'PEAR_Error')) {
-            return $openssl;
+            throw new Horde_Exception($openssl);
         }
 
         $sslpath = (empty($GLOBALS['conf']['utils']['openssl_binary'])) ? null : $GLOBALS['conf']['utils']['openssl_binary'];
@@ -408,14 +428,12 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
         }
         $res = $this->parsePKCS12Data($pkcs12, $params);
         if (is_a($res, 'PEAR_Error')) {
-            return $res;
+            throw new Horde_Exception($res);
         }
 
         $this->addPersonalPrivateKey($res->private);
         $this->addPersonalPublicKey($res->public);
         $this->addAdditionalCert($res->certs);
-
-        return true;
     }
 
     /**
@@ -424,12 +442,20 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
      * @param string $data  The signed S/MIME data.
      *
      * @return string  The contents embedded in the signed data.
-     *                 Returns PEAR_Error on error.
+     * @throws Horde_Exception
      */
     public function extractSignedContents($data)
     {
-        $sslpath = (empty($GLOBALS['conf']['utils']['openssl_binary'])) ? null : $GLOBALS['conf']['utils']['openssl_binary'];
-        return parent::extractSignedContents($data, $sslpath);
+        $sslpath = empty($GLOBALS['conf']['utils']['openssl_binary'])
+            ? null
+            : $GLOBALS['conf']['utils']['openssl_binary'];
+
+        $res = parent::extractSignedContents($data, $sslpath);
+        if (is_a($res, 'PEAR_Error')) {
+            throw new Horde_Exception($res);
+        }
+
+        return $res;
     }
 
 }
index 6234f1a..faa3c85 100644 (file)
@@ -159,6 +159,7 @@ class IMP
      * @param string $newName     The contact's name.
      *
      * @return string  A link or message to show in the notification area.
+     * @throws Horde_Exception
      */
     static public function addAddress($newAddress, $newName)
     {
@@ -172,17 +173,18 @@ class IMP
                                   array(array('name' => $newName, 'email' => $newAddress),
                                         'array', $prefs->getValue('add_source')));
         if (is_a($result, 'PEAR_Error')) {
-            return $result;
+            throw new Horde_Exception($result);
         }
 
         $contact_link = $registry->link('contacts/show', array('uid' => $result, 'source' => $prefs->getValue('add_source')));
-        if (!empty($contact_link) && !is_a($contact_link, 'PEAR_Error')) {
-            $contact_link = Horde::link(Horde::url($contact_link), sprintf(_("Go to address book entry of \"%s\""), $newName)) . @htmlspecialchars($newName, ENT_COMPAT, NLS::getCharset()) . '</a>';
-        } else {
-            $contact_link = @htmlspecialchars($newName, ENT_COMPAT, NLS::getCharset());
-        }
 
-        return $contact_link;
+        $old_error = error_reporting(0);
+        $escapeName = htmlspecialchars($newName, ENT_COMPAT, NLS::getCharset());
+        error_reporting($old_error);
+
+        return (!empty($contact_link) && !is_a($contact_link, 'PEAR_Error'))
+            ? Horde::link(Horde::url($contact_link), sprintf(_("Go to address book entry of \"%s\""), $newName)) . $escapeName . '</a>'
+            : $escapeName;
     }
 
     /**
index 9c57111..81e0ec8 100644 (file)
@@ -15,7 +15,7 @@ class Maintenance_Task_delete_attachments_monthly extends Maintenance_Task
      *
      * @return boolean  Whether any old attachments were deleted.
      */
-    function doMaintenance()
+    public function doMaintenance()
     {
         /* Find the UNIX timestamp of the last second that we will not
          * purge. */
@@ -46,7 +46,7 @@ class Maintenance_Task_delete_attachments_monthly extends Maintenance_Task
      * @return string  Description of what the operation is going to do during
      *                 this login.
      */
-    function describeMaintenance()
+    public function describeMaintenance()
     {
         return sprintf(_("All old linked attachments more than %s months old will be deleted."), $GLOBALS['prefs']->getValue('delete_attachments_monthly_keep'));
     }
index cccbd50..7256b84 100644 (file)
@@ -337,13 +337,13 @@ class IMP_Horde_Mime_Viewer_itip extends Horde_Mime_Viewer_Driver
 
                     // Send the reply.
                     $mail_driver = IMP_Compose::getMailDriver();
-                    $status = $mime->send($organizerEmail, $msg_headers,
-                                          $mail_driver['driver'],
-                                          $mail_driver['params']);
-                    if (is_a($status, 'PEAR_Error')) {
-                        $msgs[] = array('error', sprintf(_("Error sending reply: %s."), $status->getMessage()));
-                    } else {
+                    try {
+                        $mime->send($organizerEmail, $msg_headers,
+                                    $mail_driver['driver'],
+                                    $mail_driver['params']);
                         $msgs[] = array('success', _("Reply Sent."));
+                    } catch (Horde_Mime_Exception $e) {
+                        $msgs[] = array('error', sprintf(_("Error sending reply: %s."), $e->getMessage()));
                     }
                 } else {
                     $msgs[] = array('warning', _("This action is not supported."));
@@ -439,13 +439,13 @@ class IMP_Horde_Mime_Viewer_itip extends Horde_Mime_Viewer_Driver
 
                     // Send the reply.
                     $mail_driver = IMP_Compose::getMailDriver();
-                    $status = $mime->send($organizerEmail, $msg_headers,
-                                          $mail_driver['driver'],
-                                          $mail_driver['params']);
-                    if (is_a($status, 'PEAR_Error')) {
-                        $msgs[] = array('error', sprintf(_("Error sending reply: %s."), $status->getMessage()));
-                    } else {
+                    try {
+                        $mime->send($organizerEmail, $msg_headers,
+                                    $mail_driver['driver'],
+                                    $mail_driver['params']);
                         $msgs[] = array('success', _("Reply Sent."));
+                    } catch (Horde_Mime_Exception $e) {
+                        $msgs[] = array('error', sprintf(_("Error sending reply: %s."), $e->getMessage()));
                     }
                 } else {
                     $msgs[] = array('warning', _("Invalid Action selected for this component."));
index c9b5d47..b23ac3a 100644 (file)
@@ -222,16 +222,16 @@ class IMP_Horde_Mime_Viewer_pgp extends Horde_Mime_Viewer_Driver
             }
         }
 
-        if (!is_null($symmetric_pass)) {
-            $decrypted_data = $this->_imppgp->decryptMessage($encrypted_data, 'symmetric', $symmetric_pass);
-        } elseif (!is_null($personal_pass)) {
-            $decrypted_data = $this->_imppgp->decryptMessage($encrypted_data, 'personal', $personal_pass);
-        } else {
-            $decrypted_data = $this->_imppgp->decryptMessage($encrypted_data, 'literal');
-        }
-
-        if (is_a($decrypted_data, 'PEAR_Error')) {
-            $status[] = _("The message below does not appear to be a valid PGP encrypted message. Error: ") . $decrypted_data->getMessage();
+        try {
+            if (!is_null($symmetric_pass)) {
+                $decrypted_data = $this->_imppgp->decryptMessage($encrypted_data, 'symmetric', $symmetric_pass);
+            } elseif (!is_null($personal_pass)) {
+                $decrypted_data = $this->_imppgp->decryptMessage($encrypted_data, 'personal', $personal_pass);
+            } else {
+                $decrypted_data = $this->_imppgp->decryptMessage($encrypted_data, 'literal');
+            }
+        } catch (Horde_Exception $e) {
+            $status[] = _("The message below does not appear to be a valid PGP encrypted message. Error: ") . $e->getMessage();
             if (!is_null($symmetric_pass)) {
                 $this->_imppgp->unsetPassphrase('symmetric', $this->_getSymmetricID());
                 return $this->_getEmbeddedMimeParts();
@@ -324,22 +324,20 @@ class IMP_Horde_Mime_Viewer_pgp extends Horde_Mime_Viewer_Driver
 
             /* Check for the 'x-imp-pgp-signature' param. This is set by the
              * plain driver when parsing PGP armor text. */
-            if ($sig_part->getContentTypeParameter('x-imp-pgp-signature')) {
-                $sig_result = $this->_imppgp->verifySignature($signed_data, $this->_address);
-            } else {
-                $sig_result = $this->_imppgp->verifySignature($signed_data, $this->_address, $sig_part->getContents());
-            }
-
             $graphicsdir = $GLOBALS['registry']->getImageDir('horde');
+            try {
+                $sig_result = $sig_part->getContentTypeParameter('x-imp-pgp-signature')
+                    ? $this->_imppgp->verifySignature($signed_data, $this->_address)
+                    : $this->_imppgp->verifySignature($signed_data, $this->_address, $sig_part->getContents());
+                }
 
-            if (is_a($sig_result, 'PEAR_Error')) {
-                $icon = Horde::img('alerts/error.png', _("Error"), null, $graphicsdir);
-                $sig_result = $sig_result->getMessage();
-            } else {
                 $icon = Horde::img('alerts/success.png', _("Success"), null, $graphicsdir);
                 if (empty($sig_result)) {
                    $sig_result = _("The message below has been verified.");
                 }
+            } catch (Horde_Exception $e) {
+                $icon = Horde::img('alerts/error.png', _("Error"), null, $graphicsdir);
+                $sig_result = $e->getMessage();
             }
 
             require_once 'Horde/Text/Filter.php';
index 2e3a138..65226da 100644 (file)
@@ -153,9 +153,11 @@ class IMP_Horde_Mime_Viewer_smime extends Horde_Mime_Viewer_Driver
         }
 
         $raw_text = $GLOBALS['imp_imap']->utils->removeBareNewlines($this->_params['contents']->getBodyPart($this->_mimepart->getMimeId(), array('mimeheaders' => true)));
-        $decrypted_data = $this->_impsmime->decryptMessage($raw_text);
-        if (is_a($decrypted_data, 'PEAR_Error')) {
-            $status[] = $decrypted_data->getMessage();
+
+        try {
+            $decrypted_data = $this->_impsmime->decryptMessage($raw_text);
+        } catch (Horde_Exception $e) {
+            $status[] = $e->getMessage();
             return null;
         }
 
@@ -255,12 +257,12 @@ class IMP_Horde_Mime_Viewer_smime extends Horde_Mime_Viewer_Driver
 
         $subpart = $this->_params['contents']->getMIMEPart($sig_id);
         if (!isset($subpart)) {
-            $msg_data = $this->_impsmime->extractSignedContents($raw_text);
-            if (is_a($msg_data, 'PEAR_Error')) {
-                $this->_status[] = $msg_data->getMessage();
-                $subpart = $this->_mimepart;
-            } else {
+            try {
+                $msg_data = $this->_impsmime->extractSignedContents($raw_text);
                 $subpart = Horde_Mime_Part::parseMessage($msg_data);
+            } catch (Horde_Exception $e) {
+                $this->_status[] = $e->getMessage();
+                $subpart = $this->_mimepart;
             }
         }
 
index 1e5bde5..03e63c2 100644 (file)
 class IMP_Sentmail
 {
     /**
+     * Hash containing configuration parameters.
+     *
+     * @var array
+     */
+    protected $_params = array();
+
+    /**
      * Attempts to return a concrete IMP_Sentmail instance based on $driver.
      *
      * @param string $driver  The type of the concrete IMP_Sentmail subclass
@@ -38,19 +45,24 @@ class IMP_Sentmail
 
         $driver = basename($driver);
         $class = 'IMP_Sentmail_' . $driver;
-        if (!class_exists($class)) {
-            @include dirname(__FILE__) . '/Sentmail/' . $driver . '.php';
-        }
 
         if (class_exists($class)) {
-            $sentmail = new $class($params);
-            $result = $sentmail->initialize();
-            if (!is_a($result, 'PEAR_Error')) {
-                return $sentmail;
-            }
+            try {
+                return new $class($params);
+            } catch (Horde_Exception $e) {}
         }
 
-        return new IMP_Sentmail();
+        return new IMP_Sentmail($params);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @throws Horde_Exception
+     */
+    public function __construct($params = array())
+    {
+        $this->_params = $params;
     }
 
     /**
@@ -99,6 +111,7 @@ class IMP_Sentmail
      *                        A value of null returns all message types.
      *
      * @return array  A list with the $limit most favourite recipients.
+     * @throws Horde_Exception
      */
     public function favouriteRecipients($limit,
                                         $filter = array('new', 'forward', 'reply', 'redirect'))
@@ -114,6 +127,7 @@ class IMP_Sentmail
      *                        user?
      *
      * @return integer  The number of recipients in the given time period.
+     * @throws Horde_Exception
      */
     public function numberOfRecipients($hours, $user = false)
     {
@@ -136,6 +150,7 @@ class IMP_Sentmail
      *
      * @param integer $before  Unix timestamp before that all log entries
      *                         should be deleted.
+     * @throws Horde_Exception
      */
     protected function _deleteOldEntries($before)
     {
index 3de53ca..e9b5000 100644 (file)
 class IMP_Sentmail_sql extends IMP_Sentmail
 {
     /**
-     * Hash containing connection parameters.
-     *
-     * @var array
-     */
-    protected $_params = array();
-
-    /**
      * Handle for the current database connection.
      *
      * @var DB
@@ -42,10 +35,43 @@ class IMP_Sentmail_sql extends IMP_Sentmail
      * Constructor.
      *
      * @param array $params  A hash containing connection parameters.
+     *
+     * @throws Horde_Exception
      */
     function __construct($params = array())
     {
-        $this->_params = $params;
+        parent::__construct($params);
+
+        Horde::assertDriverConfig($this->_params, 'storage', array('phptype', 'table'));
+
+        if (!isset($this->_params['database'])) {
+            $this->_params['database'] = '';
+        }
+        if (!isset($this->_params['username'])) {
+            $this->_params['username'] = '';
+        }
+        if (!isset($this->_params['hostspec'])) {
+            $this->_params['hostspec'] = '';
+        }
+
+        /* Connect to the SQL server using the supplied parameters. */
+        require_once 'DB.php';
+        $this->_db = DB::connect($this->_params,
+                                 array('persistent' => !empty($this->_params['persistent']),
+                                       'ssl' => !empty($this->_params['ssl'])));
+        if (is_a($this->_db, 'PEAR_Error')) {
+            throw new Horde_Exception($this->_db);
+        }
+
+        /* Set DB portability options. */
+        switch ($this->_db->phptype) {
+        case 'mssql':
+            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
+            break;
+
+        default:
+            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+        }
     }
 
     /**
@@ -91,6 +117,7 @@ class IMP_Sentmail_sql extends IMP_Sentmail
      *                        A value of null returns all message types.
      *
      * @return array  A list with the $limit most favourite recipients.
+     * @throws Horde_Exception
      */
     public function favouriteRecipients($limit,
                                         $filter = array('new', 'forward', 'reply', 'redirect'))
@@ -116,7 +143,7 @@ class IMP_Sentmail_sql extends IMP_Sentmail
         $recipients = $this->_db->getAll($query);
         if (is_a($recipients, 'PEAR_Error')) {
             Horde::logMessage($recipients, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return $recipients;
+            throw new Horde_Exception($recipients);
         }
 
         /* Extract email addresses. */
@@ -136,6 +163,7 @@ class IMP_Sentmail_sql extends IMP_Sentmail
      *                        user?
      *
      * @return integer  The number of recipients in the given time period.
+     * @throws Horde_Exception
      */
     public function numberOfRecipients($hours, $user = false)
     {
@@ -154,6 +182,7 @@ class IMP_Sentmail_sql extends IMP_Sentmail
         $recipients = $this->_db->getOne($query, array(time() - $hours * 3600));
         if (is_a($recipients, 'PEAR_Error')) {
             Horde::logMessage($recipients, __FILE__, __LINE__, PEAR_LOG_ERR);
+            throw new Horde_Exception($recipients);
         }
 
         return $recipients;
@@ -164,6 +193,8 @@ class IMP_Sentmail_sql extends IMP_Sentmail
      *
      * @param integer $before  Unix timestamp before that all log entries
      *                         should be deleted.
+     *
+     * @throw Horde_Exception
      */
     protected function _deleteOldEntries($before)
     {
@@ -179,49 +210,8 @@ class IMP_Sentmail_sql extends IMP_Sentmail
         $result = $this->_db->query($query, array($before));
         if (is_a($result, 'PEAR_Error')) {
             Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return $result;
+            throw new Horde_Exception($result);
         }
     }
 
-    /**
-     * Attempts to open a connection to the SQL server.
-     *
-     * @return boolean  True on success, PEAR_Error on failure.
-     */
-    public function initialize()
-    {
-        Horde::assertDriverConfig($this->_params, 'storage',
-                                  array('phptype', 'table'));
-
-        if (!isset($this->_params['database'])) {
-            $this->_params['database'] = '';
-        }
-        if (!isset($this->_params['username'])) {
-            $this->_params['username'] = '';
-        }
-        if (!isset($this->_params['hostspec'])) {
-            $this->_params['hostspec'] = '';
-        }
-
-        /* Connect to the SQL server using the supplied parameters. */
-        require_once 'DB.php';
-        $this->_db = DB::connect($this->_params,
-                                 array('persistent' => !empty($this->_params['persistent']),
-                                       'ssl' => !empty($this->_params['ssl'])));
-        if (is_a($this->_db, 'PEAR_Error')) {
-            return $this->_db;
-        }
-
-        /* Set DB portability options. */
-        switch ($this->_db->phptype) {
-        case 'mssql':
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
-            break;
-        default:
-            $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
-        }
-
-        return true;
-    }
-
 }
index 6f3e137..eef38f4 100644 (file)
@@ -79,9 +79,10 @@ class IMP_Session
         /* Run the username through virtualhost expansion functions if
          * necessary. */
         if (!empty($conf['hooks']['vinfo'])) {
-            $hook_user = Horde::callHook('_imp_hook_vinfo', array('username', $imapuser), 'imp');
-            if (!is_a($hook_user, 'PEAR_Error')) {
-                $imapuser = $hook_user;
+            try {
+                $imapuser = Horde::callHook('_imp_hook_vinfo', array('username', $imapuser), 'imp');
+            } catch (Horde_Exception $e) {
+                Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
             }
         }
 
index 1876a7d..f916b7f 100644 (file)
@@ -82,13 +82,18 @@ class IMP_UI_Message
             } else {
                 /* Send out the MDN now. */
                 $mail_driver = IMP_Compose::getMailDriver();
+
                 try {
                     $mdn->generate(false, $confirmed, 'displayed', $mail_driver['driver'], $mail_driver['params']);
                     IMP_Maillog::log('mdn', $msg_id, 'displayed');
-                } catch (Horde_Mime_Exception $e) {}
+                    $success = true;
+                } catch (Horde_Mime_Exception $e) {
+                    $success = false;
+                }
+
                 if ($GLOBALS['conf']['sentmail']['driver'] != 'none') {
                     $sentmail = IMP_Sentmail::factory();
-                    $sentmail->log('mdn', '', $return_addr, !is_a($result, 'PEAR_Error'));
+                    $sentmail->log('mdn', '', $return_addr, $success);
                 }
             }
         }
index 05f85bd..bc3312f 100644 (file)
@@ -56,13 +56,15 @@ require_once dirname(__FILE__) . '/lib/base.php';
 
 /* Call the mailbox redirection hook, if requested. */
 if (!empty($conf['hooks']['mbox_redirect'])) {
-    $redirect = Horde::callHook('_imp_hook_mbox_redirect',
-                                array($imp_mbox['mailbox']),
-                                'imp');
-    if (!empty($redirect) && !is_a($redirect, 'PEAR_Error')) {
-        $redirect = Horde::applicationUrl($redirect, true);
-        header('Location: ' . $redirect);
-        exit;
+    try {
+        $redirect = Horde::callHook('_imp_hook_mbox_redirect', array($imp_mbox['mailbox']), 'imp');
+        if (!empty($redirect)) {
+            $redirect = Horde::applicationUrl($redirect, true);
+            header('Location: ' . $redirect);
+            exit;
+        }
+    } catch (Horde_Exception $e) {
+        Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
     }
 }
 
index 13aaa59..55fded4 100644 (file)
@@ -156,11 +156,11 @@ case 'flag_message':
     break;
 
 case 'add_address':
-    $contact_link = IMP::addAddress(Util::getFormData('address'), Util::getFormData('name'));
-    if (is_a($contact_link, 'PEAR_Error')) {
-        $notification->push($contact_link);
-    } else {
+    try {
+        $contact_link = IMP::addAddress(Util::getFormData('address'), Util::getFormData('name'));
         $notification->push(sprintf(_("Entry \"%s\" was successfully added to the address book"), $contact_link), 'horde.success', array('content.raw'));
+    } catch (Horde_Exception $e) {
+        $notification->push($e, 'horde.error');
     }
     break;
 
index 1cef3fb..358225e 100644 (file)
@@ -89,11 +89,11 @@ case 'generate_key':
     } elseif ($passphrase1 !== $passphrase2) {
         $notification->push(_("Passphrases do not match"), 'horde.error');
     } else {
-        $result = $imp_pgp->generatePersonalKeys($realname, $email, $passphrase1, $comment, $keylength);
-        if (is_a($result, 'PEAR_Error')) {
-            $notification->push($result, $result->getCode());
-        } else {
+        try {
+            $imp_pgp->generatePersonalKeys($realname, $email, $passphrase1, $comment, $keylength);
             $notification->push(_("Personal PGP keypair generated successfully."), 'horde.success');
+        } catch (Horde_Exception $e) {
+            $notification->push($e);
         }
     }
     break;
@@ -189,25 +189,23 @@ case 'process_import_personal_private_key':
     exit;
 
 case 'view_public_key':
-    $key = $imp_pgp->getPublicKey(Util::getFormData('email'), null, false);
-    if (is_a($key, 'PEAR_Error')) {
-        $key = $key->getMessage();
+case 'info_public_key':
+    try {
+        $key = $imp_pgp->getPublicKey(Util::getFormData('email'), null, false);
+    } catch (Horde_Exception $e) {
+        $key = $e->getMessage();
+    }
+    if ($actionID == 'view_public_key') {
+        _textWindowOutput('PGP Public Key', $key);
+    } else {
+        _printKeyInfo($key);
     }
-    _textWindowOutput('PGP Public Key', $key);
     exit;
 
 case 'view_personal_public_key':
     _textWindowOutput('PGP Personal Public Key', $imp_pgp->getPersonalPublicKey());
     exit;
 
-case 'info_public_key':
-    $key = $imp_pgp->getPublicKey(Util::getFormData('email'), null, false);
-    if (is_a($key, 'PEAR_Error')) {
-        $key = $key->getMessage();
-    }
-    _printKeyInfo($key);
-    exit;
-
 case 'info_personal_public_key':
     _printKeyInfo($imp_pgp->getPersonalPublicKey());
     exit;
@@ -221,11 +219,11 @@ case 'info_personal_private_key':
     exit;
 
 case 'delete_public_key':
-    $result = $imp_pgp->deletePublicKey(Util::getFormData('email'));
-    if (is_a($result, 'PEAR_Error')) {
-        $notification->push($result, $result->getCode());
-    } else {
+    try {
+        $imp_pgp->deletePublicKey(Util::getFormData('email'));
         $notification->push(sprintf(_("PGP Public Key for \"%s\" was successfully deleted."), Util::getFormData('email')), 'horde.success');
+    } catch (Horde_Exception $e) {
+        $notification->push($e);
     }
     break;
 
@@ -264,11 +262,11 @@ case 'unset_passphrase':
     break;
 
 case 'send_public_key':
-    $result = $imp_pgp->sendToPublicKeyserver($imp_pgp->getPersonalPublicKey());
-    if (is_a($result, 'PEAR_Error')) {
-        $notification->push($result, $result->getCode());
-    } else {
+    try {
+        $imp_pgp->sendToPublicKeyserver($imp_pgp->getPersonalPublicKey());
         $notification->push(_("Key successfully sent to the public keyserver."), 'horde.success');
+    } catch (Horde_Exception $e) {
+        $notification->push($e);
     }
     break;
 }
@@ -276,9 +274,11 @@ case 'send_public_key':
 $selfURL = Horde::applicationUrl('pgp.php');
 
 /* Get list of Public Keys on keyring. */
-$pubkey_list = $imp_pgp->listPublicKeys();
-if (is_a($pubkey_list, 'PEAR_Error')) {
-    $notification->push($pubkey_list, $pubkey_list->getCode());
+try {
+    $pubkey_list = $imp_pgp->listPublicKeys();
+} catch (Horde_Exception $e) {
+    $pubkey_list = array();
+    $notification->push($e);
 }
 
 $result = Horde::loadConfiguration('prefs.php', array('prefGroups', '_prefs'), 'imp');
@@ -319,21 +319,18 @@ if ($prefs->getValue('use_pgp')) {
 
     $t->set('empty_pubkey_list', empty($pubkey_list));
     if (!$t->get('empty_pubkey_list')) {
-        $t->set('pubkey_error', is_a($pubkey_list, 'PEAR_Error') ? $pubkey_list->getMessage() : false);
-        if (!$t->get('pubkey_error')) {
-            $plist = array();
-            foreach ($pubkey_list as $val) {
-                $linkurl = Util::addParameter($selfURL, 'email', $val['email']);
-                $plist[] = array(
-                    'name' => $val['name'],
-                    'email' => $val['email'],
-                    'view' => Horde::link(Util::addParameter($linkurl, 'actionID', 'view_public_key'), sprintf(_("View %s Public Key"), $val['name']), null, 'view_key'),
-                    'info' => Horde::link(Util::addParameter($linkurl, 'actionID', 'info_public_key'), sprintf(_("Information on %s Public Key"), $val['name']), null, 'info_key'),
-                    'delete' => Horde::link(Util::addParameter($linkurl, 'actionID', 'delete_public_key'), sprintf(_("Delete %s Public Key"), $val['name']), null, null, "if (confirm('" . addslashes(_("Are you sure you want to delete this public key?")) . "')) { return true; } else { return false; }")
-                );
-            }
-            $t->set('pubkey_list', $plist);
+        $plist = array();
+        foreach ($pubkey_list as $val) {
+            $linkurl = Util::addParameter($selfURL, 'email', $val['email']);
+            $plist[] = array(
+                'name' => $val['name'],
+                'email' => $val['email'],
+                'view' => Horde::link(Util::addParameter($linkurl, 'actionID', 'view_public_key'), sprintf(_("View %s Public Key"), $val['name']), null, 'view_key'),
+                'info' => Horde::link(Util::addParameter($linkurl, 'actionID', 'info_public_key'), sprintf(_("Information on %s Public Key"), $val['name']), null, 'info_key'),
+                'delete' => Horde::link(Util::addParameter($linkurl, 'actionID', 'delete_public_key'), sprintf(_("Delete %s Public Key"), $val['name']), null, null, "if (confirm('" . addslashes(_("Are you sure you want to delete this public key?")) . "')) { return true; } else { return false; }")
+            );
         }
+        $t->set('pubkey_list', $plist);
     }
 
     $t->set('no_file_upload', !$_SESSION['imp']['file_upload']);
index cfec5ed..fd169fb 100644 (file)
@@ -92,11 +92,11 @@ case 'delete_key':
     break;
 
 case 'delete_public_key':
-    $result = $imp_smime->deletePublicKey(Util::getFormData('email'));
-    if (is_a($result, 'PEAR_Error')) {
-        $notification->push($result, $result->getCode());
-    } else {
+    try {
+        $imp_smime->deletePublicKey(Util::getFormData('email'));
         $notification->push(sprintf(_("S/MIME Public Key for \"%s\" was successfully deleted."), Util::getFormData('email')), 'horde.success');
+    } catch (Horde_Exception $e) {
+        $notification->push($e);
     }
     break;
 
@@ -125,19 +125,17 @@ case 'process_import_public_key':
     exit;
 
 case 'view_public_key':
-    $key = $imp_smime->getPublicKey(Util::getFormData('email'));
-    if (is_a($key, 'PEAR_Error')) {
-        $key = $key->getMessage();
-    }
-    _textWindowOutput('S/MIME Public Key', $key);
-    exit;
-
 case 'info_public_key':
-    $key = $imp_smime->getPublicKey(Util::getFormData('email'));
-    if (is_a($key, 'PEAR_Error')) {
-        $key = $key->getMessage();
+    try {
+        $key = $imp_smime->getPublicKey(Util::getFormData('email'));
+    } catch (Horde_Exception $e) {
+        $key = $e->getMessage();
+    }
+    if ($actionID == 'view_public_key') {
+        _textWindowOutput('S/MIME Public Key', $key);
+    } else {
+        _printKeyInfo($key);
     }
-    _printKeyInfo($key);
     exit;
 
 case 'view_personal_public_key':
@@ -161,14 +159,14 @@ case 'process_import_personal_certs':
         $actionID = 'import_personal_certs';
         _importKeyDialog('process_import_personal_certs');
     } else {
-        $res = $imp_smime->addFromPKCS12($pkcs12, Util::getFormData('upload_key_pass'), Util::getFormData('upload_key_pk_pass'));
-        if (is_a($res, 'PEAR_Error')) {
-            $notification->push(_("Personal S/MIME certificates NOT imported: ") . $res->getMessage(), 'horde.error');
-            $actionID = 'import_personal_certs';
-            _importKeyDialog('process_import_personal_certs');
-        } else {
+        try {
+            $imp_smime->addFromPKCS12($pkcs12, Util::getFormData('upload_key_pass'), Util::getFormData('upload_key_pk_pass'));
             $notification->push(_("S/MIME Public/Private Keypair successfully added."), 'horde.success');
             _reloadWindow();
+        } catch (Horde_Exception $e) {
+            $notification->push(_("Personal S/MIME certificates NOT imported: ") . $e->getMessage(), 'horde.error');
+            $actionID = 'import_personal_certs';
+            _importKeyDialog('process_import_personal_certs');
         }
     }
     exit;
@@ -209,9 +207,11 @@ case 'save_options':
 }
 
 /* Get list of Public Keys. */
-$pubkey_list = $imp_smime->listPublicKeys();
-if (is_a($pubkey_list, 'PEAR_Error')) {
-    $notification->push($pubkey_list, $pubkey_list->getCode());
+try {
+    $pubkey_list = $imp_smime->listPublicKeys();
+} catch (Horde_Exception $e) {
+    $pubkey_list = array();
+    $notification->push($e);
 }
 
 $result = Horde::loadConfiguration('prefs.php', array('prefGroups', '_prefs'), 'imp');
@@ -248,21 +248,18 @@ if (!is_a($openssl_check, 'PEAR_Error') && $prefs->getValue('use_smime')) {
 
     $t->set('empty_pubkey_list', empty($pubkey_list));
     if (!$t->get('empty_pubkey_list')) {
-        $t->set('pubkey_error', is_a($pubkey_list, 'PEAR_Error') ? $pubkey_list->getMessage() : false);
-        if (!$t->get('pubkey_error')) {
-            $plist = array();
-            foreach ($pubkey_list as $val) {
-                $linkurl = Util::addParameter($selfURL, 'email', $val['email']);
-                $plist[] = array(
-                    'name' => $val['name'],
-                    'email' => $val['email'],
-                    'view' => Horde::link(Util::addParameter($linkurl, 'actionID', 'view_public_key'), sprintf(_("View %s Public Key"), $val['name']), null, 'view_key'),
-                    'info' => Horde::link(Util::addParameter($linkurl, 'actionID', 'info_public_key'), sprintf(_("Information on %s Public Key"), $val['name']), null, 'info_key'),
-                    'delete' => Horde::link(Util::addParameter($linkurl, 'actionID', 'delete_public_key'), sprintf(_("Delete %s Public Key"), $val['name']), null, null, "if (confirm('" . addslashes(_("Are you sure you want to delete this public key?")) . "')) { return true; } else { return false; }")
-                );
-            }
-            $t->set('pubkey_list', $plist);
+        $plist = array();
+        foreach ($pubkey_list as $val) {
+            $linkurl = Util::addParameter($selfURL, 'email', $val['email']);
+            $plist[] = array(
+                'name' => $val['name'],
+                'email' => $val['email'],
+                'view' => Horde::link(Util::addParameter($linkurl, 'actionID', 'view_public_key'), sprintf(_("View %s Public Key"), $val['name']), null, 'view_key'),
+                'info' => Horde::link(Util::addParameter($linkurl, 'actionID', 'info_public_key'), sprintf(_("Information on %s Public Key"), $val['name']), null, 'info_key'),
+                'delete' => Horde::link(Util::addParameter($linkurl, 'actionID', 'delete_public_key'), sprintf(_("Delete %s Public Key"), $val['name']), null, null, "if (confirm('" . addslashes(_("Are you sure you want to delete this public key?")) . "')) { return true; } else { return false; }")
+            );
         }
+        $t->set('pubkey_list', $plist);
     }
 
     $t->set('no_file_upload', !$_SESSION['imp']['file_upload']);
index acef4c2..6c5ad00 100644 (file)
@@ -33,9 +33,6 @@
 <if:empty_pubkey_list>
  <em><gettext>No Keys in Keyring</gettext></em><br />
 <else:empty_pubkey_list>
-<if:pubkey_error>
- <em style="color:red"><gettext>Error:</gettext></em> <tag:pubkey_error /><br />
-<else:pubkey_error>
  <table>
 <loop:pubkey_list>
   <tr>
@@ -44,7 +41,7 @@
   </tr>
 </loop:pubkey_list>
  </table>
-</else:pubkey_error></if:pubkey_error></else:empty_pubkey_list></if:empty_pubkey_list>
+</else:empty_pubkey_list></if:empty_pubkey_list>
 
 <if:no_file_upload>
  <br /><span style="color:red"><gettext>Key import is not available. File upload is not enabled on this server.</gettext></span><br />
index 9cc83d6..61cbaa6 100644 (file)
@@ -25,9 +25,6 @@
 <if:empty_pubkey_list>
  <em><gettext>No Keys in Keyring</gettext></em>
 <else:empty_pubkey_list>
-<if:pubkey_error>
- <em style="color:red"><gettext>Error:</gettext></em> <tag:pubkey_error />
-<else:pubkey_error>
  <table>
 <loop:pubkey_list>
   <tr>
@@ -36,7 +33,7 @@
   </tr>
 </loop:pubkey_list>
  </table>
-</else:pubkey_error></if:pubkey_error></else:empty_pubkey_list></if:empty_pubkey_list>
+</else:empty_pubkey_list></if:empty_pubkey_list>
 
 <if:no_file_upload>
  <em style="color:red"><gettext>Key import is not available. File upload is not enabled on this server.</gettext></em>
index 71fb9b6..b3fb7dc 100644 (file)
@@ -48,11 +48,11 @@ NLS::setTimeZone();
 $actionID = Util::getFormData('actionID');
 switch ($actionID) {
 case 'add_address':
-    $contact_link = IMP::addAddress(Util::getFormData('address'), Util::getFormData('name'));
-    if (is_a($contact_link, 'PEAR_Error')) {
-        $notification->push($contact_link);
-    } else {
+    try {
+        $contact_link = IMP::addAddress(Util::getFormData('address'), Util::getFormData('name'));
         $notification->push(sprintf(_("Entry \"%s\" was successfully added to the address book"), $contact_link), 'horde.success', array('content.raw'));
+    } catch (Horde_Exception $e) {
+        $notification->push($e);
     }
     break;
 }