break;
}
- $result = IMP::addAddress($email, $name);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, 'horde.error');
- $result = false;
- } else {
+ try {
+ IMP::addAddress($email, $name);
$result = true;
$notification->push(sprintf(_("%s was successfully added to your address book."), $name ? $name : $email), 'horde.success');
+ } catch (Horde_Exception $e) {
+ $notification->push($e, 'horde.error');
+ $result = false;
}
break;
break;
case 'resume':
- $result = $imp_compose->resumeDraft($index . IMP::IDX_SEP . $folder);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result->getMessage(), 'horde.error');
- } else {
+ try {
+ $result = $imp_compose->resumeDraft($index . IMP::IDX_SEP . $folder);
+
if ($result['mode'] == 'html') {
$show_editor = true;
}
$identity->setDefault($result['identity']);
}
$header = array_merge($header, $result['header']);
+ } catch (IMP_Compose_Exception $e) {
+ $notification->push($e->getMessage(), 'horde.error');
}
$get_sig = false;
break;
switch ($actionID) {
// 'd' = draft
case 'd':
- $result = $imp_compose->resumeDraft($index . IMP::IDX_SEP . $thismailbox);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, 'horde.error');
- } else {
+ try {
+ $result = $imp_compose->resumeDraft($index . IMP::IDX_SEP . $thismailbox);
+
$msg = $result['msg'];
$header = array_merge($header, $result['header']);
if (!is_null($result['identity']) &&
$sent_mail_folder = $identity->getValue('sent_mail_folder');
}
$resume_draft = true;
+ } catch (IMP_Compose_Exception $e) {
+ $notification->push($e, 'horde.error');
}
break;
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;
}
$imp_compose->pgpAttachPubkey((bool) Util::getFormData('pgp_attach_pubkey'));
$imp_compose->userLinkAttachments((bool) Util::getFormData('link_attachments'));
-$vcard = $imp_compose->attachVCard((bool) Util::getFormData('vcard'), $identity->getValue('fullname'));
-if (is_a($vcard, 'PEAR_Error')) {
- $notification->push($vcard);
+try {
+ $imp_compose->attachVCard((bool) Util::getFormData('vcard'), $identity->getValue('fullname'));
+} catch (IMP_Compose_Exception $e) {
+ $notification->push($e);
}
/* Init IMP_UI_Compose:: object. */
break;
case 'draft':
- $result = $imp_compose->resumeDraft($index . IMP::IDX_SEP . $thismailbox);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result->getMessage(), 'horde.error');
- } else {
+ try {
+ $result = $imp_compose->resumeDraft($index . IMP::IDX_SEP . $thismailbox);
+
if (!is_null($rtemode)) {
$rtemode = ($result['mode'] == 'html');
}
$sent_mail_folder = $identity->getValue('sent_mail_folder');
}
$resume_draft = true;
+ } catch (IMP_Compose_Exception $e) {
+ $notification->push($e, 'horde.error');
}
$get_sig = false;
break;
if (!empty($addrs['list'])) {
$imp_pgp = &Horde_Crypt::singleton(array('imp', 'pgp'));
foreach ($addrs['list'] as $val) {
- $res = $imp_pgp->getPublicKey($val);
- if (is_a($res, 'PEAR_Error')) {
- $notification->push(_("PGP encryption cannot be used by default as public keys cannot be found for all recipients."), 'horde.warning');
- $encrypt_options = ($default_encrypt == IMP::PGP_ENCRYPT) ? IMP::ENCRYPT_NONE : IMP::PGP_SIGN;
- break;
- }
+ $imp_pgp->getPublicKey($val);
}
}
- } catch (IMP_Compose_Exception $e) {}
+ } catch (IMP_Compose_Exception $e) {
+ } catch (Horde_Exception $e) {
+ $notification->push(_("PGP encryption cannot be used by default as public keys cannot be found for all recipients."), 'horde.warning');
+ $encrypt_options = ($default_encrypt == IMP::PGP_ENCRYPT) ? IMP::ENCRYPT_NONE : IMP::PGP_SIGN;
+ }
}
}
// function should be a valid page within a horde application which will be
// placed in a "Location" header to redirect the client. The only parameter
// is the name of the mailbox which the user has opened. If an empty string
-// is returned the user is not redirected.
+// is returned the user is not redirected. Throw a Horde_Exception on error.
// if (!function_exists('_imp_hook_mbox_redirect')) {
// function _imp_hook_mbox_redirect($mailbox)
v5.0-git
--------
+[mms] All native IMP code now uses exceptions instead of PEAR_Errors.
[mms] Fix wrong charset on filenames when stripping attachments (Bug #7220).
[mms] Use effects queue to prevent issues with users clicking on effects
elements too quickly.
{
/* Set up the base message now. */
$mime = $this->_createMimeMessage(array(null), $message, $charset, array('html' => $html, 'nofinal' => true, 'noattach' => !$session));
- if (is_a($mime, 'PEAR_Error')) {
- return $mime;
- }
$base = $mime['msg'];
$base->isBasePart(true);
* @param string $index The IMAP message mailbox/index. The index should
* be in IMP::parseIndicesList() format #1.
*
- * @return mixed PEAR_Error on error, or an array with the following
- * keys:
+ * @return mixed An array with the following keys:
* <pre>
* 'msg' - (string) The message text.
* 'mode' - (string) 'html' or 'text'.
* 'header' - (array) A list of headers to add to the outgoing message.
* 'identity' - (integer) The identity used to create the message.
* </pre>
+ * @throws IMP_Compose_Exception
*/
public function resumeDraft($index)
{
try {
$contents = IMP_Contents::singleton($index);
} catch (Horde_Exception $e) {
- // TODO
- return $contents;
+ throw new IMP_Compose_Exception($e);
}
$msg_text = $this->_getMessageText($contents, array('type' => 'draft'));
if ($prefs->getValue('use_smime') &&
in_array($encrypt, array(IMP::SMIME_ENCRYPT, IMP::SMIME_SIGNENC))) {
foreach ($recip['list'] as $val) {
- $res = $this->_createMimeMessage(array($val), $body, $charset, $msg_options);
- if (is_a($res, 'PEAR_Error')) {
- return $res;
- }
- $send_msgs[] = $res;
+ $send_msgs[] = $this->_createMimeMessage(array($val), $body, $charset, $msg_options);
}
/* Must target the encryption for the sender before saving message
$send_msgs[] = $save_msg = $this->_createMimeMessage($recip['list'], $body, $charset, $msg_options);
}
- if (is_a($save_msg, 'PEAR_Error')) {
- return $save_msg;
- }
-
/* Initalize a header object for the outgoing message. */
$headers = new Horde_Mime_Headers();
}
}
+ if ($conf['sentmail']['driver'] != 'none') {
+ $sentmail = IMP_Sentmail::factory();
+ }
+
/* Send the messages out now. */
foreach ($send_msgs as $val) {
try {
} catch (IMP_Compose_Exception $e) {
/* Unsuccessful send. */
Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
+ if (isset($sentmail)) {
+ $sentmail->log(empty($opts['reply_type']) ? 'new' : $opts['reply_type'], $headers->getValue('message-id'), $val['recipients'], false);
+ }
+
throw new IMP_Compose_Exception(sprintf(_("There was an error sending your message: %s"), $e->getMessage()));
}
/* Store history information. */
- if ($conf['sentmail']['driver'] != 'none') {
- $sentmail = IMP_Sentmail::factory();
- $sentmail->log(empty($opts['reply_type']) ? 'new' : $opts['reply_type'], $headers->getValue('message-id'), $val['recipients'], !is_a($res, 'PEAR_Error'));
+ if (isset($sentmail)) {
+ $sentmail->log(empty($opts['reply_type']) ? 'new' : $opts['reply_type'], $headers->getValue('message-id'), $val['recipients'], true);
}
}
$mail_driver = $this->getMailDriver();
- $res = $message->send($email, $headers, $mail_driver['driver'], $mail_driver['params']);
- if (is_a($res, 'PEAR_Error')) {
- throw new IMP_Compose_Exception($res);
+ try {
+ $message->send($email, $headers, $mail_driver['driver'], $mail_driver['params']);
+ } catch (Horde_Mime_Exception $e) {
+ throw new IMP_Compose_Exception($e);
}
}
}
/* Do the encryption/signing requested. */
- switch ($encrypt) {
- case IMP::PGP_SIGN:
- $base = $imp_pgp->IMPsignMIMEPart($base);
- break;
-
- case IMP::PGP_ENCRYPT:
- case IMP::PGP_SYM_ENCRYPT:
- $to_list = empty($options['from'])
- ? $to
- : array_keys(array_flip(array_merge($to, array($options['from']))));
- $base = $imp_pgp->IMPencryptMIMEPart($base, $to_list, ($encrypt == IMP::PGP_SYM_ENCRYPT) ? $symmetric_passphrase : null);
- break;
+ try {
+ switch ($encrypt) {
+ case IMP::PGP_SIGN:
+ $base = $imp_pgp->IMPsignMIMEPart($base);
+ break;
- case IMP::PGP_SIGNENC:
- case IMP::PGP_SYM_SIGNENC:
- $to_list = empty($options['from'])
- ? $to
- : array_keys(array_flip(array_merge($to, array($options['from']))));
- $base = $imp_pgp->IMPsignAndEncryptMIMEPart($base, $to_list, ($encrypt == IMP::PGP_SYM_SIGNENC) ? $symmetric_passphrase : null);
- break;
- }
+ case IMP::PGP_ENCRYPT:
+ case IMP::PGP_SYM_ENCRYPT:
+ $to_list = empty($options['from'])
+ ? $to
+ : array_keys(array_flip(array_merge($to, array($options['from']))));
+ $base = $imp_pgp->IMPencryptMIMEPart($base, $to_list, ($encrypt == IMP::PGP_SYM_ENCRYPT) ? $symmetric_passphrase : null);
+ break;
- /* Check for errors. */
- if (is_a($base, 'PEAR_Error')) {
- throw new IMP_Compose_Exception(_("PGP Error: ") . $base->getMessage(), $base->getCode());
+ case IMP::PGP_SIGNENC:
+ case IMP::PGP_SYM_SIGNENC:
+ $to_list = empty($options['from'])
+ ? $to
+ : array_keys(array_flip(array_merge($to, array($options['from']))));
+ $base = $imp_pgp->IMPsignAndEncryptMIMEPart($base, $to_list, ($encrypt == IMP::PGP_SYM_SIGNENC) ? $symmetric_passphrase : null);
+ break;
+ }
+ } catch (Horde_Exception $e) {
+ throw new IMP_Compose_Exception(_("PGP Error: ") . $e->getMessage(), $e->getCode());
}
} elseif ($GLOBALS['prefs']->getValue('use_smime') &&
in_array($encrypt, array(IMP::SMIME_ENCRYPT, IMP::SMIME_SIGN, IMP::SMIME_SIGNENC))) {
}
/* Do the encryption/signing requested. */
- switch ($encrypt) {
- case IMP::SMIME_SIGN:
- $base = $imp_smime->IMPsignMIMEPart($base);
- break;
-
- case IMP::SMIME_ENCRYPT:
- $base = $imp_smime->IMPencryptMIMEPart($base, $to[0]);
- break;
+ try {
+ switch ($encrypt) {
+ case IMP::SMIME_SIGN:
+ $base = $imp_smime->IMPsignMIMEPart($base);
+ break;
- case IMP::SMIME_SIGNENC:
- $base = $imp_smime->IMPsignAndEncryptMIMEPart($base, $to[0]);
- break;
- }
+ case IMP::SMIME_ENCRYPT:
+ $base = $imp_smime->IMPencryptMIMEPart($base, $to[0]);
+ break;
- /* Check for errors. */
- if (is_a($base, 'PEAR_Error')) {
- throw new IMP_Compose_Exception(_("S/MIME Error: ") . $base->getMessage(), $base->getCode());
+ case IMP::SMIME_SIGNENC:
+ $base = $imp_smime->IMPsignAndEncryptMIMEPart($base, $to[0]);
+ break;
+ }
+ } catch (Horde_Exception $e) {
+ throw new IMP_Compose_Exception(_("S/MIME Error: ") . $e->getMessage(), $e->getCode());
}
}
/**
* Adds attachments from the IMP_Contents object to the message.
*
- * @param IMP_Contents &$contents An IMP_Contents object.
- * @param array $options Additional options:
+ * @param IMP_Contents $contents An IMP_Contents object.
+ * @param array $options Additional options:
* <pre>
* 'notify' - (boolean) Add notification message on errors?
* 'skip' - (array) Skip these MIME IDs.
* </pre>
- *
- * @return array An array of PEAR_Error object on error.
- * An empty array if successful.
*/
- public function attachFilesFromMessage(&$contents, $options = array())
+ public function attachFilesFromMessage($contents, $options = array())
{
$mime_message = $contents->getMIMEMessage();
$dl_list = array_slice(array_keys($mime_message->contentTypeMap()), 1);
* @param boolean $attach True if vCard should be attached.
* @param string $name The user's name.
*
- * @return mixed True on success, PEAR_Error on error.
+ * @throws IMP_Compose_Exception
*/
public function attachVCard($attach, $name)
{
$vcard = $GLOBALS['registry']->call('contacts/ownVCard');
if (is_a($vcard, 'PEAR_Error')) {
- return $vcard;
+ throw new IMP_Compose_Exception($vcard);
}
$part = new Horde_Mime_Part();
$part->setContents($vcard);
$part->setName((strlen($name) ? $name : 'vcard') . '.vcf');
$this->_attachVCard = $part;
-
- return true;
}
/**
/**
* Constructor
*/
- function __construct()
+ public function __construct()
{
parent::__construct(array(
'program' => $GLOBALS['conf']['utils']['gnupg'],
* @param string $comment See Horde_Crypt_pgp::
* @param string $keylength See Horde_Crypt_pgp::
*
- * @return PEAR_Error Returns PEAR_Error object on error.
+ * @throws Horde_Exception
*/
public function generatePersonalKeys($name, $email, $passphrase,
$comment = '', $keylength = 1024)
{
$keys = $this->generateKey($name, $email, $passphrase, $comment, $keylength);
if (is_a($keys, 'PEAR_Error')) {
- return $keys;
+ throw new Horde_Exception($keys);
}
/* Store the keys in the user's preferences. */
/* Check to make sure the key does not already exist in ANY
* address book and remove the id from the key_info for a correct
* output. */
- $result = $this->getPublicKey($sig['email'], null, false);
- if (!is_a($result, 'PEAR_Error') && !empty($result)) {
- unset($key_info['signature'][$id]);
- continue;
- }
+ try {
+ $result = $this->getPublicKey($sig['email'], null, false);
+ if (!empty($result)) {
+ unset($key_info['signature'][$id]);
+ continue;
+ }
+ } catch (Horde_Exception $e) {}
/* Add key to the user's address book. */
$result = $GLOBALS['registry']->call('contacts/addField', array($sig['email'], $sig['name'], self::PUBKEY_FIELD, $public_key, $GLOBALS['prefs']->getValue('add_source')));
if (is_a($result, 'PEAR_Error')) {
- return $result;
+ throw new Horde_Exception($result);
}
}
* @param boolean $server Whether to check the publick key servers for
* the key.
*
- * @return string The PGP public key requested. Returns PEAR_Error object
- * on error.
+ * @return string The PGP public key requested.
+ * @throws Horde_Exception
*/
public function getPublicKey($address, $fingerprint = null, $server = true)
{
/* Try retrieving via a PGP public keyserver. */
if ($server && is_a($result, 'PEAR_Error')) {
- $result = $this->getFromPublicKeyserver($fingerprint, $address);
+ $this->getFromPublicKeyserver($fingerprint, $address);
}
/* Return now, if no public key found at all. */
if (is_a($result, 'PEAR_Error')) {
- return $result;
+ throw new Horde_Exception($result);
}
/* If more than one public key is returned, just return the first in
/**
* Retrieves all public keys from a user's address book(s).
*
- * @return array All PGP public keys available. Returns PEAR_Error object
- * on error.
+ * @return array All PGP public keys available.
+ * @throws Horde_Exception
*/
public function listPublicKeys()
{
$params = IMP_Compose::getAddressSearchParams();
- return (empty($params['sources'])) ? array() : $GLOBALS['registry']->call('contacts/getAllAttributeValues', array(self::PUBKEY_FIELD, $params['sources']));
+ if (empty($params['sources'])) {
+ return array();
+ }
+
+ $res = $GLOBALS['registry']->call('contacts/getAllAttributeValues', array(self::PUBKEY_FIELD, $params['sources']));
+ if (is_a($res, 'PEAR_Error')) {
+ throw new Horde_Exception($res);
+ }
+
+ return $res;
}
/**
*
* @param string $email The e-mail address to delete.
*
- * @return PEAR_Error Returns PEAR_Error object on error.
+ * @throws Horde_Exception
*/
public function deletePublicKey($email)
{
$params = IMP_Compose::getAddressSearchParams();
- return $GLOBALS['registry']->call('contacts/deleteField', array($email, self::PUBKEY_FIELD, $params['sources']));
+ $res = $GLOBALS['registry']->call('contacts/deleteField', array($email, self::PUBKEY_FIELD, $params['sources']));
+ if (is_a($res, 'PEAR_Error')) {
+ throw new Horde_Exception($res);
+ }
+
+ return $res;
}
/**
* @param string $address The email address of the requested key.
*
* @return string See Horde_Crypt_pgp::getPublicKeyserver()
+ * @throws Horde_Exception
*/
public function getFromPublicKeyserver($fingerprint, $address = null)
{
* @param string $pubkey The PGP public key.
*
* @return string See Horde_Crypt_pgp::putPublicKeyserver()
+ * @throws Horde_Exception
*/
public function sendToPublicKeyserver($pubkey)
{
*
* @return string See Horde_Crypt_pgp::getPublicKeyserver() -or-
* Horde_Crypt_pgp::putPublicKeyserver().
+ * @throws Horde_Exception
*/
protected function _keyserverConnect($data, $method, $additional = null)
{
foreach ($conf['utils']['gnupg_keyserver'] as $server) {
$result = $this->getPublicKeyserver($data, $server, $timeout, $additional);
if (!is_a($result, 'PEAR_Error')) {
- return $result;
+ throw new Horde_Exception($result);
}
}
return $result;
} else {
return $this->putPublicKeyserver($data, $conf['utils']['gnupg_keyserver'][0], $timeout);
}
- } else {
- return PEAR::raiseError(_("Public PGP keyserver support has been disabled."), 'horde.warning');
}
+
+ throw new Horde_Exception(_("Public PGP keyserver support has been disabled."), 'horde.warning');
}
/**
*
* @return string See Horde_Crypt_pgp::decryptSignature() -or-
* Horde_Crypt_pgp::decryptDetachedSignature().
+ * @throws Horde_Exception
*/
public function verifySignature($text, $address, $signature = '')
{
}
$public_key = $this->getPublicKey($address, $fingerprint);
- if (is_a($public_key, 'PEAR_Error')) {
- return $public_key;
- }
if (empty($signature)) {
$options = array('type' => 'signature');
$options['pubkey'] = $public_key;
/* decrypt() returns a PEAR_Error object on error. */
- return $this->decrypt($text, $options);
+ $res = $this->decrypt($text, $options);
+ if (is_a($res, 'PEAR_Error')) {
+ throw new Horde_Exception($res);
+ }
+
+ return $res;
}
/**
* @param boolean $passphrase If $type is 'personal' or 'symmetrical',
* the passphrase to use.
*
- * @return string The decrypted message. Returns PEAR_Error object on
- * error.
+ * @return string The decrypted message.
+ * @throws Horde_Exception
*/
public function decryptMessage($text, $type, $passphrase = null)
{
- /* decrypt() returns a PEAR_Error object on error. */
switch ($type) {
case 'literal':
- return $this->decrypt($text, array('type' => 'message', 'no_passphrase' => true));
+ $res = $this->decrypt($text, array('type' => 'message', 'no_passphrase' => true));
+ break;
case 'symmetric':
- return $this->decrypt($text, array('type' => 'message', 'passphrase' => $passphrase));
+ $res = $this->decrypt($text, array('type' => 'message', 'passphrase' => $passphrase));
+ break;
case 'personal':
- return $this->decrypt($text, array('type' => 'message', 'pubkey' => $this->getPersonalPublicKey(), 'privkey' => $this->getPersonalPrivateKey(), 'passphrase' => $passphrase));
+ $res = $this->decrypt($text, array('type' => 'message', 'pubkey' => $this->getPersonalPublicKey(), 'privkey' => $this->getPersonalPrivateKey(), 'passphrase' => $passphrase));
+ break;
+ }
+
+ if (is_a($res, 'PEAR_Error')) {
+ throw new Horde_Exception($res);
}
+
+ return $res;
}
/**
* encrypting. If null, uses the personal key.
*
* @return array The list of parameters needed by encrypt().
- * Returns PEAR_Error on error.
+ * @throws Horde_Exception
*/
protected function _encryptParameters($addresses, $symmetric)
{
$key_addr = array_pop($addrOb);
/* Get the public key for the address. */
- $public_key = $this->getPublicKey($key_addr);
- if (is_a($public_key, 'PEAR_Error')) {
- return $public_key;
- }
- $addr_list[$key_addr] = $public_key;
+ $addr_list[$key_addr] = $this->getPublicKey($key_addr);
}
return array('recips' => $addr_list);
*
* @param Horde_Mime_Part $mime_part The object to sign.
*
- * @return Horde_Mime_Part See Horde_Crypt_pgp::signMIMEPart(). Returns
- * PEAR_Error object on error.
+ * @return Horde_Mime_Part See Horde_Crypt_pgp::signMIMEPart().
+ * @throws Horde_Exception
*/
public function IMPsignMIMEPart($mime_part)
{
- return $this->signMIMEPart($mime_part, $this->_signParameters());
+ $res = $this->signMIMEPart($mime_part, $this->_signParameters());
+ if (is_a($res, 'PEAR_Error')) {
+ throw new Horde_Exception($res);
+ }
+ return $res;
}
/**
* use for encrypting. If null, uses
* the personal key.
*
- * @return Horde_Mime_Part See Horde_Crypt_pgp::encryptMIMEPart(). Returns
- * PEAR_Error object on error.
+ * @return Horde_Mime_Part See Horde_Crypt_pgp::encryptMIMEPart().
+ * @throws Horde_Exception
*/
public function IMPencryptMIMEPart($mime_part, $addresses,
$symmetric = null)
{
- $params = $this->_encryptParameters($addresses, $symmetric);
- if (is_a($params, 'PEAR_Error')) {
- return $params;
+ $res = $this->encryptMIMEPart($mime_part, $this->_encryptParameters($addresses, $symmetric));
+ if (is_a($res, 'PEAR_Error')) {
+ throw new Horde_Exception($res);
}
- return $this->encryptMIMEPart($mime_part, $params);
+ return $res;
}
/**
* the personal key.
*
* @return Horde_Mime_Part See Horde_Crypt_pgp::signAndencryptMIMEPart().
- * Returns PEAR_Error object on error.
+ * @throws Horde_Exception
*/
public function IMPsignAndEncryptMIMEPart($mime_part, $addresses,
$symmetric = null)
{
- $encrypt_params = $this->_encryptParameters($addresses, $symmetric);
- if (is_a($encrypt_params, 'PEAR_Error')) {
- return $encrypt_params;
+ $res = $this->signAndEncryptMIMEPart($mime_part, $this->_signParameters(), $this->_encryptParameters($addresses, $symmetric));
+ if (is_a($res, 'PEAR_Error')) {
+ throw new Horde_Exception($res);
}
- return $this->signAndEncryptMIMEPart($mime_part, $this->_signParameters(), $encrypt_params);
+ return $res;
}
/**
/**
* Constructor.
*/
- function __construct()
+ public function __construct()
{
parent::__construct(array('temp' => Horde::getTempDir()));
}
* @param string $address The e-mail address of the recipient.
*
* @return array The list of parameters needed by encrypt().
- * Returns PEAR_Error object on error.
+ * @throws Horde_Exception
*/
protected function _encryptParameters($address)
{
$key_addr = array_pop($addrOb);
$public_key = $this->getPublicKey($key_addr);
- if (is_a($public_key, 'PEAR_Error')) {
- return $public_key;
- }
return array(
'pubkey' => $public_key,
* @param string $address The e-mail address to search for.
*
* @return string The S/MIME public key requested.
- * Returns PEAR_Error object on error.
+ * @throws Horde_Exception
*/
public function getPublicKey($address)
{
if (!empty($personal_pubkey) && $identity->hasAddress($address)) {
return $personal_pubkey;
}
+ throw new Horde_Exception($key);
}
/* If more than one public key is returned, just return the first in
* Retrieves all public keys from a user's address book(s).
*
* @return array All PGP public keys available.
- * Returns PEAR_Error object on error.
+ * @throws Horde_Exception
*/
public function listPublicKeys()
{
$params = IMP_Compose::getAddressSearchParams();
- return (empty($params['sources']))
- ? array()
- : $GLOBALS['registry']->call('contacts/getAllAttributeValues', array(self::PUBKEY_FIELD, $params['sources']));
+ if (empty($params['sources'])) {
+ return array();
+ }
+ $res = $GLOBALS['registry']->call('contacts/getAllAttributeValues', array(self::PUBKEY_FIELD, $params['sources']));
+ if (is_a($res, 'PEAR_Error')) {
+ throw new Horde_Exception($res);
+ }
+
+ return $res;
}
/**
*
* @param string $email The e-mail address to delete.
*
- * @return PEAR_Error Returns PEAR_Error object on error.
+ * @throws Horde_Exception
*/
public function deletePublicKey($email)
{
$params = IMP_Compose::getAddressSearchParams();
- return $GLOBALS['registry']->call('contacts/deleteField', array($email, self::PUBKEY_FIELD, $params['sources']));
+ $res = $GLOBALS['registry']->call('contacts/deleteField', array($email, self::PUBKEY_FIELD, $params['sources']));
+ if (is_a($res, 'PEAR_Error')) {
+ throw new Horde_Exception($res);
+ }
}
/**
* @param string $text The text to decrypt.
*
* @return string See Horde_Crypt_smime::decrypt().
- * Returns PEAR_Error object on error.
+ * @throws Horde_Exception
*/
public function decryptMessage($text)
{
/* decrypt() returns a PEAR_Error object on error. */
- return $this->decrypt($text, array('type' => 'message', 'pubkey' => $this->getPersonalPublicKey(), 'privkey' => $this->getPersonalPrivateKey(), 'passphrase' => $this->getPassphrase()));
+ $res = $this->decrypt($text, array('type' => 'message', 'pubkey' => $this->getPersonalPublicKey(), 'privkey' => $this->getPersonalPrivateKey(), 'passphrase' => $this->getPassphrase()));
+ if (is_a($res, 'PEAR_Error')) {
+ throw new Horde_Exception($res);
+ }
+
+ return $res;
}
/**
* @param mixed $to_address The e-mail address of the key to use for
* encryption.
*
- * @return MIME_Part See Horde_Crypt_smime::encryptMIMEPart(). Returns
- * PEAR_Error on error.
+ * @return MIME_Part See Horde_Crypt_smime::encryptMIMEPart().
+ * @throws Horde_Exception
*/
public function IMPencryptMIMEPart($mime_part, $to_address)
{
- $params = $this->_encryptParameters($to_address);
- return is_a($params, 'PEAR_Error')
- ? $params
- : $this->encryptMIMEPart($mime_part, $params);
+ $res = $this->encryptMIMEPart($mime_part, $this->_encryptParameters($to_address));
+ if (is_a($res, 'PEAR_Error')) {
+ throw new Horde_Exception($res);
+ }
+
+ return $res;
}
/**
*
* @param MIME_Part $mime_part The MIME_Part object to sign.
*
- * @return MIME_Part See Horde_Crypt_smime::signMIMEPart(). Returns
- * PEAR_Error on error.
+ * @return MIME_Part See Horde_Crypt_smime::signMIMEPart().
+ * @throws Horde_Exception
*/
public function IMPsignMIMEPart($mime_part)
{
- return $this->signMIMEPart($mime_part, $this->_signParameters());
+ $res = $this->signMIMEPart($mime_part, $this->_signParameters());
+ if (is_a($res, 'PEAR_Error')) {
+ throw new Horde_Exception($res);
+ }
+
+ return $res;
}
/**
* encryption.
*
* @return MIME_Part See Horde_Crypt_smime::signAndencryptMIMEPart().
- * Returns PEAR_Error on error.
+ * @throws Horde_Exception
*/
public function IMPsignAndEncryptMIMEPart($mime_part, $to_address)
{
- $encrypt_params = $this->_encryptParameters($to_address);
- if (is_a($encrypt_params, 'PEAR_Error')) {
- return $encrypt_params;
+ $res = $this->signAndEncryptMIMEPart($mime_part, $this->_signParameters(), $this->_encryptParameters($to_address));
+ if (is_a($res, 'PEAR_Error')) {
+ throw new Horde_Exception($res);
}
- return $this->signAndEncryptMIMEPart($mime_part, $this->_signParameters(), $encrypt_params);
+
+ return $res;
}
/**
* @param string $password The password of the PKCS 12 file.
* @param string $pkpass The password to use to encrypt the private key.
*
- * @return boolean True on success, PEAR_Error on error.
+ * @throws Horde_Exception
*/
public function addFromPKCS12($pkcs12, $password, $pkpass = null)
{
$openssl = $this->checkForOpenSSL();
if (is_a($openssl, 'PEAR_Error')) {
- return $openssl;
+ throw new Horde_Exception($openssl);
}
$sslpath = (empty($GLOBALS['conf']['utils']['openssl_binary'])) ? null : $GLOBALS['conf']['utils']['openssl_binary'];
}
$res = $this->parsePKCS12Data($pkcs12, $params);
if (is_a($res, 'PEAR_Error')) {
- return $res;
+ throw new Horde_Exception($res);
}
$this->addPersonalPrivateKey($res->private);
$this->addPersonalPublicKey($res->public);
$this->addAdditionalCert($res->certs);
-
- return true;
}
/**
* @param string $data The signed S/MIME data.
*
* @return string The contents embedded in the signed data.
- * Returns PEAR_Error on error.
+ * @throws Horde_Exception
*/
public function extractSignedContents($data)
{
- $sslpath = (empty($GLOBALS['conf']['utils']['openssl_binary'])) ? null : $GLOBALS['conf']['utils']['openssl_binary'];
- return parent::extractSignedContents($data, $sslpath);
+ $sslpath = empty($GLOBALS['conf']['utils']['openssl_binary'])
+ ? null
+ : $GLOBALS['conf']['utils']['openssl_binary'];
+
+ $res = parent::extractSignedContents($data, $sslpath);
+ if (is_a($res, 'PEAR_Error')) {
+ throw new Horde_Exception($res);
+ }
+
+ return $res;
}
}
* @param string $newName The contact's name.
*
* @return string A link or message to show in the notification area.
+ * @throws Horde_Exception
*/
static public function addAddress($newAddress, $newName)
{
array(array('name' => $newName, 'email' => $newAddress),
'array', $prefs->getValue('add_source')));
if (is_a($result, 'PEAR_Error')) {
- return $result;
+ throw new Horde_Exception($result);
}
$contact_link = $registry->link('contacts/show', array('uid' => $result, 'source' => $prefs->getValue('add_source')));
- if (!empty($contact_link) && !is_a($contact_link, 'PEAR_Error')) {
- $contact_link = Horde::link(Horde::url($contact_link), sprintf(_("Go to address book entry of \"%s\""), $newName)) . @htmlspecialchars($newName, ENT_COMPAT, NLS::getCharset()) . '</a>';
- } else {
- $contact_link = @htmlspecialchars($newName, ENT_COMPAT, NLS::getCharset());
- }
- return $contact_link;
+ $old_error = error_reporting(0);
+ $escapeName = htmlspecialchars($newName, ENT_COMPAT, NLS::getCharset());
+ error_reporting($old_error);
+
+ return (!empty($contact_link) && !is_a($contact_link, 'PEAR_Error'))
+ ? Horde::link(Horde::url($contact_link), sprintf(_("Go to address book entry of \"%s\""), $newName)) . $escapeName . '</a>'
+ : $escapeName;
}
/**
*
* @return boolean Whether any old attachments were deleted.
*/
- function doMaintenance()
+ public function doMaintenance()
{
/* Find the UNIX timestamp of the last second that we will not
* purge. */
* @return string Description of what the operation is going to do during
* this login.
*/
- function describeMaintenance()
+ public function describeMaintenance()
{
return sprintf(_("All old linked attachments more than %s months old will be deleted."), $GLOBALS['prefs']->getValue('delete_attachments_monthly_keep'));
}
// Send the reply.
$mail_driver = IMP_Compose::getMailDriver();
- $status = $mime->send($organizerEmail, $msg_headers,
- $mail_driver['driver'],
- $mail_driver['params']);
- if (is_a($status, 'PEAR_Error')) {
- $msgs[] = array('error', sprintf(_("Error sending reply: %s."), $status->getMessage()));
- } else {
+ try {
+ $mime->send($organizerEmail, $msg_headers,
+ $mail_driver['driver'],
+ $mail_driver['params']);
$msgs[] = array('success', _("Reply Sent."));
+ } catch (Horde_Mime_Exception $e) {
+ $msgs[] = array('error', sprintf(_("Error sending reply: %s."), $e->getMessage()));
}
} else {
$msgs[] = array('warning', _("This action is not supported."));
// Send the reply.
$mail_driver = IMP_Compose::getMailDriver();
- $status = $mime->send($organizerEmail, $msg_headers,
- $mail_driver['driver'],
- $mail_driver['params']);
- if (is_a($status, 'PEAR_Error')) {
- $msgs[] = array('error', sprintf(_("Error sending reply: %s."), $status->getMessage()));
- } else {
+ try {
+ $mime->send($organizerEmail, $msg_headers,
+ $mail_driver['driver'],
+ $mail_driver['params']);
$msgs[] = array('success', _("Reply Sent."));
+ } catch (Horde_Mime_Exception $e) {
+ $msgs[] = array('error', sprintf(_("Error sending reply: %s."), $e->getMessage()));
}
} else {
$msgs[] = array('warning', _("Invalid Action selected for this component."));
}
}
- if (!is_null($symmetric_pass)) {
- $decrypted_data = $this->_imppgp->decryptMessage($encrypted_data, 'symmetric', $symmetric_pass);
- } elseif (!is_null($personal_pass)) {
- $decrypted_data = $this->_imppgp->decryptMessage($encrypted_data, 'personal', $personal_pass);
- } else {
- $decrypted_data = $this->_imppgp->decryptMessage($encrypted_data, 'literal');
- }
-
- if (is_a($decrypted_data, 'PEAR_Error')) {
- $status[] = _("The message below does not appear to be a valid PGP encrypted message. Error: ") . $decrypted_data->getMessage();
+ try {
+ if (!is_null($symmetric_pass)) {
+ $decrypted_data = $this->_imppgp->decryptMessage($encrypted_data, 'symmetric', $symmetric_pass);
+ } elseif (!is_null($personal_pass)) {
+ $decrypted_data = $this->_imppgp->decryptMessage($encrypted_data, 'personal', $personal_pass);
+ } else {
+ $decrypted_data = $this->_imppgp->decryptMessage($encrypted_data, 'literal');
+ }
+ } catch (Horde_Exception $e) {
+ $status[] = _("The message below does not appear to be a valid PGP encrypted message. Error: ") . $e->getMessage();
if (!is_null($symmetric_pass)) {
$this->_imppgp->unsetPassphrase('symmetric', $this->_getSymmetricID());
return $this->_getEmbeddedMimeParts();
/* Check for the 'x-imp-pgp-signature' param. This is set by the
* plain driver when parsing PGP armor text. */
- if ($sig_part->getContentTypeParameter('x-imp-pgp-signature')) {
- $sig_result = $this->_imppgp->verifySignature($signed_data, $this->_address);
- } else {
- $sig_result = $this->_imppgp->verifySignature($signed_data, $this->_address, $sig_part->getContents());
- }
-
$graphicsdir = $GLOBALS['registry']->getImageDir('horde');
+ try {
+ $sig_result = $sig_part->getContentTypeParameter('x-imp-pgp-signature')
+ ? $this->_imppgp->verifySignature($signed_data, $this->_address)
+ : $this->_imppgp->verifySignature($signed_data, $this->_address, $sig_part->getContents());
+ }
- if (is_a($sig_result, 'PEAR_Error')) {
- $icon = Horde::img('alerts/error.png', _("Error"), null, $graphicsdir);
- $sig_result = $sig_result->getMessage();
- } else {
$icon = Horde::img('alerts/success.png', _("Success"), null, $graphicsdir);
if (empty($sig_result)) {
$sig_result = _("The message below has been verified.");
}
+ } catch (Horde_Exception $e) {
+ $icon = Horde::img('alerts/error.png', _("Error"), null, $graphicsdir);
+ $sig_result = $e->getMessage();
}
require_once 'Horde/Text/Filter.php';
}
$raw_text = $GLOBALS['imp_imap']->utils->removeBareNewlines($this->_params['contents']->getBodyPart($this->_mimepart->getMimeId(), array('mimeheaders' => true)));
- $decrypted_data = $this->_impsmime->decryptMessage($raw_text);
- if (is_a($decrypted_data, 'PEAR_Error')) {
- $status[] = $decrypted_data->getMessage();
+
+ try {
+ $decrypted_data = $this->_impsmime->decryptMessage($raw_text);
+ } catch (Horde_Exception $e) {
+ $status[] = $e->getMessage();
return null;
}
$subpart = $this->_params['contents']->getMIMEPart($sig_id);
if (!isset($subpart)) {
- $msg_data = $this->_impsmime->extractSignedContents($raw_text);
- if (is_a($msg_data, 'PEAR_Error')) {
- $this->_status[] = $msg_data->getMessage();
- $subpart = $this->_mimepart;
- } else {
+ try {
+ $msg_data = $this->_impsmime->extractSignedContents($raw_text);
$subpart = Horde_Mime_Part::parseMessage($msg_data);
+ } catch (Horde_Exception $e) {
+ $this->_status[] = $e->getMessage();
+ $subpart = $this->_mimepart;
}
}
class IMP_Sentmail
{
/**
+ * Hash containing configuration parameters.
+ *
+ * @var array
+ */
+ protected $_params = array();
+
+ /**
* Attempts to return a concrete IMP_Sentmail instance based on $driver.
*
* @param string $driver The type of the concrete IMP_Sentmail subclass
$driver = basename($driver);
$class = 'IMP_Sentmail_' . $driver;
- if (!class_exists($class)) {
- @include dirname(__FILE__) . '/Sentmail/' . $driver . '.php';
- }
if (class_exists($class)) {
- $sentmail = new $class($params);
- $result = $sentmail->initialize();
- if (!is_a($result, 'PEAR_Error')) {
- return $sentmail;
- }
+ try {
+ return new $class($params);
+ } catch (Horde_Exception $e) {}
}
- return new IMP_Sentmail();
+ return new IMP_Sentmail($params);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @throws Horde_Exception
+ */
+ public function __construct($params = array())
+ {
+ $this->_params = $params;
}
/**
* A value of null returns all message types.
*
* @return array A list with the $limit most favourite recipients.
+ * @throws Horde_Exception
*/
public function favouriteRecipients($limit,
$filter = array('new', 'forward', 'reply', 'redirect'))
* user?
*
* @return integer The number of recipients in the given time period.
+ * @throws Horde_Exception
*/
public function numberOfRecipients($hours, $user = false)
{
*
* @param integer $before Unix timestamp before that all log entries
* should be deleted.
+ * @throws Horde_Exception
*/
protected function _deleteOldEntries($before)
{
class IMP_Sentmail_sql extends IMP_Sentmail
{
/**
- * Hash containing connection parameters.
- *
- * @var array
- */
- protected $_params = array();
-
- /**
* Handle for the current database connection.
*
* @var DB
* Constructor.
*
* @param array $params A hash containing connection parameters.
+ *
+ * @throws Horde_Exception
*/
function __construct($params = array())
{
- $this->_params = $params;
+ parent::__construct($params);
+
+ Horde::assertDriverConfig($this->_params, 'storage', array('phptype', 'table'));
+
+ if (!isset($this->_params['database'])) {
+ $this->_params['database'] = '';
+ }
+ if (!isset($this->_params['username'])) {
+ $this->_params['username'] = '';
+ }
+ if (!isset($this->_params['hostspec'])) {
+ $this->_params['hostspec'] = '';
+ }
+
+ /* Connect to the SQL server using the supplied parameters. */
+ require_once 'DB.php';
+ $this->_db = DB::connect($this->_params,
+ array('persistent' => !empty($this->_params['persistent']),
+ 'ssl' => !empty($this->_params['ssl'])));
+ if (is_a($this->_db, 'PEAR_Error')) {
+ throw new Horde_Exception($this->_db);
+ }
+
+ /* Set DB portability options. */
+ switch ($this->_db->phptype) {
+ case 'mssql':
+ $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
+ break;
+
+ default:
+ $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+ }
}
/**
* A value of null returns all message types.
*
* @return array A list with the $limit most favourite recipients.
+ * @throws Horde_Exception
*/
public function favouriteRecipients($limit,
$filter = array('new', 'forward', 'reply', 'redirect'))
$recipients = $this->_db->getAll($query);
if (is_a($recipients, 'PEAR_Error')) {
Horde::logMessage($recipients, __FILE__, __LINE__, PEAR_LOG_ERR);
- return $recipients;
+ throw new Horde_Exception($recipients);
}
/* Extract email addresses. */
* user?
*
* @return integer The number of recipients in the given time period.
+ * @throws Horde_Exception
*/
public function numberOfRecipients($hours, $user = false)
{
$recipients = $this->_db->getOne($query, array(time() - $hours * 3600));
if (is_a($recipients, 'PEAR_Error')) {
Horde::logMessage($recipients, __FILE__, __LINE__, PEAR_LOG_ERR);
+ throw new Horde_Exception($recipients);
}
return $recipients;
*
* @param integer $before Unix timestamp before that all log entries
* should be deleted.
+ *
+ * @throw Horde_Exception
*/
protected function _deleteOldEntries($before)
{
$result = $this->_db->query($query, array($before));
if (is_a($result, 'PEAR_Error')) {
Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
- return $result;
+ throw new Horde_Exception($result);
}
}
- /**
- * Attempts to open a connection to the SQL server.
- *
- * @return boolean True on success, PEAR_Error on failure.
- */
- public function initialize()
- {
- Horde::assertDriverConfig($this->_params, 'storage',
- array('phptype', 'table'));
-
- if (!isset($this->_params['database'])) {
- $this->_params['database'] = '';
- }
- if (!isset($this->_params['username'])) {
- $this->_params['username'] = '';
- }
- if (!isset($this->_params['hostspec'])) {
- $this->_params['hostspec'] = '';
- }
-
- /* Connect to the SQL server using the supplied parameters. */
- require_once 'DB.php';
- $this->_db = DB::connect($this->_params,
- array('persistent' => !empty($this->_params['persistent']),
- 'ssl' => !empty($this->_params['ssl'])));
- if (is_a($this->_db, 'PEAR_Error')) {
- return $this->_db;
- }
-
- /* Set DB portability options. */
- switch ($this->_db->phptype) {
- case 'mssql':
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
- break;
- default:
- $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
- }
-
- return true;
- }
-
}
/* Run the username through virtualhost expansion functions if
* necessary. */
if (!empty($conf['hooks']['vinfo'])) {
- $hook_user = Horde::callHook('_imp_hook_vinfo', array('username', $imapuser), 'imp');
- if (!is_a($hook_user, 'PEAR_Error')) {
- $imapuser = $hook_user;
+ try {
+ $imapuser = Horde::callHook('_imp_hook_vinfo', array('username', $imapuser), 'imp');
+ } catch (Horde_Exception $e) {
+ Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
}
}
} else {
/* Send out the MDN now. */
$mail_driver = IMP_Compose::getMailDriver();
+
try {
$mdn->generate(false, $confirmed, 'displayed', $mail_driver['driver'], $mail_driver['params']);
IMP_Maillog::log('mdn', $msg_id, 'displayed');
- } catch (Horde_Mime_Exception $e) {}
+ $success = true;
+ } catch (Horde_Mime_Exception $e) {
+ $success = false;
+ }
+
if ($GLOBALS['conf']['sentmail']['driver'] != 'none') {
$sentmail = IMP_Sentmail::factory();
- $sentmail->log('mdn', '', $return_addr, !is_a($result, 'PEAR_Error'));
+ $sentmail->log('mdn', '', $return_addr, $success);
}
}
}
/* Call the mailbox redirection hook, if requested. */
if (!empty($conf['hooks']['mbox_redirect'])) {
- $redirect = Horde::callHook('_imp_hook_mbox_redirect',
- array($imp_mbox['mailbox']),
- 'imp');
- if (!empty($redirect) && !is_a($redirect, 'PEAR_Error')) {
- $redirect = Horde::applicationUrl($redirect, true);
- header('Location: ' . $redirect);
- exit;
+ try {
+ $redirect = Horde::callHook('_imp_hook_mbox_redirect', array($imp_mbox['mailbox']), 'imp');
+ if (!empty($redirect)) {
+ $redirect = Horde::applicationUrl($redirect, true);
+ header('Location: ' . $redirect);
+ exit;
+ }
+ } catch (Horde_Exception $e) {
+ Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
}
}
break;
case 'add_address':
- $contact_link = IMP::addAddress(Util::getFormData('address'), Util::getFormData('name'));
- if (is_a($contact_link, 'PEAR_Error')) {
- $notification->push($contact_link);
- } else {
+ try {
+ $contact_link = IMP::addAddress(Util::getFormData('address'), Util::getFormData('name'));
$notification->push(sprintf(_("Entry \"%s\" was successfully added to the address book"), $contact_link), 'horde.success', array('content.raw'));
+ } catch (Horde_Exception $e) {
+ $notification->push($e, 'horde.error');
}
break;
} elseif ($passphrase1 !== $passphrase2) {
$notification->push(_("Passphrases do not match"), 'horde.error');
} else {
- $result = $imp_pgp->generatePersonalKeys($realname, $email, $passphrase1, $comment, $keylength);
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, $result->getCode());
- } else {
+ try {
+ $imp_pgp->generatePersonalKeys($realname, $email, $passphrase1, $comment, $keylength);
$notification->push(_("Personal PGP keypair generated successfully."), 'horde.success');
+ } catch (Horde_Exception $e) {
+ $notification->push($e);
}
}
break;
exit;
case 'view_public_key':
- $key = $imp_pgp->getPublicKey(Util::getFormData('email'), null, false);
- if (is_a($key, 'PEAR_Error')) {
- $key = $key->getMessage();
+case 'info_public_key':
+ try {
+ $key = $imp_pgp->getPublicKey(Util::getFormData('email'), null, false);
+ } catch (Horde_Exception $e) {
+ $key = $e->getMessage();
+ }
+ if ($actionID == 'view_public_key') {
+ _textWindowOutput('PGP Public Key', $key);
+ } else {
+ _printKeyInfo($key);
}
- _textWindowOutput('PGP Public Key', $key);
exit;
case 'view_personal_public_key':
_textWindowOutput('PGP Personal Public Key', $imp_pgp->getPersonalPublicKey());
exit;
-case 'info_public_key':
- $key = $imp_pgp->getPublicKey(Util::getFormData('email'), null, false);
- if (is_a($key, 'PEAR_Error')) {
- $key = $key->getMessage();
- }
- _printKeyInfo($key);
- exit;
-
case 'info_personal_public_key':
_printKeyInfo($imp_pgp->getPersonalPublicKey());
exit;
exit;
case 'delete_public_key':
- $result = $imp_pgp->deletePublicKey(Util::getFormData('email'));
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, $result->getCode());
- } else {
+ try {
+ $imp_pgp->deletePublicKey(Util::getFormData('email'));
$notification->push(sprintf(_("PGP Public Key for \"%s\" was successfully deleted."), Util::getFormData('email')), 'horde.success');
+ } catch (Horde_Exception $e) {
+ $notification->push($e);
}
break;
break;
case 'send_public_key':
- $result = $imp_pgp->sendToPublicKeyserver($imp_pgp->getPersonalPublicKey());
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, $result->getCode());
- } else {
+ try {
+ $imp_pgp->sendToPublicKeyserver($imp_pgp->getPersonalPublicKey());
$notification->push(_("Key successfully sent to the public keyserver."), 'horde.success');
+ } catch (Horde_Exception $e) {
+ $notification->push($e);
}
break;
}
$selfURL = Horde::applicationUrl('pgp.php');
/* Get list of Public Keys on keyring. */
-$pubkey_list = $imp_pgp->listPublicKeys();
-if (is_a($pubkey_list, 'PEAR_Error')) {
- $notification->push($pubkey_list, $pubkey_list->getCode());
+try {
+ $pubkey_list = $imp_pgp->listPublicKeys();
+} catch (Horde_Exception $e) {
+ $pubkey_list = array();
+ $notification->push($e);
}
$result = Horde::loadConfiguration('prefs.php', array('prefGroups', '_prefs'), 'imp');
$t->set('empty_pubkey_list', empty($pubkey_list));
if (!$t->get('empty_pubkey_list')) {
- $t->set('pubkey_error', is_a($pubkey_list, 'PEAR_Error') ? $pubkey_list->getMessage() : false);
- if (!$t->get('pubkey_error')) {
- $plist = array();
- foreach ($pubkey_list as $val) {
- $linkurl = Util::addParameter($selfURL, 'email', $val['email']);
- $plist[] = array(
- 'name' => $val['name'],
- 'email' => $val['email'],
- 'view' => Horde::link(Util::addParameter($linkurl, 'actionID', 'view_public_key'), sprintf(_("View %s Public Key"), $val['name']), null, 'view_key'),
- 'info' => Horde::link(Util::addParameter($linkurl, 'actionID', 'info_public_key'), sprintf(_("Information on %s Public Key"), $val['name']), null, 'info_key'),
- 'delete' => Horde::link(Util::addParameter($linkurl, 'actionID', 'delete_public_key'), sprintf(_("Delete %s Public Key"), $val['name']), null, null, "if (confirm('" . addslashes(_("Are you sure you want to delete this public key?")) . "')) { return true; } else { return false; }")
- );
- }
- $t->set('pubkey_list', $plist);
+ $plist = array();
+ foreach ($pubkey_list as $val) {
+ $linkurl = Util::addParameter($selfURL, 'email', $val['email']);
+ $plist[] = array(
+ 'name' => $val['name'],
+ 'email' => $val['email'],
+ 'view' => Horde::link(Util::addParameter($linkurl, 'actionID', 'view_public_key'), sprintf(_("View %s Public Key"), $val['name']), null, 'view_key'),
+ 'info' => Horde::link(Util::addParameter($linkurl, 'actionID', 'info_public_key'), sprintf(_("Information on %s Public Key"), $val['name']), null, 'info_key'),
+ 'delete' => Horde::link(Util::addParameter($linkurl, 'actionID', 'delete_public_key'), sprintf(_("Delete %s Public Key"), $val['name']), null, null, "if (confirm('" . addslashes(_("Are you sure you want to delete this public key?")) . "')) { return true; } else { return false; }")
+ );
}
+ $t->set('pubkey_list', $plist);
}
$t->set('no_file_upload', !$_SESSION['imp']['file_upload']);
break;
case 'delete_public_key':
- $result = $imp_smime->deletePublicKey(Util::getFormData('email'));
- if (is_a($result, 'PEAR_Error')) {
- $notification->push($result, $result->getCode());
- } else {
+ try {
+ $imp_smime->deletePublicKey(Util::getFormData('email'));
$notification->push(sprintf(_("S/MIME Public Key for \"%s\" was successfully deleted."), Util::getFormData('email')), 'horde.success');
+ } catch (Horde_Exception $e) {
+ $notification->push($e);
}
break;
exit;
case 'view_public_key':
- $key = $imp_smime->getPublicKey(Util::getFormData('email'));
- if (is_a($key, 'PEAR_Error')) {
- $key = $key->getMessage();
- }
- _textWindowOutput('S/MIME Public Key', $key);
- exit;
-
case 'info_public_key':
- $key = $imp_smime->getPublicKey(Util::getFormData('email'));
- if (is_a($key, 'PEAR_Error')) {
- $key = $key->getMessage();
+ try {
+ $key = $imp_smime->getPublicKey(Util::getFormData('email'));
+ } catch (Horde_Exception $e) {
+ $key = $e->getMessage();
+ }
+ if ($actionID == 'view_public_key') {
+ _textWindowOutput('S/MIME Public Key', $key);
+ } else {
+ _printKeyInfo($key);
}
- _printKeyInfo($key);
exit;
case 'view_personal_public_key':
$actionID = 'import_personal_certs';
_importKeyDialog('process_import_personal_certs');
} else {
- $res = $imp_smime->addFromPKCS12($pkcs12, Util::getFormData('upload_key_pass'), Util::getFormData('upload_key_pk_pass'));
- if (is_a($res, 'PEAR_Error')) {
- $notification->push(_("Personal S/MIME certificates NOT imported: ") . $res->getMessage(), 'horde.error');
- $actionID = 'import_personal_certs';
- _importKeyDialog('process_import_personal_certs');
- } else {
+ try {
+ $imp_smime->addFromPKCS12($pkcs12, Util::getFormData('upload_key_pass'), Util::getFormData('upload_key_pk_pass'));
$notification->push(_("S/MIME Public/Private Keypair successfully added."), 'horde.success');
_reloadWindow();
+ } catch (Horde_Exception $e) {
+ $notification->push(_("Personal S/MIME certificates NOT imported: ") . $e->getMessage(), 'horde.error');
+ $actionID = 'import_personal_certs';
+ _importKeyDialog('process_import_personal_certs');
}
}
exit;
}
/* Get list of Public Keys. */
-$pubkey_list = $imp_smime->listPublicKeys();
-if (is_a($pubkey_list, 'PEAR_Error')) {
- $notification->push($pubkey_list, $pubkey_list->getCode());
+try {
+ $pubkey_list = $imp_smime->listPublicKeys();
+} catch (Horde_Exception $e) {
+ $pubkey_list = array();
+ $notification->push($e);
}
$result = Horde::loadConfiguration('prefs.php', array('prefGroups', '_prefs'), 'imp');
$t->set('empty_pubkey_list', empty($pubkey_list));
if (!$t->get('empty_pubkey_list')) {
- $t->set('pubkey_error', is_a($pubkey_list, 'PEAR_Error') ? $pubkey_list->getMessage() : false);
- if (!$t->get('pubkey_error')) {
- $plist = array();
- foreach ($pubkey_list as $val) {
- $linkurl = Util::addParameter($selfURL, 'email', $val['email']);
- $plist[] = array(
- 'name' => $val['name'],
- 'email' => $val['email'],
- 'view' => Horde::link(Util::addParameter($linkurl, 'actionID', 'view_public_key'), sprintf(_("View %s Public Key"), $val['name']), null, 'view_key'),
- 'info' => Horde::link(Util::addParameter($linkurl, 'actionID', 'info_public_key'), sprintf(_("Information on %s Public Key"), $val['name']), null, 'info_key'),
- 'delete' => Horde::link(Util::addParameter($linkurl, 'actionID', 'delete_public_key'), sprintf(_("Delete %s Public Key"), $val['name']), null, null, "if (confirm('" . addslashes(_("Are you sure you want to delete this public key?")) . "')) { return true; } else { return false; }")
- );
- }
- $t->set('pubkey_list', $plist);
+ $plist = array();
+ foreach ($pubkey_list as $val) {
+ $linkurl = Util::addParameter($selfURL, 'email', $val['email']);
+ $plist[] = array(
+ 'name' => $val['name'],
+ 'email' => $val['email'],
+ 'view' => Horde::link(Util::addParameter($linkurl, 'actionID', 'view_public_key'), sprintf(_("View %s Public Key"), $val['name']), null, 'view_key'),
+ 'info' => Horde::link(Util::addParameter($linkurl, 'actionID', 'info_public_key'), sprintf(_("Information on %s Public Key"), $val['name']), null, 'info_key'),
+ 'delete' => Horde::link(Util::addParameter($linkurl, 'actionID', 'delete_public_key'), sprintf(_("Delete %s Public Key"), $val['name']), null, null, "if (confirm('" . addslashes(_("Are you sure you want to delete this public key?")) . "')) { return true; } else { return false; }")
+ );
}
+ $t->set('pubkey_list', $plist);
}
$t->set('no_file_upload', !$_SESSION['imp']['file_upload']);
<if:empty_pubkey_list>
<em><gettext>No Keys in Keyring</gettext></em><br />
<else:empty_pubkey_list>
-<if:pubkey_error>
- <em style="color:red"><gettext>Error:</gettext></em> <tag:pubkey_error /><br />
-<else:pubkey_error>
<table>
<loop:pubkey_list>
<tr>
</tr>
</loop:pubkey_list>
</table>
-</else:pubkey_error></if:pubkey_error></else:empty_pubkey_list></if:empty_pubkey_list>
+</else:empty_pubkey_list></if:empty_pubkey_list>
<if:no_file_upload>
<br /><span style="color:red"><gettext>Key import is not available. File upload is not enabled on this server.</gettext></span><br />
<if:empty_pubkey_list>
<em><gettext>No Keys in Keyring</gettext></em>
<else:empty_pubkey_list>
-<if:pubkey_error>
- <em style="color:red"><gettext>Error:</gettext></em> <tag:pubkey_error />
-<else:pubkey_error>
<table>
<loop:pubkey_list>
<tr>
</tr>
</loop:pubkey_list>
</table>
-</else:pubkey_error></if:pubkey_error></else:empty_pubkey_list></if:empty_pubkey_list>
+</else:empty_pubkey_list></if:empty_pubkey_list>
<if:no_file_upload>
<em style="color:red"><gettext>Key import is not available. File upload is not enabled on this server.</gettext></em>
$actionID = Util::getFormData('actionID');
switch ($actionID) {
case 'add_address':
- $contact_link = IMP::addAddress(Util::getFormData('address'), Util::getFormData('name'));
- if (is_a($contact_link, 'PEAR_Error')) {
- $notification->push($contact_link);
- } else {
+ try {
+ $contact_link = IMP::addAddress(Util::getFormData('address'), Util::getFormData('name'));
$notification->push(sprintf(_("Entry \"%s\" was successfully added to the address book"), $contact_link), 'horde.success', array('content.raw'));
+ } catch (Horde_Exception $e) {
+ $notification->push($e);
}
break;
}