From a9d399155d205ae41015d7d205c6dacd7ecfc0d2 Mon Sep 17 00:00:00 2001 From: Kyle Francis <franck6@rpi.edu> Date: Wed, 30 Mar 2016 09:33:53 -0400 Subject: [PATCH] Implemented attaching pub PGP key to outgoing messages. --- plugins/enigma/lib/enigma_ui.php | 24 +++++++++++++++++++++++- 1 files changed, 23 insertions(+), 1 deletions(-) diff --git a/plugins/enigma/lib/enigma_ui.php b/plugins/enigma/lib/enigma_ui.php index 6ae69da..f0963dc 100644 --- a/plugins/enigma/lib/enigma_ui.php +++ b/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. -- Gitblit v1.9.1