From f0fa9324d83ea1bd57f0b702e3b419f7194169cb Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Thu, 21 Apr 2016 02:13:52 -0400
Subject: [PATCH] Merge branch 'master' of github.com:roundcube/roundcubemail

---
 CHANGELOG                                   |    2 ++
 INSTALL                                     |    2 +-
 plugins/enigma/lib/enigma_driver_gnupg.php  |   14 ++++++++++++--
 program/lib/Roundcube/rcube_addressbook.php |    4 ++--
 plugins/enigma/composer.json                |    2 +-
 program/lib/Roundcube/rcube_contacts.php    |    4 +++-
 composer.json-dist                          |    2 +-
 plugins/enigma/config.inc.php.dist          |    3 +++
 8 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 3c03d58..f717326 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,8 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Enigma: Added enigma_debug option
+
 RELEASE 1.2-rc
 --------------
 - Managesieve: Refactored script parser to be 100x faster
diff --git a/INSTALL b/INSTALL
index 6dd289e..7056495 100644
--- a/INSTALL
+++ b/INSTALL
@@ -22,7 +22,7 @@
    - Net_IDNA2 0.1.1 or newer
    - Auth_SASL 1.0.6 or newer
    - Net_Sieve 1.3.2 or newer (for managesieve plugin)
-   - Crypt_GPG 1.4.0 or newer (for enigma plugin)
+   - Crypt_GPG 1.4.1 or newer (for enigma plugin)
 * php.ini options (see .htaccess file):
    - error_reporting E_ALL & ~E_NOTICE (or lower)
    - memory_limit > 16MB (increase as suitable to support large attachments)
diff --git a/composer.json-dist b/composer.json-dist
index 58c50c7..f14541c 100644
--- a/composer.json-dist
+++ b/composer.json-dist
@@ -28,7 +28,7 @@
         "pear-pear.php.net/net_idna2": "~0.1.1",
         "pear-pear.php.net/mail_mime": "~1.10.0",
         "pear-pear.php.net/net_smtp": "~1.7.1",
-        "pear-pear.php.net/crypt_gpg": "~1.4.0",
+        "pear-pear.php.net/crypt_gpg": "~1.4.1",
         "roundcube/net_sieve": "~1.5.0"
     },
     "require-dev": {
diff --git a/plugins/enigma/composer.json b/plugins/enigma/composer.json
index 4cfc44d..244ba05 100644
--- a/plugins/enigma/composer.json
+++ b/plugins/enigma/composer.json
@@ -24,6 +24,6 @@
     "require": {
         "php": ">=5.3.0",
         "roundcube/plugin-installer": "~0.1.6",
-        "pear-pear.php.net/crypt_gpg": "~1.4.0"
+        "pear-pear.php.net/crypt_gpg": "~1.4.1"
     }
 }
diff --git a/plugins/enigma/config.inc.php.dist b/plugins/enigma/config.inc.php.dist
index f7f6f9a..2b9b846 100644
--- a/plugins/enigma/config.inc.php.dist
+++ b/plugins/enigma/config.inc.php.dist
@@ -9,6 +9,9 @@
 // A driver to use for S/MIME. Default: "phpssl".
 $config['enigma_smime_driver'] = 'phpssl';
 
+// Enables logging of enigma operations (including Crypt_GPG debug info)
+$config['enigma_debug'] = false;
+
 // Keys directory for all users. Default 'enigma/home'.
 // Must be writeable by PHP process
 $config['enigma_pgp_homedir'] = null;
diff --git a/plugins/enigma/lib/enigma_driver_gnupg.php b/plugins/enigma/lib/enigma_driver_gnupg.php
index 5ddf724..9a8e59e 100644
--- a/plugins/enigma/lib/enigma_driver_gnupg.php
+++ b/plugins/enigma/lib/enigma_driver_gnupg.php
@@ -40,6 +40,7 @@
     function init()
     {
         $homedir = $this->rc->config->get('enigma_pgp_homedir', INSTALL_PATH . 'plugins/enigma/home');
+        $debug   = $this->rc->config->get('enigma_debug');
 
         if (!$homedir)
             return new enigma_error(enigma_error::INTERNAL,
@@ -73,7 +74,7 @@
             $this->gpg = new Crypt_GPG(array(
                 'homedir'   => $this->homedir,
                 // 'binary'    => '/usr/bin/gpg2',
-                // 'debug'     => true,
+                'debug'     => $debug ? array($this, 'debug') : false,
           ));
         }
         catch (Exception $e) {
@@ -257,10 +258,11 @@
     public function gen_key($data)
     {
         try {
+            $debug  = $this->rc->config->get('enigma_debug');
             $keygen = new Crypt_GPG_KeyGenerator(array(
                     'homedir' => $this->homedir,
                     // 'binary'  => '/usr/bin/gpg2',
-                    // 'debug'   => true,
+                    'debug'   => $debug ? array($this, 'debug') : false,
             ));
 
             $key = $keygen
@@ -441,4 +443,12 @@
 
         return $ekey;
     }
+
+    /**
+     * Write debug info from Crypt_GPG to logs/enigma
+     */
+    public function debug($line)
+    {
+        rcube::write_log('enigma', 'GPG: ' . $line);
+    }
 }
diff --git a/program/lib/Roundcube/rcube_addressbook.php b/program/lib/Roundcube/rcube_addressbook.php
index 5f13da0..ae72dcd 100644
--- a/program/lib/Roundcube/rcube_addressbook.php
+++ b/program/lib/Roundcube/rcube_addressbook.php
@@ -130,10 +130,10 @@
     /**
      * Get a specific contact record
      *
-     * @param mixed record identifier(s)
+     * @param mixed   Record identifier(s)
      * @param boolean True to return record as associative array, otherwise a result set is returned
      *
-     * @return mixed Result object with all record fields or False if not found
+     * @return rcube_result_set|array Result object with all record fields
      */
     abstract function get_record($id, $assoc=false);
 
diff --git a/program/lib/Roundcube/rcube_contacts.php b/program/lib/Roundcube/rcube_contacts.php
index c9c01e4..71549e9 100644
--- a/program/lib/Roundcube/rcube_contacts.php
+++ b/program/lib/Roundcube/rcube_contacts.php
@@ -542,7 +542,7 @@
      * @param mixed $id    Record identifier(s)
      * @param bool  $assoc Enables returning associative array
      *
-     * @return mixed Result object with all record fields or False if not found
+     * @return rcube_result_set|array Result object with all record fields
      */
     function get_record($id, $assoc = false)
     {
@@ -560,6 +560,8 @@
             $this->user_id
         );
 
+        $this->result = null;
+
         if ($sql_arr = $this->db->fetch_assoc()) {
             $record = $this->convert_db_data($sql_arr);
             $this->result = new rcube_result_set(1);

--
Gitblit v1.9.1