From 2965a981b7ec22866fbdf2d567d87e2d068d3617 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Fri, 31 Jul 2015 16:04:08 -0400
Subject: [PATCH] Allow to search and import missing PGP pubkeys from keyservers using Publickey.js

---
 plugins/enigma/enigma.js |   66 ++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 1 deletions(-)

diff --git a/plugins/enigma/enigma.js b/plugins/enigma/enigma.js
index a7bc43f..4048d8d 100644
--- a/plugins/enigma/enigma.js
+++ b/plugins/enigma/enigma.js
@@ -33,6 +33,9 @@
     }
     else if (rcmail.env.task == 'mail') {
         if (rcmail.env.action == 'compose') {
+            rcmail.addEventListener('beforesend', function(props) { rcmail.enigma_beforesend_handler(props); })
+                .addEventListener('beforesavedraft', function(props) { rcmail.enigma_beforesavedraft_handler(props); });
+
             $('input,label', $('#enigmamenu')).mouseup(function(e) {
                 // don't close the menu on mouse click inside
                 e.stopPropagation();
@@ -234,9 +237,45 @@
     list.insert_row(row);
 }
 
+
 /*********************************************************/
 /*********        Enigma Message methods         *********/
 /*********************************************************/
+
+// handle message send/save action
+rcube_webmail.prototype.enigma_beforesend_handler = function(props)
+{
+    this.env.last_action = 'send';
+    this.enigma_compose_handler(props);
+}
+
+rcube_webmail.prototype.enigma_beforesavedraft_handler = function(props)
+{
+    this.env.last_action = 'savedraft';
+    this.enigma_compose_handler(props);
+}
+
+rcube_webmail.prototype.enigma_compose_handler = function(props)
+{
+    var form = this.gui_objects.messageform;
+
+    // copy inputs from enigma menu to the form
+    $('#enigmamenu input').each(function() {
+        var id = this.id + '_cpy', input = $('#' + id);
+
+        if (!input.length) {
+            input = $(this).clone();
+            input.prop({id: id, type: 'hidden'}).appendTo(form);
+        }
+
+        input.val(this.checked ? '1' : '');
+    });
+
+    // disable signing when saving drafts
+    if (this.env.last_action == 'savedraft') {
+        $('input[name="_enigma_sign"]', form).val(0);
+    }
+}
 
 // Import attached keys/certs file
 rcube_webmail.prototype.enigma_import_attachment = function(mime_id)
@@ -249,6 +288,7 @@
     return false;
 }
 
+// password request popup
 rcube_webmail.prototype.enigma_password_request = function(data)
 {
     if (!data || !data.keyid) {
@@ -268,7 +308,8 @@
             .appendTo(myprompt);
 
     data.key = data.keyid;
-    data.keyid = data.keyid.substr(0, 8);
+    if (data.keyid.length > 8)
+        data.keyid = data.keyid.substr(data.keyid.length - 8);
 
     $.each(['keyid', 'user'], function() {
         msg = msg.replace('$' + this, data[this]);
@@ -310,8 +351,14 @@
     }
 }
 
+// submit entered password
 rcube_webmail.prototype.enigma_password_submit = function(keyid, password)
 {
+    if (this.env.action == 'compose') {
+        return this.enigma_password_compose_submit(keyid, password);
+    }
+
+    // message preview
     var form = $('<form>').attr({method: 'post', action: location.href, style: 'display:none'})
         .append($('<input>').attr({type: 'hidden', name: '_keyid', value: keyid}))
         .append($('<input>').attr({type: 'hidden', name: '_passwd', value: password}))
@@ -320,3 +367,20 @@
 
     form.submit();
 }
+
+// submit entered password - in mail compose page
+rcube_webmail.prototype.enigma_password_compose_submit = function(keyid, password)
+{
+    var form = this.gui_objects.messageform;
+
+    if (!$('input[name="_keyid"]', form).length) {
+        $(form).append($('<input>').attr({type: 'hidden', name: '_keyid', value: keyid}))
+            .append($('<input>').attr({type: 'hidden', name: '_passwd', value: password}));
+    }
+    else {
+        $('input[name="_keyid"]', form).val(keyid);
+        $('input[name="_passwd"]', form).val(password);
+    }
+
+    this.submit_messageform(this.env.last_action == 'savedraft');
+}

--
Gitblit v1.9.1