plugins/enigma/lib/enigma_driver_gnupg.php | ●●●●● patch | view | raw | blame | history | |
plugins/enigma/lib/enigma_engine.php | ●●●●● patch | view | raw | blame | history | |
plugins/enigma/lib/enigma_ui.php | ●●●●● patch | view | raw | blame | history |
plugins/enigma/lib/enigma_driver_gnupg.php
@@ -339,6 +339,17 @@ } } public function pubkey_for_attach($email) { try { $pubkey = $this->gpg->exportPublicKey($email, true); return $pubkey; } catch (Exception $e) { return $this->get_error_from_exception($e); } } /** * Converts Crypt_GPG exception into Enigma's error object * plugins/enigma/lib/enigma_engine.php
@@ -921,6 +921,38 @@ return $result; } function get_gpg_pubkey_for_attach($email) { $this->load_pgp_driver(); $result = $this->pgp_driver->pubkey_for_attach($email); if ($result instanceof enigma_error) { rcube::raise_error(array( 'code' => 600, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Enigma plugin: " . $result->getMessage() ), true, false); } return $result; } function get_keyID($email) { $this->load_pgp_driver(); $result = $this->pgp_driver->get_keyID($email); if ($result instanceof enigma_error) { rcube::raise_error(array( 'code' => 600, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Enigma plugin: " . $result->getMessage() ), true, false); } return $result; } /** * Find PGP private/public key * plugins/enigma/lib/enigma_ui.php
@@ -929,11 +929,15 @@ } /** * Handle message_ready hook (encryption/signing) * Handle message_ready hook (encryption/signing/attach public key) */ function message_ready($p) { $savedraft = !empty($_POST['_draft']) && empty($_GET['_saveonly']); if (!$savedraft && rcube_utils::get_input_value('_enigma_attachpubkey', rcube_utils::INPUT_POST)) { $p = $this->attach_public($p); } if (!$savedraft && rcube_utils::get_input_value('_enigma_sign', rcube_utils::INPUT_POST)) { $this->enigma->load_engine(); @@ -972,6 +976,24 @@ } /** * Add sender's public key (PGP). */ function attach_public($p) { // get sender's PGP pubkey for attachment $this->enigma->load_engine(); $key = $this->enigma->engine->list_keys($p['message']->headers()['From']); $keyID = $key[0]->subkeys[0]->get_short_id(); $pubkey_armor = $this->enigma->engine->get_gpg_pubkey_for_attach($p['message']->headers()['From']); if(!$pubkey_armor instanceof enigma_error) { $p['message']->addAttachment($pubkey_armor, 'application/pgp-keys', "0x$keyID.asc", false); } return $p; } /** * Handler for message_compose_body hook * Display error when the message cannot be encrypted * and provide a way to try again with a password.