From fba1ab0c46ddbad3bcbb392d0d41891b8bea692c Mon Sep 17 00:00:00 2001 From: the-djmaze <3752035+the-djmaze@users.noreply.github.com> Date: Tue, 3 Nov 2026 21:57:10 +0100 Subject: [PATCH] Don't throw error when finding pgp key --- .../v/0.0.0/app/libraries/snappymail/gpg/pgp.php | 12 +++++++++--- .../v/0.0.0/app/libraries/snappymail/pgp/pecl.php | 6 +++--- .../libraries/snappymail/repository/signature.php | 8 ++++---- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/gpg/pgp.php b/snappymail/v/0.0.0/app/libraries/snappymail/gpg/pgp.php index 543b9a5c2..23124eb6f 100644 --- a/snappymail/v/0.0.0/app/libraries/snappymail/gpg/pgp.php +++ b/snappymail/v/0.0.0/app/libraries/snappymail/gpg/pgp.php @@ -445,7 +445,13 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface $arguments[] = \escapeshellarg($pattern); } - $result = $this->exec($arguments); + try { + $result = $this->exec($arguments); + } catch (\RuntimeException $e) { + if (!\str_contains($e->getMessage(), 'No public key')) { + throw $e; + } + } $keys = []; if ($result) { @@ -565,13 +571,13 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface 'private' => [] ]; // Public - foreach (($this->keyinfo($pattern) ?: []) as $key) { + foreach (($this->keyInfo($pattern) ?: []) as $key) { $key['can_verify'] = $key['can_sign']; unset($key['can_sign']); $keys['public'][] = $key; } // Private, read https://github.com/php-gnupg/php-gnupg/issues/5 - foreach (($this->keyinfo($pattern, 1) ?: []) as $key) { + foreach (($this->keyInfo($pattern, 1) ?: []) as $key) { $key['can_decrypt'] = $key['can_encrypt']; unset($key['can_encrypt']); $keys['private'][] = $key; diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/pgp/pecl.php b/snappymail/v/0.0.0/app/libraries/snappymail/pgp/pecl.php index bdbaaefe8..68cb2b619 100644 --- a/snappymail/v/0.0.0/app/libraries/snappymail/pgp/pecl.php +++ b/snappymail/v/0.0.0/app/libraries/snappymail/pgp/pecl.php @@ -285,7 +285,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface public function keyInfo(string $pattern, bool $private = false): array { - return $this->GnuPG->keyinfo($pattern, $private ? 1 : 0); + return $this->GnuPG->keyInfo($pattern, $private ? 1 : 0); } /** @@ -298,13 +298,13 @@ class PECL implements \SnappyMail\PGP\PGPInterface 'private' => [] ]; // Public - foreach (($this->GnuPG->keyinfo($pattern) ?: []) as $key) { + foreach (($this->GnuPG->keyInfo($pattern) ?: []) as $key) { $key['can_verify'] = $key['can_sign']; unset($key['can_sign']); $keys['public'][] = $key; } // Private, read https://github.com/php-gnupg/php-gnupg/issues/5 - foreach (($this->GnuPG->keyinfo($pattern, 1) ?: []) as $key) { + foreach (($this->GnuPG->keyInfo($pattern, 1) ?: []) as $key) { $key['can_decrypt'] = $key['can_encrypt']; unset($key['can_encrypt']); $keys['private'][] = $key; diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/repository/signature.php b/snappymail/v/0.0.0/app/libraries/snappymail/repository/signature.php index a9054b682..3bfbce10f 100644 --- a/snappymail/v/0.0.0/app/libraries/snappymail/repository/signature.php +++ b/snappymail/v/0.0.0/app/libraries/snappymail/repository/signature.php @@ -41,7 +41,7 @@ abstract class Signature private static function importKey($gnupg): void { - if (!\count($gnupg->keyinfo(static::KEY_FINGERPRINT))) { + if (!\count($gnupg->keyInfo(static::KEY_FINGERPRINT))) { // Try local key $file = __DIR__ . '/repository/releases.asc'; if (\is_readable($file)) { @@ -50,16 +50,16 @@ abstract class Signature } $gnupg->importFile($file); } - if (!\count($gnupg->keyinfo(static::KEY_FINGERPRINT))) { + if (!\count($gnupg->keyInfo(static::KEY_FINGERPRINT))) { // Try to fetch from WKD server // https://snappymail.eu/.well-known/openpgpkey/hu/i4cdqgcarfjdjnba6y4jnf498asg8c6p $sKey = Keyservers::wkd('releases@snappymail.eu'); $sKey && $gnupg->import($sKey); // Try to fetch from HKPS server - if (!\count($gnupg->keyinfo(static::KEY_FINGERPRINT))) { + if (!\count($gnupg->keyInfo(static::KEY_FINGERPRINT))) { $sKey = Keyservers::get(static::KEY_FINGERPRINT); $sKey && $gnupg->import($sKey); - if (!\count($gnupg->keyinfo(static::KEY_FINGERPRINT))) { + if (!\count($gnupg->keyInfo(static::KEY_FINGERPRINT))) { throw new \Exception('Repository PGP public key is missing'); /* $aKeys = Keyservers::index('releases@snappymail.eu');