Don't return any PEAR_Errors in IMP code.
authorMichael M Slusarz <slusarz@curecanti.org>
Sun, 22 Feb 2009 01:54:59 +0000 (18:54 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Sun, 22 Feb 2009 04:24:02 +0000 (21:24 -0700)
First step on conversion to exclusively using exceptions.

37 files changed:
imp/acl.php
imp/ajax.php
imp/compose-dimp.php
imp/compose-mimp.php
imp/compose.php
imp/config/hooks.php.dist
imp/folders.php
imp/lib/Compose.php
imp/lib/Contents.php
imp/lib/Crypt/pgp.php
imp/lib/Crypt/smime.php
imp/lib/Fetchmail.php
imp/lib/Fetchmail/imap.php
imp/lib/IMAP/ACL.php
imp/lib/IMAP/Tree.php
imp/lib/IMP.php
imp/lib/Mailbox.php
imp/lib/Maintenance/Task/tos_agreement.php
imp/lib/Message.php
imp/lib/Quota.php
imp/lib/Quota/command.php
imp/lib/Quota/hook.php
imp/lib/Quota/imap.php
imp/lib/Quota/logfile.php
imp/lib/Quota/maildir.php
imp/lib/Quota/mdaemon.php
imp/lib/Quota/mercury32.php
imp/lib/Quota/sql.php
imp/lib/Spam.php
imp/lib/UI/Compose.php
imp/lib/Views/ShowMessage.php
imp/mailbox.php
imp/message-mimp.php
imp/message.php
imp/pgp.php
imp/smime.php
imp/view.php

index f063498..af74832 100644 (file)
@@ -57,18 +57,24 @@ case 'imp_acl_set':
         /* Each ACL is submitted with the acl as the value. Reverse the hash
            mapping for editACL(). */
         $new_acl = array_flip($new_acl);
-        $result = $ACLDriver->editACL($folder, $new_user, $new_acl);
-        if (is_a($result, 'PEAR_Error')) {
-            $notification->push($result);
-        } elseif (!count($new_acl)) {
-            $notification->push(sprintf(_("All rights on folder \"%s\" successfully removed for user \"%s\"."), $folder, $new_user), 'horde.success');
-        } else {
-            $notification->push(sprintf(_("User \"%s\" successfully given the specified rights for the folder \"%s\"."), $new_user, $folder), 'horde.success');
+        try {
+            $ACLDriver->editACL($folder, $new_user, $new_acl);
+            if (!count($new_acl)) {
+                $notification->push(sprintf(_("All rights on folder \"%s\" successfully removed for user \"%s\"."), $folder, $new_user), 'horde.success');
+            } else {
+                $notification->push(sprintf(_("User \"%s\" successfully given the specified rights for the folder \"%s\"."), $new_user, $folder), 'horde.success');
+            }
+        } catch (Horde_Exception $e) {
+            $notification->push($e);
         }
     }
 
     if ($ok_form) {
-        $current_acl = $ACLDriver->getACL($folder);
+        try {
+            $current_acl = $ACLDriver->getACL($folder);
+        } catch (Horde_Exception $e) {
+            Horde::fatal($e, __FILE__, __LINE__);
+        }
         foreach ($acls as $user => $acl) {
             if ($acl) {
                 $acl = array_flip($acl);
@@ -98,13 +104,15 @@ case 'imp_acl_set':
                 continue;
             }
 
-            $result = $ACLDriver->editACL($folder, $user, $acl);
-            if (is_a($result, 'PEAR_Error')) {
-                $notification->push($result);
-            } elseif (!count($acl)) {
-                $notification->push(sprintf(_("All rights on folder \"%s\" successfully removed for user \"%s\"."), $folder, $user), 'horde.success');
-            } else {
-                $notification->push(sprintf(_("User \"%s\" successfully given the specified rights for the folder \"%s\"."), $user, $folder), 'horde.success');
+            try {
+                $ACLDriver->editACL($folder, $user, $acl);
+                if (!count($acl)) {
+                    $notification->push(sprintf(_("All rights on folder \"%s\" successfully removed for user \"%s\"."), $folder, $user), 'horde.success');
+                } else {
+                    $notification->push(sprintf(_("User \"%s\" successfully given the specified rights for the folder \"%s\"."), $user, $folder), 'horde.success');
+                }
+            } catch (Horde_Exception $e) {
+                $notification->push($e);
             }
         }
     }
@@ -118,7 +126,11 @@ if (empty($folder)) {
     $folder = 'INBOX';
 }
 
-$curr_acl = $ACLDriver->getACL($folder);
+try {
+    $curr_acl = $ACLDriver->getACL($folder);
+} catch (Horde_Exception $e) {
+    Horde::fatal($e, __FILE__, __LINE__);
+}
 $canEdit = $ACLDriver->canEdit($folder, $_SESSION['imp']['uniquser']);
 
 require_once 'Horde/Prefs/UI.php';
index 621dc9e..2adff59 100644 (file)
@@ -196,15 +196,15 @@ case 'CreateFolder':
     $imp_folder = IMP_Folder::singleton();
 
     $new = String::convertCharset($mbox, NLS::getCharset(), 'UTF7-IMAP');
-    $new = $imptree->createMailboxName(Util::getPost('parent'), $new);
-    if (is_a($new, 'PEAR_Error')) {
-        $notification->push($new, 'horde.error');
-        $result = false;
-    } else {
+    try {
+        $new = $imptree->createMailboxName(Util::getPost('parent'), $new);
         $result = $imp_folder->create($new, $prefs->getValue('subscribe'));
         if ($result) {
             $result = DIMP::getFolderResponse($imptree);
         }
+    } catch (Horde_Exception $e) {
+        $notification->push($e, 'horde.error');
+        $result = false;
     }
     break;
 
@@ -236,12 +236,9 @@ case 'RenameFolder':
 
     $imp_folder = IMP_Folder::singleton();
 
-    $new = $imptree->createMailboxName($new_parent, $new);
-    if (is_a($new, 'PEAR_Error')) {
-        $notification->push($new, 'horde.error');
-        $result = false;
-    } else {
-        require_once 'Horde/String.php';
+    try {
+        $new = $imptree->createMailboxName($new_parent, $new);
+
         $new = String::convertCharset($new, NLS::getCharset(), 'UTF7-IMAP');
         if ($old != $new) {
             $result = $imp_folder->rename($old, $new);
@@ -249,6 +246,9 @@ case 'RenameFolder':
                 $result = DIMP::getFolderResponse($imptree);
             }
         }
+    } catch (Horde_Exception $e) {
+        $notification->push($e, 'horde.error');
+        $result = false;
     }
     break;
 
index c375a23..ed9f9ee 100644 (file)
@@ -91,10 +91,8 @@ if (count($_POST)) {
         $header['from'] = $from;
 
         /* Save the draft. */
-        $res = $imp_compose->saveDraft($header, Util::getFormData('message', ''), NLS::getCharset(), Util::getFormData('html'));
-        if (is_a($res, 'PEAR_Error')) {
-            $notification->push($res->getMessage(), 'horde.error');
-        } else {
+        try {
+            $res = $imp_compose->saveDraft($header, Util::getFormData('message', ''), NLS::getCharset(), Util::getFormData('html'));
             $result->success = true;
 
             /* Delete existing draft. */
@@ -107,6 +105,8 @@ if (count($_POST)) {
             } else {
                 $notification->push($res);
             }
+        } catch (IMP_Compose_Exception $e) {
+            $notification->push($e, 'horde.error');
         }
         break;
 
@@ -149,10 +149,11 @@ if (count($_POST)) {
             'reply_index' => $result->index . IMP::IDX_SEP . $result->reply_folder,
             'readreceipt' => Util::getFormData('request_read_receipt')
         );
-        $sent = $imp_compose->buildAndSendMessage($message, $header, $charset, $html, $options);
 
-        if (is_a($sent, 'PEAR_Error')) {
-            $notification->push($sent, 'horde.error');
+        try {
+            $sent = $imp_compose->buildAndSendMessage($message, $header, $charset, $html, $options);
+        } catch (IMP_Compose_Exception $e) {
+            $notification->push($e, 'horde.error');
             break;
         }
         $result->success = true;
@@ -193,8 +194,9 @@ if (in_array($type, array('reply', 'reply_all', 'reply_list', 'forward_all', 'fo
         $type = 'new';
     }
 
-    $imp_contents = &IMP_Contents::singleton($index . IMP::IDX_SEP . $folder);
-    if (is_a($imp_contents, 'PEAR_Error')) {
+    try {
+        $imp_contents = &IMP_Contents::singleton($index . IMP::IDX_SEP . $folder);
+    } catch (Horde_Exception $e) {
         $notification->push(_("Requested message not found."), 'horde.error');
         $index = $folder = null;
         $type = 'new';
index 55174dc..08d6337 100644 (file)
@@ -17,12 +17,13 @@ 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;
 }
 
 require_once dirname(__FILE__) . '/lib/base.php';
@@ -137,16 +138,17 @@ case _("Redirect"):
 
     $f_to = $imp_ui->getAddressList(Util::getFormData('to'));
 
-    $result = $imp_ui->redirectMessage($f_to, $imp_compose, $imp_contents, NLS::getEmailCharset());
-    if (!is_a($result, 'PEAR_Error')) {
+    try {
+        $imp_ui->redirectMessage($f_to, $imp_compose, $imp_contents, NLS::getEmailCharset());
         if ($prefs->getValue('compose_confirm')) {
             $notification->push(_("Message redirected successfully."), 'horde.success');
         }
         require IMP_BASE . '/mailbox-mimp.php';
         exit;
+    } catch (Horde_Exception $e) {
+        $actionID = 'rc';
+        $notification->push($e, 'horde.error');
     }
-    $actionID = 'rc';
-    $notification->push($result, 'horde.error');
     break;
 
 case _("Send"):
@@ -205,21 +207,22 @@ case _("Send"):
         'reply_index' => empty($index) ? null : $index . IMP::IDX_SEP . $thismailbox,
         'readreceipt' => Util::getFormData('request_read_receipt')
     );
-    $sent = $imp_compose->buildAndSendMessage($message, $header, NLS::getEmailCharset(), false, $options);
-
-    if (is_a($sent, 'PEAR_Error')) {
-        $notification->push($sent, 'horde.error');
-    } elseif ($sent) {
-        if (Util::getFormData('resume_draft') &&
-            $prefs->getValue('auto_delete_drafts')) {
-            $imp_message = &IMP_Message::singleton();
-            $idx_array = array($index . IMP::IDX_SEP . $thismailbox);
-            $delete_draft = $imp_message->delete($idx_array, true);
-        }
 
-        $notification->push(_("Message sent successfully."), 'horde.success');
-        require IMP_BASE . '/mailbox-mimp.php';
-        exit;
+    try {
+        if ($imp_compose->buildAndSendMessage($message, $header, NLS::getEmailCharset(), false, $options)) {
+            if (Util::getFormData('resume_draft') &&
+                $prefs->getValue('auto_delete_drafts')) {
+                $imp_message = &IMP_Message::singleton();
+                $idx_array = array($index . IMP::IDX_SEP . $thismailbox);
+                $delete_draft = $imp_message->delete($idx_array, true);
+            }
+
+            $notification->push(_("Message sent successfully."), 'horde.success');
+            require IMP_BASE . '/mailbox-mimp.php';
+            exit;
+        }
+    } catch (IMP_Compose_Exception $e) {
+        $notification->push($e, 'horde.error');
     }
     break;
 }
index d8b6e32..0f0a024 100644 (file)
@@ -111,9 +111,10 @@ if ($actionID) {
         break;
 
     default:
-        $result = IMP::checkRequestToken('imp.compose', Util::getFormData('compose_requestToken'));
-        if (is_a($result, 'PEAR_Error')) {
-            $notification->push($result);
+        try {
+            IMP::checkRequestToken('imp.compose', Util::getFormData('compose_requestToken'));
+        } catch (Horde_Exception $e) {
+            $notification->push($e);
             $actionID = null;
         }
     }
@@ -372,8 +373,8 @@ case 'redirect_send':
 
     $f_to = Util::getFormData('to', $imp_ui->getAddressList(Util::getFormData('to'), Util::getFormData('to_list'), Util::getFormData('to_field'), Util::getFormData('to_new')));
 
-    $result = $imp_ui->redirectMessage($f_to, $imp_compose, $imp_contents, $encoding);
-    if (!is_a($result, 'PEAR_Error')) {
+    try {
+        $imp_ui->redirectMessage($f_to, $imp_compose, $imp_contents, $encoding);
         if ($isPopup) {
             if ($prefs->getValue('compose_confirm')) {
                 $notification->push(_("Message redirected successfully."), 'horde.success');
@@ -388,10 +389,11 @@ case 'redirect_send':
             header('Location: ' . _mailboxReturnURL(false));
         }
         exit;
+    } catch (Horde_Exception $e) {
+        $notification->push($e, 'horde.error');
+        $actionID = 'redirect_compose';
+        $get_sig = false;
     }
-    $notification->push($result, 'horde.error');
-    $actionID = 'redirect_compose';
-    $get_sig = false;
     break;
 
 case 'send_message':
@@ -432,13 +434,15 @@ case 'send_message':
         'priority' => Util::getFormData('x_priority'),
         'readreceipt' => Util::getFormData('request_read_receipt')
     );
-    $sent = $imp_compose->buildAndSendMessage($message, $header, $charset, $rtemode, $options);
 
-    if (is_a($sent, 'PEAR_Error')) {
+    try {
+        $sent = $imp_compose->buildAndSendMessage($message, $header, $charset, $rtemode, $options);
+    } catch (IMP_Compose_Exception $e) {
         $get_sig = false;
-        $code = $sent->getCode();
-        $notification->push($sent, strpos($code, 'horde.') === 0 ? $code : 'horde.error');
-        switch ($sent->getUserInfo()) {
+        $code = $e->getCode();
+        $notification->push($e, strpos($code, 'horde.') === 0 ? $code : 'horde.error');
+        // TODO
+        switch ($e->encrypt) {
         case 'pgp_symmetric_passphrase_dialog':
             $pgp_symmetric_passphrase_dialog = true;
             break;
@@ -499,23 +503,24 @@ case 'save_draft':
     $message = Util::getFormData('message', '');
 
     /* Save the draft. */
-    $result = $imp_compose->saveDraft($header, $message, NLS::getCharset(), $rtemode);
-    if (is_a($result, 'PEAR_Error')) {
-        $notification->push($result->getMessage(), 'horde.error');
-    } else {
+    try {
+        $result = $imp_compose->saveDraft($header, $message, NLS::getCharset(), $rtemode);
+
         /* Closing draft if requested by preferences. */
         if ($isPopup) {
             if ($prefs->getValue('close_draft')) {
                 Util::closeWindowJS();
+                exit;
             } else {
                 $notification->push($result, 'horde.success');
-                break;
             }
         } else {
             $notification->push($result);
             header('Location: ' . _mailboxReturnURL(false));
+            exit;
         }
-        exit;
+    } catch (IMP_Compose_Exception $e) {
+        $notification->push($e, 'horde.error');
     }
 
     $get_sig = false;
@@ -557,9 +562,10 @@ case 'selectlist_process':
                     $part = new Horde_Mime_Part();
                     $part->setContents($data);
                     $part->setName(reset($val));
-                    $res = $imp_compose->addMIMEPartAttachment($part);
-                    if (is_a($res, 'PEAR_Error')) {
-                        $notification->push($res, 'horde.error');
+                    try {
+                        $imp_compose->addMIMEPartAttachment($part);
+                    } catch (IMP_Compose_Exception $e) {
+                        $notification->push($e, 'horde.error');
                     }
                 }
             }
@@ -732,18 +738,20 @@ if ($prefs->getValue('use_pgp')) {
     $default_encrypt = $prefs->getValue('default_encrypt');
     if (!$token &&
         in_array($default_encrypt, array(IMP::PGP_ENCRYPT, IMP::PGP_SIGNENC))) {
-        $addrs = $imp_compose->recipientList($header);
-        if (!is_a($addrs, 'PEAR_Error') && !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;
+        try {
+            $addrs = $imp_compose->recipientList($header);
+            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;
+                    }
                 }
             }
-        }
+        } catch (IMP_Compose_Exception $e) {}
     }
 }
 
index 0ce4e90..dbaa907 100644 (file)
 // ex. $HTTP_HOST = 'mail.mydomain.com', $username = 'myname':
 //   $vdomain  = 'mydomain.com'
 //   $username = 'myname_mydomain_com'
+//
+// Throw a Horde_Exception object on failure.
+
 
 // if (!function_exists('_imp_hook_vinfo')) {
 //     function _imp_hook_vinfo($type = 'username', $data = null)
 //             return $vdomain;
 //
 //         default:
-//             return PEAR::raiseError('invalid type: ' . $type);
+//             throw new Horde_Exception('invalid type: ' . $type);
 //         }
 //     }
 // }
@@ -505,7 +508,7 @@ if (!empty($GLOBALS['conf']['kolab']['enabled'])) {
 // @return array Tuple with two members:
 //               first: disk space used (in bytes)
 //               second: maximum disk space (in bytes)
-//               In case of an error, return PEAR::raiseError()
+//               In case of an error, throw a Horde_Exception object.
 if (!function_exists('_imp_hook_quota')) {
     function _imp_hook_quota($params = null)
     {
@@ -516,11 +519,11 @@ if (!function_exists('_imp_hook_quota')) {
 
         $session = ssh2_connect($host);
         if (!$session) {
-            return PEAR::raiseError(_("Connection to server failed."), 'horde.error');
+            throw new Horde_Exception(_("Connection to server failed."), 'horde.error');
         }
 
         if (!ssh2_auth_password($session, $user, $pass)) {
-            return PEAR::raiseError(_("Authentication failed."), 'horde.error');
+            throw new Horde_Exception(_("Authentication failed."), 'horde.error');
         }
 
         $stream = ssh2_exec($session, $command, false);
index a6ec822..7222e99 100644 (file)
@@ -73,9 +73,10 @@ $open_compose_window = null;
 /* Run through the action handlers. */
 $actionID = Util::getFormData('actionID');
 if ($actionID) {
-    $result = IMP::checkRequestToken('imp.folders', Util::getFormData('folders_token'));
-    if (is_a($result, 'PEAR_Error')) {
-        $notification->push($result);
+    try {
+        IMP::checkRequestToken('imp.folders', Util::getFormData('folders_token'));
+    } catch (Horde_Exception $e) {
+        $notification->push($e);
         $actionID = null;
     }
 }
@@ -162,11 +163,11 @@ case 'import_mbox':
 case 'create_folder':
     $new_mailbox = Util::getFormData('new_mailbox');
     if (!empty($new_mailbox)) {
-        $new_mailbox = $imaptree->createMailboxName(array_shift($folder_list), String::convertCharset($new_mailbox, $charset, 'UTF7-IMAP'));
-        if (is_a($new_mailbox, 'PEAR_Error')) {
-            $notification->push($new_mailbox);
-        } else {
+        try {
+            $new_mailbox = $imaptree->createMailboxName(array_shift($folder_list), String::convertCharset($new_mailbox, $charset, 'UTF7-IMAP'));
             $imp_folder->create($new_mailbox, $subscribe);
+        } catch (Horde_Exception $e) {
+            $notification->push($e);
         }
     }
     break;
index cbf94e6..f235ab2 100644 (file)
@@ -142,19 +142,18 @@ class IMP_Compose
      * @param string $charset  The charset that was used for the headers.
      * @param boolean $html    Whether this is an HTML message.
      *
-     * @return mixed  Notification text on success, PEAR_Error on error.
+     * @return string  Notification text on success.
+     * @throws IMP_Compose_Exception
      */
     public function saveDraft($headers, $message, $charset, $html)
     {
         $drafts_folder = IMP::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true);
         if (empty($drafts_folder)) {
-            return PEAR::raiseError(_("Saving the draft failed. No draft folder specified."));
+            throw new IMP_Compose_Exception(_("Saving the draft failed. No draft folder specified."));
         }
 
         $body = $this->_saveDraftMsg($headers, $message, $charset, $html, true);
-        return is_a($body, 'PEAR_Error')
-            ? $body
-            : $this->_saveDraftServer($body, $drafts_folder);
+        return $this->_saveDraftServer($body, $drafts_folder);
     }
 
     /**
@@ -168,7 +167,8 @@ class IMP_Compose
      * @param boolean $html     Whether this is an HTML message.
      * @param boolean $session  Do we have an active session?
      *
-     * @return mixed  PEAR_Error on error, the body text on success.
+     * @return string  The body text.
+     * @throws IMP_Compose_Exception
      */
     protected function _saveDraftMsg($headers, $message, $charset, $html,
                                      $session)
@@ -194,7 +194,7 @@ class IMP_Compose
                 if ($session) {
                     $addr_check = Horde_Mime::encodeAddress($this->formatAddr($addr), $charset, $_SESSION['imp']['maildomain']);
                     if (is_a($addr_check, 'PEAR_Error')) {
-                        return PEAR::raiseError(sprintf(_("Saving the draft failed. The %s header contains an invalid e-mail address: %s."), $k, $addr_check->getMessage()));
+                        throw new IMP_Compose_Exception(sprintf(_("Saving the draft failed. The %s header contains an invalid e-mail address: %s."), $k, $addr_check->getMessage()));
                     }
                 }
                 $draft_headers->addHeader($v, $addr);
@@ -220,6 +220,7 @@ class IMP_Compose
      *                             (UTF7-IMAP).
      *
      * @return string  Status string.
+     * @throw IMP_Compose_Exception
      */
     protected function _saveDraftServer($data, $drafts_mbox)
     {
@@ -229,7 +230,7 @@ class IMP_Compose
         /* Check for access to drafts folder. */
         if (!$imp_folder->exists($drafts_mbox) &&
             !$imp_folder->create($drafts_mbox, $GLOBALS['prefs']->getValue('subscribe'))) {
-            return PEAR::raiseError(_("Saving the draft failed. Could not create a drafts folder."));
+            throw new IMP_Compose_Exception(_("Saving the draft failed. Could not create a drafts folder."));
         }
 
         $append_flags = array('\\draft');
@@ -277,8 +278,10 @@ class IMP_Compose
      */
     public function resumeDraft($index)
     {
-        $contents = IMP_Contents::singleton($index);
-        if (is_a($contents, 'PEAR_Error')) {
+        try {
+            $contents = IMP_Contents::singleton($index);
+        } catch (Horde_Exception $e) {
+            // TODO
             return $contents;
         }
 
@@ -353,7 +356,8 @@ class IMP_Compose
      * </pre>
      *
      * @return boolean  Whether the sent message has been saved in the
-     *                  sent-mail folder, or a PEAR_Error on failure.
+     *                  sent-mail folder.
+     * @throws IMP_Compose_Exception
      */
     public function buildAndSendMessage($body, $header, $charset, $html,
                                         $opts = array())
@@ -363,9 +367,6 @@ class IMP_Compose
         /* We need at least one recipient & RFC 2822 requires that no 8-bit
          * characters can be in the address fields. */
         $recip = $this->recipientList($header);
-        if (is_a($recip, 'PEAR_Error')) {
-            return $recip;
-        }
         $header = array_merge($header, $recip['header']);
 
         $barefrom = Horde_Mime_Address::bareAddress($header['from'], $_SESSION['imp']['maildomain']);
@@ -496,11 +497,12 @@ class IMP_Compose
 
         /* Send the messages out now. */
         foreach ($send_msgs as $val) {
-            $res = $this->sendMessage($val['to'], $headers, $val['msg'], $charset);
-            if (is_a($res, 'PEAR_Error')) {
+            try {
+                $this->sendMessage($val['to'], $headers, $val['msg'], $charset);
+            } catch (IMP_Compose_Exception $e) {
                 /* Unsuccessful send. */
-                Horde::logMessage($res->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
-                return PEAR::raiseError(sprintf(_("There was an error sending your message: %s"), $res->getMessage()));
+                Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
+                throw new IMP_Compose_Exception(sprintf(_("There was an error sending your message: %s"), $e->getMessage()));
             }
 
             /* Store history information. */
@@ -619,7 +621,7 @@ class IMP_Compose
      * @param string $charset              The charset that was used for the
      *                                     headers.
      *
-     * @return mixed  True on success, PEAR_Error on error.
+     * @throws IMP_Compose_Exception
      */
     public function sendMessage($email, $headers, $message, $charset)
     {
@@ -628,20 +630,20 @@ class IMP_Compose
         /* Properly encode the addresses we're sending to. */
         $email = Horde_Mime::encodeAddress($email, null, $_SESSION['imp']['maildomain']);
         if (is_a($email, 'PEAR_Error')) {
-            return $email;
+            throw new IMP_Compose_Exception($email);
         }
 
         /* Validate the recipient addresses. */
         $result = Horde_Mime_Address::parseAddressList($email, array('defserver' => $_SESSION['imp']['maildomain'], 'validate' => true));
         if (empty($result)) {
-            return $result;
+            return;
         }
 
         $timelimit = IMP::hasPermission('max_timelimit');
         if ($timelimit !== true) {
             if ($conf['sentmail']['driver'] == 'none') {
                 Horde::logMessage('The permission for the maximum number of recipients per time period has been enabled, but no backend for the sent-mail logging has been configured for IMP.', __FILE__, __LINE__, PEAR_LOG_ERR);
-                return PEAR::raiseError(_("The system is not properly configured. A detailed error description has been logged for the administrator."));
+                throw new IMP_Compose_Exception(_("The system is not properly configured. A detailed error description has been logged for the administrator."));
             }
             $sentmail = IMP_Sentmail::factory();
             $recipients = $sentmail->numberOfRecipients($conf['sentmail']['params']['limit_period'], true);
@@ -653,13 +655,16 @@ class IMP_Compose
                 if (!empty($conf['hooks']['permsdenied'])) {
                     $error = Horde::callHook('_perms_hook_denied', array('imp:max_timelimit'), 'horde', $error);
                 }
-                return PEAR::raiseError($error);
+                throw new IMP_Compose_Exception($error);
             }
         }
 
         $mail_driver = $this->getMailDriver();
 
-        return $message->send($email, $headers, $mail_driver['driver'], $mail_driver['params']);
+        $res = $message->send($email, $headers, $mail_driver['driver'], $mail_driver['params']);
+        if (is_a($res, 'PEAR_Error')) {
+            throw new IMP_Compose_Exception($res);
+        }
     }
 
     /**
@@ -773,13 +778,13 @@ class IMP_Compose
      * @param boolean $exceed  Test if user has exceeded the allowed
      *                         number of recipients?
      *
-     * @return array  PEAR_Error on error, or an array with the following
-     *                entries:
+     * @return array  An array with the following entries:
      * <pre>
      * 'list' - An array of recipient addresses.
      * 'header' - An array containing the cleaned up 'to', 'cc', and 'bcc'
      *            header strings.
      * </pre>
+     * @throws IMP_Compose_Exception
      */
     public function recipientList($hdr, $exceed = true)
     {
@@ -800,7 +805,7 @@ class IMP_Compose
 
                 $obs = Horde_Mime_Address::parseAddressList($email);
                 if (empty($obs)) {
-                    return PEAR::raiseError(sprintf(_("Invalid e-mail address: %s."), $email));
+                    throw new IMP_Compose_Exception(sprintf(_("Invalid e-mail address: %s."), $email));
                 }
 
                 foreach ($obs as $ob) {
@@ -808,18 +813,12 @@ class IMP_Compose
                         $group_addresses = array();
                         foreach ($ob['addresses'] as $ad) {
                             $ret = $this->_parseAddress($ad, $email);
-                            if (is_a($ret, 'PEAR_Error')) {
-                                return $ret;
-                            }
                             $addrlist[] = $group_addresses[] = $ret;
                         }
 
                         $tmp[] = Horde_Mime_Address::writeGroupAddress($ob['groupname'], $group_addresses) . ' ';
                     } else {
                         $ret = $this->_parseAddress($ob, $email);
-                        if (is_a($ret, 'PEAR_Error')) {
-                            return $ret;
-                        }
                         $addrlist[] = $ret;
                         $tmp[] = $ret . ', ';
                     }
@@ -830,7 +829,7 @@ class IMP_Compose
         }
 
         if (empty($addrlist)) {
-            return PEAR::raiseError(_("You must enter at least one recipient."));
+            throw new IMP_Compose_Exception(_("You must enter at least one recipient."));
         }
 
         /* Count recipients if necessary. We need to split email groups
@@ -847,7 +846,7 @@ class IMP_Compose
                     if (!empty($conf['hooks']['permsdenied'])) {
                         $message = Horde::callHook('_perms_hook_denied', array('imp:max_recipients'), 'horde', $message);
                     }
-                    return PEAR::raiseError($message);
+                    throw new IMP_Compose_Exception($message);
                 }
             }
         }
@@ -861,7 +860,7 @@ class IMP_Compose
     protected function _parseAddress($ob, $email)
     {
         if (Horde_Mime::is8bit($ob['mailbox'])) {
-            return PEAR::raiseError(sprintf(_("Invalid character in e-mail address: %s."), $email));
+            throw new IMP_Compose_Exception(sprintf(_("Invalid character in e-mail address: %s."), $email));
         }
 
         // Make sure we have a valid host.
@@ -874,7 +873,7 @@ class IMP_Compose
         if (Util::extensionExists('idn')) {
             $host = idn_to_ascii(String::convertCharset($host, NLS::getCharset(), 'UTF-8'));
         } elseif (Horde_Mime::is8bit($ob['mailbox'])) {
-            return PEAR::raiseError(sprintf(_("Invalid character in e-mail address: %s."), $email));
+            throw new IMP_Compose_Exception(sprintf(_("Invalid character in e-mail address: %s."), $email));
         }
 
         return Horde_Mime_Address::writeAddress($ob['mailbox'], $host, isset($ob['personal']) ? $ob['personal'] : '');
@@ -896,7 +895,8 @@ class IMP_Compose
      * 'noattach' - (boolean) Don't add attachment information.
      * </pre>
      *
-     * @return mixed  PEAR_Error on error or TODO.
+     * @return array  TODO
+     * @throws IMP_Compose_Exception
      */
     protected function _createMimeMessage($to, $body, $charset,
                                           $options = array())
@@ -994,9 +994,6 @@ class IMP_Compose
                  $GLOBALS['conf']['compose']['link_attachments']) ||
                 !empty($GLOBALS['conf']['compose']['link_all_attachments'])) {
                 $base = $this->linkAttachments(Horde::applicationUrl('attachment.php', true), $textpart, Auth::getAuth());
-                if (is_a($base, 'PEAR_Error')) {
-                    return $base;
-                }
 
                 if ($this->_pgpAttachPubkey || $this->_attachVCard) {
                     $new_body = new Horde_Mime_Part();
@@ -1048,7 +1045,9 @@ class IMP_Compose
                 /* Check to see if we have the user's passphrase yet. */
                 $passphrase = $imp_pgp->getPassphrase('personal');
                 if (empty($passphrase)) {
-                    return PEAR::raiseError(_("PGP: Need passphrase for personal private key."), 'horde.message', null, null, 'pgp_passphrase_dialog');
+                    $e = new IMP_Compose_Exception(_("PGP: Need passphrase for personal private key."), 'horde.message');
+                    $e->encrypt = 'pgp_passphrase_dialog';
+                    throw $e;
                 }
                 break;
 
@@ -1058,7 +1057,9 @@ class IMP_Compose
                  * yet. */
                 $symmetric_passphrase = $imp_pgp->getPassphrase('symmetric', 'imp_compose_' . $this->_cacheid);
                 if (empty($symmetric_passphrase)) {
-                    return PEAR::raiseError(_("PGP: Need passphrase to encrypt your message with."), 'horde.message', null, null, 'pgp_symmetric_passphrase_dialog');
+                    $e = new IMP_Compose_Exception(_("PGP: Need passphrase to encrypt your message with."), 'horde.message');
+                    $e->encrypt = 'pgp_symmetric_passphrase_dialog';
+                    throw $e;
                 }
                 break;
             }
@@ -1088,7 +1089,7 @@ class IMP_Compose
 
             /* Check for errors. */
             if (is_a($base, 'PEAR_Error')) {
-                return PEAR::raiseError(_("PGP Error: ") . $base->getMessage());
+                throw new IMP_Compose_Exception(_("PGP Error: ") . $base->getMessage(), $base->getCode());
             }
         } elseif ($GLOBALS['prefs']->getValue('use_smime') &&
                   in_array($encrypt, array(IMP::SMIME_ENCRYPT, IMP::SMIME_SIGN, IMP::SMIME_SIGNENC))) {
@@ -1098,7 +1099,9 @@ class IMP_Compose
             if (in_array($encrypt, array(IMP::SMIME_SIGN, IMP::SMIME_SIGNENC))) {
                 $passphrase = $imp_smime->getPassphrase();
                 if ($passphrase === false) {
-                    return PEAR::raiseError(_("S/MIME Error: Need passphrase for personal private key."), 'horde.error', null, null, 'smime_passphrase_dialog');
+                    $e = new IMP_Compose_Exception(_("S/MIME Error: Need passphrase for personal private key."), 'horde.error');
+                    $e->encrypt = 'smime_passphrase_dialog';
+                    throw $e;
                 }
             }
 
@@ -1119,7 +1122,7 @@ class IMP_Compose
 
             /* Check for errors. */
             if (is_a($base, 'PEAR_Error')) {
-                return PEAR::raiseError(_("S/MIME Error: ") . $base->getMessage());
+                throw new IMP_Compose_Exception(_("S/MIME Error: ") . $base->getMessage(), $base->getCode());
             }
         }
 
@@ -1429,7 +1432,7 @@ class IMP_Compose
     {
         $msgList = IMP::parseIndicesList($indices);
         if (empty($msgList)) {
-            return;
+            return false;
         }
 
         $attached = 0;
@@ -1445,9 +1448,10 @@ class IMP_Compose
                 $part->setName(_("Forwarded Message"));
                 $part->setContents($contents->fullMessageText());
 
-                $result = $this->addMIMEPartAttachment($part);
-                if (is_a($result, 'PEAR_Error')) {
-                    $GLOBALS['notification']->push($result);
+                try {
+                    $this->addMIMEPartAttachment($part);
+                } catch (IMP_Compose_Exception $e) {
+                    $GLOBALS['notification']->push($e);
                     return false;
                 }
             }
@@ -1518,7 +1522,8 @@ class IMP_Compose
      *
      * @param string $name  The input field name from the form.
      *
-     * @return mixed  Returns the filename on success; PEAR_Error on error.
+     * @return string  The filename.
+     * @throws IMP_Compose_Exception
      */
     public function addUploadAttachment($name)
     {
@@ -1526,7 +1531,7 @@ class IMP_Compose
 
         $res = $GLOBALS['browser']->wasFileUploaded($name, _("attachment"));
         if (is_a($res, 'PEAR_Error')) {
-            return $res;
+            throw new IMP_Compose_Exception($res);
         }
 
         $filename = Util::dispelMagicQuotes($_FILES[$name]['name']);
@@ -1535,7 +1540,7 @@ class IMP_Compose
         /* Check for filesize limitations. */
         if (!empty($conf['compose']['attach_size_limit']) &&
             (($conf['compose']['attach_size_limit'] - $this->sizeOfAttachments() - $_FILES[$name]['size']) < 0)) {
-            return PEAR::raiseError(sprintf(_("Attached file \"%s\" exceeds the attachment size limits. File NOT attached."), $filename), 'horde.error');
+            throw new IMP_Compose_Exception(sprintf(_("Attached file \"%s\" exceeds the attachment size limits. File NOT attached."), $filename), 'horde.error');
         }
 
         /* Store the data in a Horde_Mime_Part. Some browsers do not send the
@@ -1565,15 +1570,12 @@ class IMP_Compose
         } else {
             $attachment = Horde::getTempFile('impatt', false);
             if (move_uploaded_file($tempfile, $attachment) === false) {
-                return PEAR::raiseError(sprintf(_("The file %s could not be attached."), $filename), 'horde.error');
+                throw new IMP_Compose_Exception(sprintf(_("The file %s could not be attached."), $filename), 'horde.error');
             }
         }
 
         /* Store the data. */
         $result = $this->_storeAttachment($part, $attachment);
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
 
         return $filename;
     }
@@ -1584,7 +1586,7 @@ class IMP_Compose
      * @param Horde_Mime_Part $part  The object that contains the attachment
      *                               data.
      *
-     * @return PEAR_Error  Returns a PEAR_Error object on error.
+     * @throws IMP_Compose_Exception
      */
     public function addMIMEPartAttachment($part)
     {
@@ -1615,7 +1617,7 @@ class IMP_Compose
             $attachment = Horde::getTempFile('impatt', false);
             $res = file_put_contents($attachment, $part->getContents());
             if ($res === false) {
-                return PEAR::raiseError(sprintf(_("Could not attach %s to the message."), $part->getName()), 'horde.error');
+                throw new IMP_Compose_Exception(sprintf(_("Could not attach %s to the message."), $part->getName()), 'horde.error');
             }
 
             if (($type == 'application/octet-stream') &&
@@ -1635,7 +1637,7 @@ class IMP_Compose
         /* Check for filesize limitations. */
         if (!empty($conf['compose']['attach_size_limit']) &&
             (($conf['compose']['attach_size_limit'] - $this->sizeOfAttachments() - $bytes) < 0)) {
-            return PEAR::raiseError(sprintf(_("Attached file \"%s\" exceeds the attachment size limits. File NOT attached."), $part->getName()), 'horde.error');
+            throw new IMP_Compose_Exception(sprintf(_("Attached file \"%s\" exceeds the attachment size limits. File NOT attached."), $part->getName()), 'horde.error');
         }
 
         /* Store the data. */
@@ -1977,10 +1979,12 @@ class IMP_Compose
             if (strpos($key, '.', 1) === false) {
                 $mime = $contents->getMIMEPart($key);
                 if (!empty($mime)) {
-                    $res = $this->addMIMEPartAttachment($mime);
-                    if (is_a($res, 'PEAR_Error') &&
-                        !empty($options['notify'])) {
-                        $GLOBALS['notification']->push($res, 'horde.warning');
+                    try {
+                        $this->addMIMEPartAttachment($mime);
+                    } catch (IMP_Compose_Exception $e) {
+                        if (!empty($options['notify'])) {
+                            $GLOBALS['notification']->push($e, 'horde.warning');
+                        }
                     }
                 }
             }
@@ -2078,14 +2082,14 @@ class IMP_Compose
      *                               attachments.
      *
      * @return Horde_Mime_Part  Modified MIME part with links to attachments.
-     *                          Returns PEAR_Error on error.
+     * @throws IMP_Compose_Exception
      */
     public function linkAttachments($baseurl, $part, $auth)
     {
         global $conf, $prefs;
 
         if (!$conf['compose']['link_attachments']) {
-            return PEAR::raiseError(_("Linked attachments are forbidden."));
+            throw new IMP_Compose_Exception(_("Linked attachments are forbidden."));
         }
 
         $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type']));
@@ -2114,7 +2118,7 @@ class IMP_Compose
             }
             if (is_a($res, 'PEAR_Error')) {
                 Horde::logMessage($res, __FILE__, __LINE__, PEAR_LOG_ERR);
-                return $res;
+                return IMP_Compose_Exception($res);
             }
         }
 
@@ -2346,12 +2350,14 @@ class IMP_Compose
                     $GLOBALS['notification']->push(sprintf(_("Did not attach \"%s\" as the file was empty."), $filename), 'horde.warning');
                     $success = false;
                 } else {
-                    $result = $this->addUploadAttachment($key);
-                    if (is_a($result, 'PEAR_Error')) {
-                        $GLOBALS['notification']->push($result, 'horde.error');
+                    try {
+                        $result = $this->addUploadAttachment($key);
+                        if ($notify) {
+                            $GLOBALS['notification']->push(sprintf(_("Added \"%s\" as an attachment."), $result), 'horde.success');
+                        }
+                    } catch (IMP_Compose_Exception $e) {
+                        $GLOBALS['notification']->push($e, 'horde.error');
                         $success = false;
-                    } elseif ($notify) {
-                        $GLOBALS['notification']->push(sprintf(_("Added \"%s\" as an attachment."), $result), 'horde.success');
                     }
                 }
             }
@@ -2389,8 +2395,9 @@ class IMP_Compose
             $headers[$val] = $imp_ui->getAddressList(Util::getFormData($val), Util::getFormData($val . '_list'), Util::getFormData($val . '_field'), Util::getFormData($val . '_new'));
         }
 
-        $body = $this->_saveDraftMsg($headers, Util::getFormData('message', ''), Util::getFormData('charset'), Util::getFormData('rtemode'), false);
-        if (is_a($body, 'PEAR_Error')) {
+        try {
+            $body = $this->_saveDraftMsg($headers, Util::getFormData('message', ''), Util::getFormData('charset'), Util::getFormData('rtemode'), false);
+        } catch (IMP_Compose_Exception $e) {
             return;
         }
 
@@ -2426,10 +2433,11 @@ class IMP_Compose
             if (empty($drafts_folder)) {
                 return;
             }
-            $res = $this->_saveDraftServer($data, $drafts_folder);
-            if (!is_a($res, 'PEAR_Error')) {
+
+            try {
+                $this->_saveDraftServer($data, $drafts_folder);
                 $GLOBALS['notification']->push(_("A message you were composing when your session expired has been recovered. You may resume composing your message by going to your Drafts folder."));
-            }
+            } catch (IMP_Compose_Exception $e) {}
         }
     }
 
@@ -2543,3 +2551,23 @@ class IMP_Compose
         return array('sources' => $src, 'fields' => $fields);
     }
 }
+
+class IMP_Compose_Exception extends Horde_Exception
+{
+    protected $_encrypt = null;
+
+    public function __set($name, $val)
+    {
+        if ($name == 'encrypt') {
+            $this->_encrypt = $val;
+        }
+    }
+
+    public function __get($name)
+    {
+        if ($name == 'encrypt') {
+            return $this->_encrypt;
+        }
+    }
+
+}
index 10c8183..1ea76b9 100644 (file)
@@ -79,7 +79,8 @@ class IMP_Contents
      * @param mixed $in  Either an index string (see IMP_Contents::singleton()
      *                   for the format) or a Horde_Mime_Part object.
      *
-     * @return IMP_Contents  The IMP_Contents object or null.
+     * @return IMP_Contents  The IMP_Contents object.
+     * @throws Horde_Exception
      */
     static public function singleton($in)
     {
@@ -101,6 +102,7 @@ class IMP_Contents
      *
      * @param mixed $in  Either an index string (see IMP_Contents::singleton()
      *                   for the format) or a Horde_Mime_Part object.
+     * @throws Horde_Exception
      */
     protected function __construct($in)
     {
@@ -116,7 +118,7 @@ class IMP_Contents
                 ), array('ids' => array($this->_index)));
                 $this->_message = $ret[$this->_index]['structure'];
             } catch (Horde_Imap_Client_Exception $e) {
-                return PEAR::raiseError('Error displaying message.');
+                throw new Horde_Exception('Error displaying message.');
             }
         }
     }
index 52df2e3..19a3e09 100644 (file)
@@ -110,14 +110,14 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
      * @param string $public_key  An PGP public key.
      *
      * @return array  See Horde_Crypt_pgp::pgpPacketInformation()
-     *                Returns PEAR_Error or error.
+     * @throws Horde_Exception
      */
     public function addPublicKey($public_key)
     {
         /* Make sure the key is valid. */
         $key_info = $this->pgpPacketInformation($public_key);
         if (!isset($key_info['signature'])) {
-            return PEAR::raiseError(_("Not a valid public key."), 'horde.error');
+            throw new Horde_Exception(_("Not a valid public key."), 'horde.error');
         }
 
         /* Remove the '_SIGNATURE' entry. */
@@ -271,7 +271,7 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp
      * @param string $method      The method to use - either 'get' or 'put'.
      * @param string $additional  Any additional data.
      *
-     * @return string  See Horde_Crypt_pgp::getPublicKeyserver()  -or-
+     * @return string  See Horde_Crypt_pgp::getPublicKeyserver() -or-
      *                     Horde_Crypt_pgp::putPublicKeyserver().
      */
     protected function _keyserverConnect($data, $method, $additional = null)
index 3dfcac2..491a3a5 100644 (file)
@@ -100,21 +100,20 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
      *
      * @param string $cert  A public certificate to add.
      *
-     * @return boolean  True on successful add.
-     *                  Returns PEAR_Error or error.
+     * @throws Horde_Exception
      */
     public function addPublicKey($cert)
     {
         /* Make sure the certificate is valid. */
         $key_info = openssl_x509_parse($cert);
         if (!is_array($key_info) || !isset($key_info['subject'])) {
-            return PEAR::raiseError(_("Not a valid public key."), 'horde.error');
+            throw new Horde_Exception(_("Not a valid public key."), 'horde.error');
         }
 
         /* Add key to the user's address book. */
         $email = $this->getEmailFromKey($cert);
         if (is_null($email)) {
-            return PEAR::raiseError(_("No email information located in the public key."), 'horde.error');
+            throw new Horde_Exception(_("No email information located in the public key."), 'horde.error');
         }
 
         /* Get the name corresponding to this key. */
@@ -123,15 +122,13 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
         } elseif (isset($key_info['subject']['OU'])) {
             $name = $key_info['subject']['OU'];
         } else {
-            return PEAR::raiseError(_("Not a valid public key."), 'horde.error');
+            throw new Horde_Exception(_("Not a valid public key."), 'horde.error');
         }
 
         $res = $GLOBALS['registry']->call('contacts/addField', array($email, $name, self::PUBKEY_FIELD, $cert, $GLOBALS['prefs']->getValue('add_source')));
         if (is_a($res, 'PEAR_Error')) {
-            return $res;
+            throw new Horde_Exception($res);
         }
-
-        return $key_info;
     }
 
     /**
index 2154224..e513235 100644 (file)
@@ -140,16 +140,18 @@ abstract class IMP_Fetchmail
             if ($driver === false) {
                 continue;
             }
-            $res = $driver->getMail();
 
-            if (is_a($res, 'PEAR_Error')) {
-                $GLOBALS['notification']->push(_("Fetchmail: ") . $res->getMessage(), 'horde.warning');
-            } elseif ($res == 1) {
-                $GLOBALS['notification']->push(_("Fetchmail: ") . sprintf(_("Fetched 1 message from %s"), $fm_account->getValue('id', $val)), 'horde.success');
-            } elseif ($res >= 0) {
-                $GLOBALS['notification']->push(_("Fetchmail: ") . sprintf(_("Fetched %d messages from %s"), $res, $fm_account->getValue('id', $val)), 'horde.success');
-            } else {
-                $GLOBALS['notification']->push(_("Fetchmail: no new messages."), 'horde.success');
+            try {
+                $res = $driver->getMail();
+                if ($res == 1) {
+                    $GLOBALS['notification']->push(_("Fetchmail: ") . sprintf(_("Fetched 1 message from %s"), $fm_account->getValue('id', $val)), 'horde.success');
+                } elseif ($res >= 0) {
+                    $GLOBALS['notification']->push(_("Fetchmail: ") . sprintf(_("Fetched %d messages from %s"), $res, $fm_account->getValue('id', $val)), 'horde.success');
+                } else {
+                    $GLOBALS['notification']->push(_("Fetchmail: no new messages."), 'horde.success');
+                }
+            } catch (Horde_Exception $e) {
+                $GLOBALS['notification']->push(_("Fetchmail: ") . $e->getMessage(), 'horde.warning');
             }
         }
     }
@@ -228,8 +230,8 @@ abstract class IMP_Fetchmail
     /**
      * Gets the mail using the data in this object.
      *
-     * @return mixed  Returns the number of messages retrieved on success.
-     *                Returns PEAR_Error on error.
+     * @return integer  Returns the number of messages retrieved on success.
+     * @throws Horde_Exception
      */
     abstract public function getMail();
 
index dfb11b9..cb2aba3 100644 (file)
@@ -104,12 +104,12 @@ class IMP_Fetchmail_imap extends IMP_Fetchmail
     /**
      * Attempts to connect to the mail server
      *
-     * @return mixed  Returns true on success or PEAR_Error on failure.
+     * @throws Horde_Exception
      */
     protected function _connect()
     {
         if (!is_null($this->_ob)) {
-            return true;
+            return;
         }
 
         $protocols = $this->_protocolList();
@@ -125,9 +125,8 @@ class IMP_Fetchmail_imap extends IMP_Fetchmail
 
         try {
             $this->_ob = Horde_Imap_Client::getInstance(($protocols[$this->_params['protocol']]['string'] == 'imap') ? 'Socket' : 'Cclient_pop3', $imap_config);
-            return true;
         } catch (Horde_Imap_Client_Exception $e) {
-            return PEAR::raiseError(_("Cannot connect to the remote mail server: ") . $e->getMessage());
+            throw new Horde_Exception(_("Cannot connect to the remote mail server: ") . $e->getMessage());
         }
     }
 
@@ -135,6 +134,7 @@ class IMP_Fetchmail_imap extends IMP_Fetchmail
      * Gets the mail using the data in this object.
      *
      * @see IMP_Fetchmail::getMail()
+     * @throws Horde_Exception
      */
     public function getMail()
     {
@@ -142,9 +142,6 @@ class IMP_Fetchmail_imap extends IMP_Fetchmail
         $numMsgs = 0;
 
         $stream = $this->_connect();
-        if (is_a($stream, 'PEAR_Error')) {
-            return $stream;
-        }
 
         /* Check to see if remote mailbox exists. */
         $mbox = $this->_params['rmailbox'];
@@ -162,7 +159,7 @@ class IMP_Fetchmail_imap extends IMP_Fetchmail
         }
 
         if (!$mbox) {
-            return PEAR::raiseError(_("Invalid Remote Mailbox"));
+            throw new Horde_Exception(_("Invalid Remote Mailbox"));
         }
 
         $query = new Horde_Imap_Client_Search_Query();
@@ -221,4 +218,5 @@ class IMP_Fetchmail_imap extends IMP_Fetchmail
 
         return $numMsgs;
     }
+
 }
index 13f7d55..7b10824 100644 (file)
@@ -140,14 +140,14 @@ class IMP_IMAP_ACL
      * @param string $mbox  The mailbox to get the ACL for.
      *
      * @return array  A hash containing information on the ACL.
+     * @throws Horde_Exception
      */
     public function getACL($mbox)
     {
         try {
             return $GLOBALS['imp_imap']->ob->getACL($mbox);
         } catch (Horde_Imap_Client_Exception $e) {
-            // return PEAR::raiseError(_("Could not retrieve ACL"));
-            return array();
+            throw new Horde_Exception(_("Could not retrieve ACL"));
         }
     }
 
@@ -156,18 +156,17 @@ class IMP_IMAP_ACL
      *
      * @param string $mbox  The mailbox on which to edit the ACL.
      * @param string $user  The user to grant rights to.
-     * @param array $acl    The keys of which are the
-     *                      rights to be granted (see RFC 2086).
+     * @param array $acl    The keys of which are the rights to be granted
+     *                      (see RFC 2086).
      *
-     * @return mixed  True on success, PEAR_Error on error.
+     * @throws Horde_Exception
      */
     public function editACL($mbox, $user, $acl)
     {
         try {
             $GLOBALS['imp_imap']->ob->setACL($mbox, $user, array('rights' => $acl));
-            return true;
         } catch (Horde_Imap_Client_Exception $e) {
-            return PEAR::raiseError(sprintf(_("Couldn't give user \"%s\" the following rights for the folder \"%s\": %s"), $user, $mbox, implode('', $acl)));
+            throw new Horde_Exception(sprintf(_("Couldn't give user \"%s\" the following rights for the folder \"%s\": %s"), $user, $mbox, implode('', $acl)));
         }
     }
 
index 56966b7..aace11e 100644 (file)
@@ -1964,7 +1964,8 @@ class IMP_IMAP_Tree
      * @param string $parent  The parent name (UTF7-IMAP).
      * @param string $parent  The new mailbox name (UTF7-IMAP).
      *
-     * @return string  The full path to the new mailbox, or PEAR_Error.
+     * @return string  The full path to the new mailbox.
+     * @throws Horde_Exception
      */
     public function createMailboxName($parent, $new)
     {
@@ -1976,7 +1977,7 @@ class IMP_IMAP_Tree
                     return $new;
                 }
             }
-            return PEAR::raiseError(_("Cannot directly create mailbox in this folder."), 'horde.error');
+            throw new Horde_Exception(_("Cannot directly create mailbox in this folder."), 'horde.error');
         }
 
         $mbox = $ns_info['name'];
index f517f6a..6234f1a 100644 (file)
@@ -123,19 +123,17 @@ class IMP
      * @param string $slug   TODO
      * @param string $token  TODO
      *
-     * @return  TODO
+     * @throws Horde_Exception
      */
     static public function checkRequestToken($slug, $token)
     {
         if (empty($_SESSION['horde_form_secrets'][$token])) {
-            return PEAR::raiseError(_("We cannot verify that this request was really sent by you. It could be a malicious request. If you intended to perform this action, you can retry it now."));
+            throw new Horde_Exception(_("We cannot verify that this request was really sent by you. It could be a malicious request. If you intended to perform this action, you can retry it now."));
         }
 
         if ($_SESSION['horde_form_secrets'][$token] + $GLOBALS['conf']['server']['token_lifetime'] < time()) {
-            return PEAR::raiseError(sprintf(_("This request cannot be completed because the link you followed or the form you submitted was only valid for %d minutes. Please try again now."), round($GLOBALS['conf']['server']['token_lifetime'] / 60)));
+            throw new Horde_Exception(sprintf(_("This request cannot be completed because the link you followed or the form you submitted was only valid for %d minutes. Please try again now."), round($GLOBALS['conf']['server']['token_lifetime'] / 60)));
         }
-
-        return true;
     }
 
     /**
@@ -747,14 +745,11 @@ class IMP
             return false;
         }
 
-        $quotaDriver = IMP_Quota::singleton($_SESSION['imp']['quota']['driver'], $_SESSION['imp']['quota']['params']);
-        if ($quotaDriver === false) {
-            return false;
-        }
-
-        $quota = $quotaDriver->getQuota();
-        if (is_a($quota, 'PEAR_Error')) {
-            Horde::logMessage($quota, __FILE__, __LINE__, PEAR_LOG_ERR);
+        try {
+            $quotaDriver = IMP_Quota::singleton($_SESSION['imp']['quota']['driver'], $_SESSION['imp']['quota']['params']);
+            $quota = $quotaDriver->getQuota();
+        } catch (Horde_Exception $e) {
+            Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
             return false;
         }
 
index 145f3a5..651b823 100644 (file)
@@ -191,15 +191,15 @@ class IMP_Mailbox
                          !$GLOBALS['prefs']->getValue('preview_show_unread') ||
                          !in_array('\\seen', $v['flags']))) {
                         if (empty($preview_info[$k])) {
-                            $imp_contents = IMP_Contents::singleton($k . IMP::IDX_SEP . $mbox);
-                            if (is_a($imp_contents, 'PEAR_Error')) {
-                                $preview_info[$k] = array('IMPpreview' => '', 'IMPpreviewc' => false);
-                            } else {
+                            try {
+                                $imp_contents = IMP_Contents::singleton($k . IMP::IDX_SEP . $mbox);
                                 $prev = $imp_contents->generatePreview();
                                 $preview_info[$k] = array('IMPpreview' => $prev['text'], 'IMPpreviewc' => $prev['cut']);
                                 if (!is_null($cache)) {
                                     $tostore[$k] = $preview_info[$k];
                                 }
+                            } catch (Horde_Exception $e) {
+                                $preview_info[$k] = array('IMPpreview' => '', 'IMPpreviewc' => false);
                             }
                         }
 
index 949bf68..d1a4138 100644 (file)
@@ -41,7 +41,7 @@ class Maintenance_Task_tos_agreement extends Maintenance_Task
     function describeMaintenance()
     {
         if (empty($GLOBALS['conf']['tos']['file'])) {
-            Horde::fatal(PEAR::raiseError(sprintf(_("Terms of Service file not specified in conf.php"))), __FILE__, __LINE__);
+            Horde::fatal(new Horde_Exception(sprintf(_("Terms of Service file not specified in conf.php"))), __FILE__, __LINE__);
         }
 
         return file_get_contents($GLOBALS['conf']['tos']['file']);
index 9278276..b02bc20 100644 (file)
@@ -428,25 +428,25 @@ class IMP_Message
      * @param string $partid  The MIME ID of the part to strip. All parts are
      *                        stripped if null.
      *
-     * @return mixed  Returns true on success, or PEAR_Error on error.
+     * @throws Horde_Exception
      */
     public function stripPart($indices, $partid = null)
     {
         /* Return error if no index was provided. */
         if (!($msgList = IMP::parseIndicesList($indices))) {
-            return PEAR::raiseError(_("An error occured while attempting to strip the attachment."));
+            throw new Horde_Exception(_("An error occured while attempting to strip the attachment."));
         }
 
         /* If more than one index provided, return error. */
         reset($msgList);
         list($mbox, $index) = each($msgList);
         if (each($msgList) || (count($index) > 1)) {
-            return PEAR::raiseError(_("An error occured while attempting to strip the attachment."));
+            throw new Horde_Exception(_("An error occured while attempting to strip the attachment."));
         }
         $index = implode('', $index);
 
         if ($GLOBALS['imp_imap']->isReadOnly($mbox)) {
-            return PEAR::raiseError(_("Cannot strip the MIME part as the mailbox is read-only"));
+            throw new Horde_Exception(_("Cannot strip the MIME part as the mailbox is read-only"));
         }
 
         /* Get a local copy of the message. */
@@ -503,7 +503,7 @@ class IMP_Message
 
             $uid = $GLOBALS['imp_imap']->ob->append($mbox, array(array('data' => $res['headertext'][0] . $message->toString(false), 'flags' => $res['flags'], 'messageid' => $res['envelope']['message-id'])));
         } catch (Horde_Imap_Client_Exception $e) {
-            return PEAR::raiseError(_("An error occured while attempting to strip the attachment."));
+            throw new Horde_Exception(_("An error occured while attempting to strip the attachment."));
         }
 
         $this->delete($indices, true, true);
@@ -514,8 +514,6 @@ class IMP_Message
         /* We need to replace the old index in the query string with the
          * new index. */
         $_SERVER['QUERY_STRING'] = preg_replace('/' . $index . '/', reset($uid), $_SERVER['QUERY_STRING']);
-
-        return true;
     }
 
     /**
index 7539ec2..3948b8b 100644 (file)
@@ -40,7 +40,8 @@ class IMP_Quota
      * @param array $params   A hash containing any additional configuration
      *                        or connection parameters a subclass might need.
      *
-     * @return mixed  The created concrete instance, or false on error.
+     * @return IMP_Quota  The concrete instance.
+     * @throws Horde_Exception
      */
     static public function singleton($driver, $params = array())
     {
@@ -48,7 +49,7 @@ class IMP_Quota
         $signature = md5(serialize(array($driver, $params)));
 
         if (!isset(self::$_instances[$signature])) {
-            self::$_instances[$signature] = IMP_Quota::factory($driver, $params);
+            self::$_instances[$signature] = IMP_Quota::getInstance($driver, $params);
         }
 
         return self::$_instances[$signature];
@@ -61,17 +62,20 @@ class IMP_Quota
      * @param array $params   A hash containing any additional configuration or
      *                        connection parameters a subclass might need.
      *
-     * @return mixed  The newly created concrete instance, or false on error.
+     * @return IMP_Quota  The concrete instance.
+     * @throws Horde_Exception
      */
-    static public function factory($driver, $params = array())
+    static public function getInstance($driver, $params = array())
     {
         $driver = basename($driver);
         require_once dirname(__FILE__) . '/Quota/' . $driver . '.php';
         $class = 'IMP_Quota_' . $driver;
 
-        return class_exists($class)
-            ? new $class($params)
-            : false;
+        if (class_exists($class)) {
+            return new $class($params);
+        }
+
+        throw new Horde_Exception('Could not create IMP_Quota instance: ' . $driver, 'horde.error');
     }
 
     /**
@@ -79,7 +83,7 @@ class IMP_Quota
      *
      * @param array $params  Hash containing connection parameters.
      */
-    public function __construct($params = array())
+    protected function __construct($params = array())
     {
         $this->_params = $params;
 
@@ -93,10 +97,10 @@ class IMP_Quota
     /**
      * Get quota information (used/allocated), in bytes.
      *
-     * @return mixed  Returns PEAR_Error on failure. Otherwise, returns an
-     *                array with the following keys:
+     * @return array  An array with the following keys:
      *                'limit' = Maximum quota allowed
      *                'usage' = Currently used portion of quota (in bytes)
+     * @throws Horde_Exception
      */
     public function getQuota()
     {
index e5687a3..ac0b44e 100644 (file)
@@ -30,7 +30,7 @@ class IMP_Quota_command extends IMP_Quota
      *
      * @param array $params  Hash containing connection parameters.
      */
-    function __construct($params = array())
+    protected function __construct($params = array())
     {
         $params = array_merge(array('quota_path' => 'quota',
                                     'grep_path'  => 'grep',
@@ -48,6 +48,8 @@ class IMP_Quota_command extends IMP_Quota
      * large number of reasons this may fail, such as OS support,
      * SELinux interference, the file being > 2 GB in size, the file
      * we're referring to not being readable, etc.
+     *
+     * @return integer  The disk block size.
      */
     protected function _blockSize()
     {
@@ -60,10 +62,10 @@ class IMP_Quota_command extends IMP_Quota
     /**
      * Get quota information (used/allocated), in bytes.
      *
-     * @return mixed  Returns PEAR_Error on failure. Otherwise, returns an
-     *                array with the following keys:
+     * @return array  An array with the following keys:
      *                'limit' = Maximum quota allowed
      *                'usage' = Currently used portion of quota (in bytes)
+     * @throws Horde_Exception
      */
     public function getQuota()
     {
@@ -81,7 +83,8 @@ class IMP_Quota_command extends IMP_Quota
            return array('usage' => $quota[1] * $blocksize,
                         'limit' => $quota[2] * $blocksize);
         }
-        return PEAR::raiseError(_("Unable to retrieve quota"), 'horde.error');
+
+        throw new Horde_Exception(_("Unable to retrieve quota"), 'horde.error');
     }
 
 }
index 1974341..1941be6 100644 (file)
@@ -23,21 +23,18 @@ class IMP_Quota_hook extends IMP_Quota
     /**
      * Get quota information (used/allocated), in bytes.
      *
-     * @return mixed  Returns PEAR_Error on failure. Otherwise, returns an
-     *                array with the following keys:
+     * @return array  An array with the following keys:
      *                'limit' = Maximum quota allowed
      *                'usage' = Currently used portion of quota (in bytes)
+     * @throws Horde_Exception
      */
     public function getQuota()
     {
         $quota = Horde::callHook('_imp_hook_quota', $this->_params, 'imp');
-        if (is_a($quota, 'PEAR_Error')) {
-            return $quota;
-        }
 
         if (count($quota) != 2) {
             Horde::logMessage('Incorrect number of return values from quota hook.', __FILE__, __LINE__, PEAR_LOG_ERR);
-            return PEAR::raiseError(_("Unable to retrieve quota"), 'horde.error');
+            throw new Horde_Exception(_("Unable to retrieve quota"), 'horde.error');
         }
 
         return array('usage' => $quota[0], 'limit' => $quota[1]);
index db532d7..6a30daf 100644 (file)
@@ -15,20 +15,21 @@ class IMP_Quota_imap extends IMP_Quota
     /**
      * Get quota information (used/allocated), in bytes.
      *
-     * @return mixed  Returns PEAR_Error on failure. Otherwise, returns an
-     *                array with the following keys:
+     * @return array  An array with the following keys:
      *                'limit' = Maximum quota allowed
      *                'usage' = Currently used portion of quota (in bytes)
+     * @throws Horde_Exception
      */
     public function getQuota()
     {
         try {
             $quota = $GLOBALS['imp_imap']->ob->getQuotaRoot($GLOBALS['imp_search']->isSearchMbox($GLOBALS['imp_mbox']['mailbox']) ? 'INBOX' : $GLOBALS['imp_mbox']['mailbox']);
-            $quota_val = reset($quota);
-            return array('usage' => $quota['storage']['usage'] * 1024, 'limit' => $quota['storage']['limit'] * 1024);
         } catch (Horde_Imap_Client_Exception $e) {
-            return PEAR::raiseError(_("Unable to retrieve quota"), 'horde.error');
+            throw new Horde_Exception(_("Unable to retrieve quota"), 'horde.error');
         }
+
+        $quota_val = reset($quota);
+        return array('usage' => $quota['storage']['usage'] * 1024, 'limit' => $quota['storage']['limit'] * 1024);
     }
 
 }
index 33c2482..00a0df1 100644 (file)
  *     )
  * );
  *
- * logfile    --  The path/to/filename of the log file to use.
- * taillines  --  The number of lines to look at in the tail of the logfile.
- * FTPmail    --  If you want to show what FTP space is available (IMAP folder)
- *                or what mail space is available (INBOX).
- *                Defines the search string to username:
- *                  FTPmail to identify the line with QUOTA info.
- * beginocc   --  String that designates the characters before the usage
- *                number.
- * midocc     --  String between usage and total storage space.
- * endocc     --  String after the storage number.
+ * logfile - The path/to/filename of the log file to use.
+ * taillines - The number of lines to look at in the tail of the logfile.
+ * FTPmail - If you want to show what FTP space is available (IMAP folder)
+ *           or what mail space is available (INBOX).
+ *           Defines the search string to username:
+ *             FTPmail to identify the line with QUOTA info.
+ * beginocc - String that designates the characters before the usage
+ *            number.
+ * midocc - String between usage and total storage space.
+ * endocc - String after the storage number.
  *
  * See the enclosed file COPYING for license information (GPL). If you
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
@@ -41,31 +41,30 @@ class IMP_Quota_logfile extends IMP_Quota
      *
      * @param array $params  Hash containing connection parameters.
      */
-    function __construct($params = array())
+    protected function __construct($params = array())
     {
-        $params = array_merge(array(
+        parent::__construct(array_merge(array(
             'logfile' => '',
             'taillines' => 10,
             'FTPmail' => 'FTP',
             'beginocc' => 'usage = ',
             'midocc' => ' of ',
             'endocc' => ' bytes'
-        ), $params);
-        parent::__construct($params);
+        ), $params));
     }
 
     /**
      * Get quota information (used/allocated), in bytes.
      *
-     * @return mixed  Returns PEAR_Error on failure. Otherwise, returns an
-     *                array with the following keys:
+     * @return array  An array with the following keys:
      *                'limit' = Maximum quota allowed
      *                'usage' = Currently used portion of quota (in bytes)
+     * @throws Horde_Exception
      */
     public function getQuota()
     {
         if (!is_file($this->_params['logfile'])) {
-            return PEAR::raiseError(_("Unable to retrieve quota"), 'horde.error');
+            throw new Horde_Exception(_("Unable to retrieve quota"), 'horde.error');
         }
 
         $full = file($this->_params['logfile']);
index 8b131cf..804067b 100644 (file)
  *     )
  * );
  *
- * path -- The path to the user's Maildir directory. You may use the
- *         two-character sequence "~U" to represent the user's account name,
- *         and the actual username will be substituted in that location.
- *         E.g., '/home/~U/Maildir/' or '/var/mail/~U/Maildir/'
+ * path - The path to the user's Maildir directory. You may use the
+ *        two-character sequence "~U" to represent the user's account name,
+ *        and the actual username will be substituted in that location.
+ *        E.g., '/home/~U/Maildir/' or '/var/mail/~U/Maildir/'
+ *
+ * Copyright 2007-2009 The Horde Project (http://www.horde.org/)
  *
  * See the enclosed file COPYING for license information (GPL). If you
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  *
- * @author  Eric Rostetter
+ * @author  Eric Rostetter <eric.rostetter@physics.utexas.edu>
  * @package IMP_Quota
  */
 class IMP_Quota_Maildir extends IMP_Quota
@@ -32,19 +34,18 @@ class IMP_Quota_Maildir extends IMP_Quota
      *
      * @param array $params  Hash containing connection parameters.
      */
-    function __construct($params = array())
+    protected function __construct($params = array())
     {
-        $params = array_merge(array('path' => ''), $params);
-        parent::__construct($params);
+        parent::__construct(array_merge(array('path' => ''), $params));
     }
 
     /**
      * Returns quota information (used/allocated), in bytes.
      *
-     * @return mixed  Returns PEAR_Error on failure. Otherwise, returns an
-     *                array with the following keys:
+     * @return array  An array with the following keys:
      *                'limit' = Maximum quota allowed
      *                'usage' = Currently used portion of quota (in bytes)
+     * @throws Horde_Exception
      */
     public function getQuota()
     {
@@ -59,7 +60,7 @@ class IMP_Quota_Maildir extends IMP_Quota
 
         // Read in the quota file and parse it, if possible.
         if (!is_file($full)) {
-            return PEAR::raiseError(_("Unable to retrieve quota"));
+            throw new Horde_Exception(_("Unable to retrieve quota"));
         }
 
         // Read in maildir quota file.
index 46ca2f5..7dde77e 100644 (file)
@@ -18,10 +18,10 @@ class IMP_Quota_mdaemon extends IMP_Quota
     /**
      * Get quota information (used/allocated), in bytes.
      *
-     * @return mixed  Returns PEAR_Error on failure. Otherwise, returns an
-     *                array with the following keys:
+     * @return array  An array with the following keys:
      *                'limit' = Maximum quota allowed
      *                'usage' = Currently used portion of quota (in bytes)
+     * @throws Horde_Exception
      */
     public function getQuota()
     {
@@ -40,7 +40,7 @@ class IMP_Quota_mdaemon extends IMP_Quota
             }
         }
 
-        return PEAR::raiseError(_("Unable to retrieve quota"), 'horde.error');
+        throw new Horde_Exception(_("Unable to retrieve quota"), 'horde.error');
     }
 
     /**
index cfdeb15..001d47e 100644 (file)
@@ -43,8 +43,7 @@ class IMP_Quota_mercury32 extends IMP_Quota
     /**
      * Get quota information (used/allocated), in bytes.
      *
-     * @return mixed  Returns PEAR_Error on failure. Otherwise, returns an
-     *                array with the following keys:
+     * @return array  An array with the following keys:
      *                'limit' = Maximum quota allowed
      *                'usage' = Currently used portion of quota (in bytes)
      */
@@ -63,7 +62,8 @@ class IMP_Quota_mercury32 extends IMP_Quota
                 return array('usage' => $quota, 'limit' => 0);
             }
         }
-        return PEAR::raiseError(_("Unable to retrieve quota"), 'horde.error');
+
+        throw new Horde_Exception(_("Unable to retrieve quota"), 'horde.error');
     }
 
 }
index 162b1e3..ecba1e0 100644 (file)
  * <code>
  * 'quota' => array(
  *     'driver' => 'sql',
- *     'params' => array_merge($GLOBALS['conf']['sql'],
- *                             array('query_quota' => 'SELECT quota FROM quotas WHERE user = ?',
- *                                   'query_used' => 'SELECT used FROM quotas WHERE user = ?'))
+ *     'params' => array_merge(
+ *         $GLOBALS['conf']['sql'],
+ *         array(
+ *             'query_quota' => 'SELECT quota FROM quotas WHERE user = ?',
+ *             'query_used' => 'SELECT used FROM quotas WHERE user = ?'
+ *         )
+ *     )
  * ),
  * </code>
  *
@@ -57,7 +61,7 @@ class IMP_Quota_sql extends IMP_Quota
     /**
      * Connects to the database
      *
-     * @return boolean  True on success, PEAR_Error on failure.
+     * @throws Horde_Exception
      */
     protected function _connect()
     {
@@ -67,7 +71,7 @@ class IMP_Quota_sql extends IMP_Quota
                                       array('persistent' => !empty($this->_params['persistent']),
                                             'ssl' => !empty($this->_params['ssl'])));
             if (is_a($this->_db, 'PEAR_Error')) {
-                return PEAR::raiseError(_("Unable to connect to SQL server."));
+                throw new Horde_Exception(_("Unable to connect to SQL server."));
             }
 
             $this->_connected = true;
@@ -79,18 +83,14 @@ class IMP_Quota_sql extends IMP_Quota
     /**
      * Returns quota information.
      *
-     * @return mixed  Returns PEAR_Error on failure. Otherwise, returns an
-     *                array with the following keys:
+     * @return array  An array with the following keys:
      *                'limit' = Maximum quota allowed
      *                'usage' = Currently used portion of quota (in bytes)
+     * @throws Horde_Exception
      */
-    function getQuota()
+    public function getQuota()
     {
         $conn = $this->_connect();
-        if (is_a($conn, 'PEAR_Error')) {
-            return $conn;
-        }
-
         $user = $_SESSION['imp']['user'];
         $quota = array('limit' => 0, 'usage' => 0);
 
@@ -104,7 +104,7 @@ class IMP_Quota_sql extends IMP_Quota
                                  $this->_params['query_quota']);
             $result = $this->_db->query($query);
             if (is_a($result, 'PEAR_Error')) {
-                return $result;
+                throw new Horde_Exception($result);
             }
 
             $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
@@ -125,7 +125,7 @@ class IMP_Quota_sql extends IMP_Quota
                                  $this->_params['query_used']);
             $result = $this->_db->query($query);
             if (is_a($result, 'PEAR_Error')) {
-                return $result;
+                throw new Horde_Exception($result);
             }
 
             $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
index b38779c..521463d 100644 (file)
@@ -40,8 +40,9 @@ class IMP_Spam
             foreach ($msgIndices as $idx) {
                 /* Fetch the raw message contents (headers and complete
                  * body). */
-                $imp_contents = &IMP_Contents::singleton($idx . IMP::IDX_SEP . $mbox);
-                if (is_a($imp_contents, 'PEAR_Error')) {
+                try {
+                    $imp_contents = &IMP_Contents::singleton($idx . IMP::IDX_SEP . $mbox);
+                } catch (Horde_Exception $e) {
                     continue;
                 }
 
@@ -123,8 +124,12 @@ class IMP_Spam
                     $spam_headers->addHeader('Subject', sprintf(_("%s report from %s"), $action, $_SESSION['imp']['uniquser']));
 
                     /* Send the message. */
-                    $imp_compose->sendMessage($to, $spam_headers, $mime, NLS::getCharset());
-                    $report_flag = true;
+                    try {
+                        $imp_compose->sendMessage($to, $spam_headers, $mime, NLS::getCharset());
+                        $report_flag = true;
+                    } catch (IMP_Compose_Exception $e) {
+                        Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
+                    }
                 }
 
                 if ($report_flag) {
index b896bc6..67d264c 100644 (file)
@@ -41,12 +41,15 @@ class IMP_UI_Compose
 
     /**
      * $encoding = DEPRECATED
+     *
+     * @throws Horde_Exception
      */
     function redirectMessage($to, $imp_compose, $contents, $encoding)
     {
-        $recip = $imp_compose->recipientList(array('to' => $to));
-        if (is_a($recip, 'PEAR_Error')) {
-            return $recip;
+        try {
+            $recip = $imp_compose->recipientList(array('to' => $to));
+        } catch (IMP_Compose_Exception $e) {
+            throw new Horde_Exception($recip);
         }
         $recipients = implode(', ', $recip['list']);
 
@@ -67,18 +70,16 @@ class IMP_UI_Compose
         $headers->removeHeader('return-path');
         $headers->addHeader('Return-Path', $from_addr);
 
-        $bodytext = $contents->getBody();
-        $status = $imp_compose->sendMessage($recipients, $headers, $bodytext, $charset);
-        $error = is_a($status, 'PEAR_Error');
-
         /* Store history information. */
         if (!empty($GLOBALS['conf']['maillog']['use_maillog'])) {
             IMP_Maillog::log('redirect', $headers->getValue('message-id'), $recipients);
         }
 
-        if ($error) {
-            Horde::logMessage($status->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
-            return $status;
+        $bodytext = $contents->getBody();
+        try {
+            $imp_compose->sendMessage($recipients, $headers, $bodytext, $charset);
+        } catch (IMP_Compose_Exception $e) {
+            throw new Horde_Exception($e);
         }
 
         $entry = sprintf("%s Redirected message sent to %s from %s",
@@ -89,8 +90,6 @@ class IMP_UI_Compose
             $sentmail = IMP_Sentmail::factory();
             $sentmail->log('redirect', $headers->getValue('message-id'), $recipients);
         }
-
-        return true;
     }
 
     /**
index 4c61383..75b504a 100644 (file)
@@ -122,8 +122,9 @@ class IMP_Views_ShowMessage
         }
 
         /* Parse MIME info and create the body of the message. */
-        $imp_contents = &IMP_Contents::singleton($index . IMP::IDX_SEP . $folder);
-        if (is_a($imp_contents, 'PEAR_Error')) {
+        try {
+            $imp_contents = &IMP_Contents::singleton($index . IMP::IDX_SEP . $folder);
+        } catch (Horde_Exception $e) {
             $result['error'] = $error_msg;
             $result['errortype'] = 'horde.error';
             return $result;
index 59a354b..05f85bd 100644 (file)
@@ -105,9 +105,10 @@ $open_compose_window = null;
 
 /* Run through the action handlers */
 if ($actionID && ($actionID != 'message_missing')) {
-    $result = IMP::checkRequestToken('imp.mailbox', Util::getFormData('mailbox_token'));
-    if (is_a($result, 'PEAR_Error')) {
-        $notification->push($result);
+    try {
+        IMP::checkRequestToken('imp.mailbox', Util::getFormData('mailbox_token'));
+    } catch (Horde_Exception $e) {
+        $notification->push($e);
         $actionID = null;
     }
 }
index 349a87a..c40c6aa 100644 (file)
@@ -54,10 +54,8 @@ case 'u':
     if ($actionID == 'u') {
         $imp_message->undelete($indices_array);
     } else {
-        $result = IMP::checkRequestToken('imp.message-mimp', Util::getFormData('mt'));
-        if (is_a($result, 'PEAR_Error')) {
-            $notification->push($result);
-        } else {
+        try {
+            IMP::checkRequestToken('imp.message-mimp', Util::getFormData('mt'));
             $imp_message->delete($indices_array);
             if ($prefs->getValue('mailbox_return')) {
                 header('Location: ' . Util::addParameter(IMP::generateIMPUrl('mailbox-mimp.php', $imp_mbox['mailbox']), array('s' => $imp_mailbox->getMessageIndex()), null, false));
@@ -68,6 +66,8 @@ case 'u':
                 !$GLOBALS['prefs']->getValue('use_trash')) {
                 $imp_mailbox->setIndex(1, 'offset');
             }
+        } catch (Horde_Exception $e) {
+            $notification->push($e);
         }
     }
     break;
@@ -112,8 +112,9 @@ $mime_headers = $fetch_ret[$index]['headertext'][0];
 $use_pop = ($_SESSION['imp']['protocol'] == 'pop');
 
 /* Parse the message. */
-$imp_contents = &IMP_Contents::singleton($index . IMP::IDX_SEP . $mailbox_name);
-if (is_a($imp_contents, 'PEAR_Error')) {
+try {
+    $imp_contents = &IMP_Contents::singleton($index . IMP::IDX_SEP . $mailbox_name);
+} catch (Horde_Exception $e) {
     header('Location: ' . Util::addParameter(IMP::generateIMPUrl('mailbox-mimp.php', $mailbox_name), array('a' => 'm'), null, false));
     exit;
 }
index 60edac8..13aaa59 100644 (file)
@@ -49,9 +49,10 @@ $user_identity = &Identity::singleton(array('imp', 'imp'));
 /* Run through action handlers. */
 $actionID = Util::getFormData('actionID');
 if ($actionID && ($actionID != 'print_message')) {
-    $result = IMP::checkRequestToken('imp.message', Util::getFormData('message_token'));
-    if (is_a($result, 'PEAR_Error')) {
-        $notification->push($result);
+    try {
+        IMP::checkRequestToken('imp.message', Util::getFormData('message_token'));
+    } catch (Horde_Exception $e) {
+        $notification->push($e);
         $actionID = null;
     }
 }
@@ -165,9 +166,10 @@ case 'add_address':
 
 case 'strip_all':
 case 'strip_attachment':
-    $result = $imp_message->stripPart($indices_array, ($actionID == 'strip_all') ? null : Util::getFormData('imapid'));
-    if (is_a($result, 'PEAR_Error')) {
-        $notification->push($result, 'horde.error');
+    try {
+        $imp_message->stripPart($indices_array, ($actionID == 'strip_all') ? null : Util::getFormData('imapid'));
+    } catch (Horde_Exception $e) {
+        $notification->push($e, 'horde.error');
     }
     break;
 }
@@ -212,8 +214,9 @@ $mime_headers = reset($fetch_ret[$index]['headertext']);
 $use_pop = ($_SESSION['imp']['protocol'] == 'pop');
 
 /* Parse the message. */
-$imp_contents = &IMP_Contents::singleton($index . IMP::IDX_SEP . $mailbox_name);
-if (is_a($imp_contents, 'PEAR_Error')) {
+try {
+    $imp_contents = &IMP_Contents::singleton($index . IMP::IDX_SEP . $mailbox_name);
+} catch (Horde_Exception $e) {
     _returnToMailbox(null, 'message_missing');
     require IMP_BASE . '/mailbox.php';
     exit;
index 2bec464..1cef3fb 100644 (file)
@@ -115,16 +115,16 @@ case 'process_import_public_key':
         _importKeyDialog('process_import_public_key');
     } else {
         /* Add the public key to the storage system. */
-        $key_info = $imp_pgp->addPublicKey($publicKey);
-        if (is_a($key_info, 'PEAR_Error')) {
-            $notification->push($key_info, 'horde.error');
-            $actionID = 'import_public_key';
-            _importKeyDialog('process_import_public_key');
-        } else {
+        try {
+            $imp_pgp->addPublicKey($publicKey);
             foreach ($key_info['signature'] as $sig) {
                 $notification->push(sprintf(_("PGP Public Key for \"%s (%s)\" was successfully added."), $sig['name'], $sig['email']), 'horde.success');
             }
             _reloadWindow();
+        } catch (Horde_Exception $e) {
+            $notification->push($e, 'horde.error');
+            $actionID = 'import_public_key';
+            _importKeyDialog('process_import_public_key');
         }
     }
     exit;
@@ -239,9 +239,10 @@ case 'save_options':
 
 case 'save_attachment_public_key':
     /* Retrieve the key from the message. */
-    $contents = &IMP_Contents::singleton(Util::getFormData('uid') . IMP::IDX_SEP . Util::getFormData('mailbox'));
-    if (is_a($contents, 'PEAR_Error')) {
-        Horde::fatal($contents, __FILE__, __LINE__);
+    try {
+        $contents = &IMP_Contents::singleton(Util::getFormData('uid') . IMP::IDX_SEP . Util::getFormData('mailbox'));
+    } catch (Horde_Exception $e) {
+        Horde::fatal($e, __FILE__, __LINE__);
     }
     $mime_part = $contents->getMIMEPart(Util::getFormData('mime_id'));
     if (empty($mime_part)) {
@@ -249,11 +250,11 @@ case 'save_attachment_public_key':
     }
 
     /* Add the public key to the storage system. */
-    $key_info = $imp_pgp->addPublicKey($mime_part->getContents());
-    if (is_a($key_info, 'PEAR_Error')) {
-        $notification->push($key_info, $key_info->getCode());
-    } else {
+    try {
+        $imp_pgp->addPublicKey($mime_part->getContents());
         Util::closeWindowJS();
+    } catch (Horde_Exception $e) {
+        $notification->push($e, $key_info->getCode());
     }
     exit;
 
index 8494089..cfec5ed 100644 (file)
@@ -112,14 +112,14 @@ case 'process_import_public_key':
         _importKeyDialog('process_import_public_key');
     } else {
         /* Add the public key to the storage system. */
-        $key_info = $imp_smime->addPublicKey($publicKey);
-        if (is_a($key_info, 'PEAR_Error')) {
-            $notification->push($key_info, 'horde.error');
-            $actionID = 'import_public_key';
-            _importKeyDialog('process_import_public_key');
-        } else {
+        try {
+            $imp_smime->addPublicKey($publicKey);
             $notification->push(_("S/MIME Public Key successfully added."), 'horde.success');
             _reloadWindow();
+        } catch (Horde_Exception $e) {
+            $notification->push($e, 'horde.error');
+            $actionID = 'import_public_key';
+            _importKeyDialog('process_import_public_key');
         }
     }
     exit;
@@ -175,9 +175,10 @@ case 'process_import_personal_certs':
 
 case 'save_attachment_public_key':
     /* Retrieve the key from the message. */
-    $contents = &IMP_Contents::singleton(Util::getFormData('uid') . IMP::IDX_SEP . Util::getFormData('mailbox'));
-    if (is_a($contents, 'PEAR_Error')) {
-        Horde::fatal($contents, __FILE__, __LINE__);
+    try {
+        $contents = &IMP_Contents::singleton(Util::getFormData('uid') . IMP::IDX_SEP . Util::getFormData('mailbox'));
+    } catch (Horde_Exception $e) {
+        Horde::fatal($e, __FILE__, __LINE__);
     }
     $mime_part = $contents->getMIMEPart(Util::getFormData('mime_id'));
     if (empty($mime_part)) {
@@ -185,11 +186,11 @@ case 'save_attachment_public_key':
     }
 
     /* Add the public key to the storage system. */
-    $cert = $imp_smime->addPublicKey($mime_part);
-    if ($cert == false) {
-        $notification->push(_("No Certificate found"), 'horde.error');
-    } else {
+    try {
+        $imp_smime->addPublicKey($mime_part);
         Util::closeWindowJS();
+    } catch (Horde_Exception $e) {
+        $notification->push(_("No Certificate found"), 'horde.error');
     }
     exit;
 
index 31e294e..cfaf9fd 100644 (file)
@@ -70,9 +70,10 @@ if ($actionID == 'compose_attach_preview') {
         exit;
     }
 
-    $contents = &IMP_Contents::singleton($index . IMP::IDX_SEP . $mailbox);
-    if (is_a($contents, 'PEAR_Error')) {
-        Horde::fatal($contents, __FILE__, __LINE__);
+    try {
+        $contents = &IMP_Contents::singleton($index . IMP::IDX_SEP . $mailbox);
+    } catch (Horde_Exception $e) {
+        Horde::fatal($e, __FILE__, __LINE__);
     }
 }