First step on conversion to exclusively using exceptions.
/* 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);
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);
}
}
}
$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';
$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;
$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);
$result = DIMP::getFolderResponse($imptree);
}
}
+ } catch (Horde_Exception $e) {
+ $notification->push($e, 'horde.error');
+ $result = false;
}
break;
$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. */
} else {
$notification->push($res);
}
+ } catch (IMP_Compose_Exception $e) {
+ $notification->push($e, 'horde.error');
}
break;
'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;
$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';
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';
$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"):
'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;
}
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;
}
}
$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');
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':
'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;
$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;
$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');
}
}
}
$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) {}
}
}
// 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);
// }
// }
// }
// @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)
{
$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);
/* 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;
}
}
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;
* @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);
}
/**
* @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)
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);
* (UTF7-IMAP).
*
* @return string Status string.
+ * @throw IMP_Compose_Exception
*/
protected function _saveDraftServer($data, $drafts_mbox)
{
/* 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');
*/
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;
}
* </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())
/* 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']);
/* 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. */
* @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)
{
/* 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);
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);
+ }
}
/**
* @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)
{
$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) {
$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 . ', ';
}
}
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
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);
}
}
}
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.
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'] : '');
* '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())
$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();
/* 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;
* 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;
}
/* 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))) {
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;
}
}
/* 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());
}
}
{
$msgList = IMP::parseIndicesList($indices);
if (empty($msgList)) {
- return;
+ return false;
}
$attached = 0;
$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;
}
}
*
* @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)
{
$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']);
/* 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
} 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;
}
* @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)
{
$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') &&
/* 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. */
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');
+ }
}
}
}
* 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']));
}
if (is_a($res, 'PEAR_Error')) {
Horde::logMessage($res, __FILE__, __LINE__, PEAR_LOG_ERR);
- return $res;
+ return IMP_Compose_Exception($res);
}
}
$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');
}
}
}
$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;
}
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) {}
}
}
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;
+ }
+ }
+
+}
* @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)
{
*
* @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)
{
), 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.');
}
}
}
* @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. */
* @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)
*
* @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. */
} 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;
}
/**
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');
}
}
}
/**
* 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();
/**
* 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();
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());
}
}
* Gets the mail using the data in this object.
*
* @see IMP_Fetchmail::getMail()
+ * @throws Horde_Exception
*/
public function getMail()
{
$numMsgs = 0;
$stream = $this->_connect();
- if (is_a($stream, 'PEAR_Error')) {
- return $stream;
- }
/* Check to see if remote mailbox exists. */
$mbox = $this->_params['rmailbox'];
}
if (!$mbox) {
- return PEAR::raiseError(_("Invalid Remote Mailbox"));
+ throw new Horde_Exception(_("Invalid Remote Mailbox"));
}
$query = new Horde_Imap_Client_Search_Query();
return $numMsgs;
}
+
}
* @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"));
}
}
*
* @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)));
}
}
* @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)
{
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'];
* @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;
}
/**
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;
}
!$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);
}
}
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']);
* @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. */
$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);
/* 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;
}
/**
* @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())
{
$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];
* @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');
}
/**
*
* @param array $params Hash containing connection parameters.
*/
- public function __construct($params = array())
+ protected function __construct($params = array())
{
$this->_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()
{
*
* @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',
* 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()
{
/**
* 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()
{
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');
}
}
/**
* 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]);
/**
* 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);
}
}
* )
* );
*
- * 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.
*
* @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']);
* )
* );
*
- * 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
*
* @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()
{
// 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.
/**
* 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()
{
}
}
- return PEAR::raiseError(_("Unable to retrieve quota"), 'horde.error');
+ throw new Horde_Exception(_("Unable to retrieve quota"), 'horde.error');
}
/**
/**
* 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)
*/
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');
}
}
* <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>
*
/**
* Connects to the database
*
- * @return boolean True on success, PEAR_Error on failure.
+ * @throws Horde_Exception
*/
protected function _connect()
{
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;
/**
* 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);
$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);
$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);
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;
}
$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) {
/**
* $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']);
$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",
$sentmail = IMP_Sentmail::factory();
$sentmail->log('redirect', $headers->getValue('message-id'), $recipients);
}
-
- return true;
}
/**
}
/* 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;
/* 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;
}
}
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));
!$GLOBALS['prefs']->getValue('use_trash')) {
$imp_mailbox->setIndex(1, 'offset');
}
+ } catch (Horde_Exception $e) {
+ $notification->push($e);
}
}
break;
$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;
}
/* 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;
}
}
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;
}
$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;
_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;
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)) {
}
/* 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;
_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;
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)) {
}
/* 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;
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__);
}
}