--- ./lib/Crypt/PGP.php-old 2007-11-18 20:31:33.000000000 +0100 +++ ./lib/Crypt/PGP.php 2007-11-18 21:00:10.000000000 +0100 @@ -163,6 +163,18 @@ return $key_info; } + /** + * Retrieves the public key from the preference storage. + */ + function _getPublicKeyFromPrefs($address) + { + global $conf; + $userprefs = &Prefs::singleton($conf['prefs']['driver'],'imp', $address, '', null, false); + $userprefs->retrieve(); + return $pk = $userprefs->getValue('pgp_public_key'); + } + + /** * Retrieves a public key by e-mail. * First, the key will be attempted to be retrieved from a user's @@ -178,10 +190,20 @@ */ function getPublicKey($address, $fingerprint = null) { - /* Try retrieving by e-mail only first. */ + /* 1. try users database */ + $prefs_key = $this->_getPublicKeyFromPrefs($address); + if(strlen($prefs_key) > 100 && + preg_match('/-----BEGIN PGP ([^-]+)-----/', $prefs_key)){ + return $prefs_key; + } + + /* 2. try retrieving from Contacts */ $result = $GLOBALS['registry']->call('contacts/getField', array($address, IMP_PGP_PUBKEY_FIELD, $this->_sources, false, true)); /* TODO: Retrieve by ID. */ + if($fingerprint == null){ + $fingerprint = $address; + } /* Try retrieving via a PGP public keyserver. */ if (is_a($result, 'PEAR_Error') && !empty($fingerprint)) {