* address book and remove the id from the key_info for a correct
* output. */
try {
- $result = $this->getPublicKey($sig['email'], null, false);
+ $result = $this->getPublicKey($sig['email'], array('nocache' => true, 'noserver' => true));
if (!empty($result)) {
unset($key_info['signature'][$id]);
continue;
* Second, if unsuccessful, the key is attempted to be retrieved via a
* public PGP keyserver.
*
- * @param string $address The e-mail address to search by.
- * @param string $fingerprint The fingerprint of the user's key.
- * @param boolean $server Whether to check the public key servers for
- * the key.
+ * @param string $address The e-mail address to search by.
+ * @param array $options Additional options:
+ * <pre>
+ * 'fingerprint' - (string) The fingerprint of the user's key.
+ * DEFAULT: fingerprint not used
+ * 'nocache' - (boolean) Don't retrieve from cache?
+ * DEFAULT: false
+ * 'noserver' - (boolean) Whether to check the public key servers for the
+ * key.
+ * DEFAULT: false
+ * </pre>
*
* @return string The PGP public key requested.
* @throws Horde_Exception
*/
- public function getPublicKey($address, $fingerprint = null, $server = true)
+ public function getPublicKey($address, $options = array())
{
+ $fingerprint = empty($options['fingerprint'])
+ ? ''
+ : $options['fingerprint'];
+
/* If there is a cache driver configured, try to get the public key
* from the cache. */
- if (($cache = IMP::getCache())) {
+ if (empty($options['nocache']) && ($cache = IMP::getCache())) {
$result = $cache->get("PGPpublicKey_" . $address . $fingerprint, 3600);
if ($result) {
Horde::logMessage('PGPpublicKey: ' . serialize($result), __FILE__, __LINE__, PEAR_LOG_DEBUG);
}
/* Try retrieving via a PGP public keyserver. */
- if ($server && is_a($result, 'PEAR_Error')) {
+ if (empty($options['noserver']) && is_a($result, 'PEAR_Error')) {
try {
$result = $this->getFromPublicKeyserver($fingerprint, $address);
$fingerprint = $this->getSignersKeyID($text);
}
- $public_key = $this->getPublicKey($address, $fingerprint);
+ $public_key = $this->getPublicKey($address, array('fingerprint' => $fingerprint));
if (empty($signature)) {
$options = array('type' => 'signature');
} else {
/* Add the public key to the storage system. */
try {
- $imp_pgp->addPublicKey($publicKey);
+ $key_info = $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');
}
case 'view_public_key':
case 'info_public_key':
try {
- $key = $imp_pgp->getPublicKey(Util::getFormData('email'), null, false);
+ $key = $imp_pgp->getPublicKey(Util::getFormData('email'), array('noserver' => true));
} catch (Horde_Exception $e) {
$key = $e->getMessage();
}