From 96c3d84cddb861956cfbc719d694eb972343f1c3 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sat, 02 Apr 2016 04:35:17 -0400
Subject: [PATCH] Enigma: Varius fixes and cleanup in code for attaching pubkeys
---
plugins/enigma/lib/enigma_engine.php | 59 +++++++++++++++++++++++++++--------------------------------
1 files changed, 27 insertions(+), 32 deletions(-)
diff --git a/plugins/enigma/lib/enigma_engine.php b/plugins/enigma/lib/enigma_engine.php
index d2f3972..c970933 100644
--- a/plugins/enigma/lib/enigma_engine.php
+++ b/plugins/enigma/lib/enigma_engine.php
@@ -313,6 +313,33 @@
}
/**
+ * Handler for attaching public key to a message
+ *
+ * @param Mail_mime Original message
+ *
+ * @return bool True on success, False on failure
+ */
+ function attach_public_key(&$message)
+ {
+ $headers = $message->headers();
+ $from = rcube_mime::decode_address_list($headers['From'], 1, false, null, true);
+ $from = $from[1];
+
+ // find my key
+ if ($from && ($key = $this->find_key($from))) {
+ $pubkey_armor = $this->export_key($key->id);
+
+ if (!$pubkey_armor instanceof enigma_error) {
+ $pubkey_name = '0x' . enigma_key::format_id($key->id) . '.asc';
+ $message->addAttachment($pubkey_armor, 'application/pgp-keys', $pubkey_name, false, '7bit');
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
* Handler for message_part_structure hook.
* Called for every part of the message.
*
@@ -909,38 +936,6 @@
{
$this->load_pgp_driver();
$result = $this->pgp_driver->list_keys($pattern);
-
- 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_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(
--
Gitblit v1.9.1