Thomas Bruederli
2015-04-17 a3644638aaf0418598196a870204e0b632a4c8ad
plugins/enigma/enigma.php
@@ -3,18 +3,11 @@
 +-------------------------------------------------------------------------+
 | Enigma Plugin for Roundcube                                             |
 |                                                                         |
 | This program is free software; you can redistribute it and/or modify    |
 | it under the terms of the GNU General Public License version 2          |
 | as published by the Free Software Foundation.                           |
 | Copyright (C) 2010-2015 The Roundcube Dev Team                          |
 |                                                                         |
 | This program is distributed in the hope that it will be useful,         |
 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
 | GNU General Public License for more details.                            |
 |                                                                         |
 | You should have received a copy of the GNU General Public License along |
 | with this program; if not, write to the Free Software Foundation, Inc., |
 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.             |
 | Licensed under the GNU General Public License version 3 or              |
 | any later version with exceptions for skins & plugins.                  |
 | See the README file for a full license statement.                       |
 |                                                                         |
 +-------------------------------------------------------------------------+
 | Author: Aleksander Machniak <alec@alec.pl>                              |
@@ -31,6 +24,7 @@
    public $task = 'mail|settings';
    public $rc;
    public $engine;
    public $ui;
    private $env_loaded  = false;
@@ -43,8 +37,6 @@
        $this->rc = rcube::get_instance();
        if ($this->rc->task == 'mail') {
            $section = rcube_utils::get_input_value('_section', rcube_utils::INPUT_GET);
            // message parse/display hooks
            $this->add_hook('message_part_structure', array($this, 'part_structure'));
            $this->add_hook('message_part_body', array($this, 'part_body'));
@@ -60,12 +52,11 @@
            // message composing
            else if ($this->rc->action == 'compose') {
                $this->load_ui();
                $this->ui->init($section);
                $this->ui->init();
            }
            // message sending (and draft storing)
            else if ($this->rc->action == 'sendmail') {
                //$this->add_hook('outgoing_message_body', array($this, 'msg_encode'));
                //$this->add_hook('outgoing_message_body', array($this, 'msg_sign'));
            else if ($this->rc->action == 'send') {
                $this->add_hook('message_ready', array($this, 'message_ready'));
            }
            $this->password_handler();
@@ -73,13 +64,13 @@
        else if ($this->rc->task == 'settings') {
            // add hooks for Enigma settings
            $this->add_hook('settings_actions', array($this, 'settings_actions'));
//            $this->add_hook('preferences_list', array($this, 'preferences_list'));
//            $this->add_hook('preferences_save', array($this, 'preferences_save'));
            $this->add_hook('preferences_sections_list', array($this, 'preferences_sections_list'));
            $this->add_hook('preferences_list', array($this, 'preferences_list'));
            $this->add_hook('preferences_save', array($this, 'preferences_save'));
            // register handler for keys/certs management
//            $this->register_action('plugin.enigma', array($this, 'preferences_ui'));
            $this->register_action('plugin.enigmakeys', array($this, 'preferences_ui'));
            $this->register_action('plugin.enigmacerts', array($this, 'preferences_ui'));
//            $this->register_action('plugin.enigmacerts', array($this, 'preferences_ui'));
            $this->load_ui();
            $this->ui->add_css();
@@ -209,6 +200,23 @@
    }
    /**
     * Handler for preferences_sections_list hook.
     * Adds Encryption settings section into preferences sections list.
     *
     * @param array Original parameters
     *
     * @return array Modified parameters
     */
    function preferences_sections_list($p)
    {
        $p['list']['enigma'] = array(
            'id' => 'enigma', 'section' => $this->gettext('encryption'),
        );
        return $p;
    }
    /**
     * Handler for preferences_list hook.
     * Adds options blocks into Enigma settings sections in Preferences.
     *
@@ -218,12 +226,111 @@
     */
    function preferences_list($p)
    {
/*
        if ($p['section'] == 'enigmasettings') {
            // This makes that section is not removed from the list
            $p['blocks']['dummy']['options']['dummy'] = array();
        if ($p['section'] != 'enigma') {
            return $p;
        }
*/
        $no_override = array_flip((array)$this->rc->config->get('dont_override'));
        $p['blocks']['main']['name'] = $this->gettext('mainoptions');
        if (!isset($no_override['enigma_signatures'])) {
            if (!$p['current']) {
                $p['blocks']['main']['content'] = true;
                return $p;
            }
            $field_id = 'rcmfd_enigma_signatures';
            $input    = new html_checkbox(array(
                    'name'  => '_enigma_signatures',
                    'id'    => $field_id,
                    'value' => 1,
            ));
            $p['blocks']['main']['options']['enigma_signatures'] = array(
                'title'   => html::label($field_id, $this->gettext('supportsignatures')),
                'content' => $input->show(intval($this->rc->config->get('enigma_signatures'))),
            );
        }
        if (!isset($no_override['enigma_decryption'])) {
            if (!$p['current']) {
                $p['blocks']['main']['content'] = true;
                return $p;
            }
            $field_id = 'rcmfd_enigma_decryption';
            $input    = new html_checkbox(array(
                    'name'  => '_enigma_decryption',
                    'id'    => $field_id,
                    'value' => 1,
            ));
            $p['blocks']['main']['options']['enigma_decryption'] = array(
                'title'   => html::label($field_id, $this->gettext('supportdecryption')),
                'content' => $input->show(intval($this->rc->config->get('enigma_decryption'))),
            );
        }
        if (!isset($no_override['enigma_sign_all'])) {
            if (!$p['current']) {
                $p['blocks']['main']['content'] = true;
                return $p;
            }
            $field_id = 'rcmfd_enigma_sign_all';
            $input    = new html_checkbox(array(
                    'name'  => '_enigma_sign_all',
                    'id'    => $field_id,
                    'value' => 1,
            ));
            $p['blocks']['main']['options']['enigma_sign_all'] = array(
                'title'   => html::label($field_id, $this->gettext('signdefault')),
                'content' => $input->show($this->rc->config->get('enigma_sign_all') ? 1 : 0),
            );
        }
        if (!isset($no_override['enigma_encrypt_all'])) {
            if (!$p['current']) {
                $p['blocks']['main']['content'] = true;
                return $p;
            }
            $field_id = 'rcmfd_enigma_encrypt_all';
            $input    = new html_checkbox(array(
                    'name'  => '_enigma_encrypt_all',
                    'id'    => $field_id,
                    'value' => 1,
            ));
            $p['blocks']['main']['options']['enigma_encrypt_all'] = array(
                'title'   => html::label($field_id, $this->gettext('encryptdefault')),
                'content' => $input->show($this->rc->config->get('enigma_encrypt_all') ? 1 : 0),
            );
        }
        if (!isset($no_override['enigma_password_time'])) {
            if (!$p['current']) {
                $p['blocks']['main']['content'] = true;
                return $p;
            }
            $field_id = 'rcmfd_enigma_password_time';
            $select   = new html_select(array('name' => '_enigma_password_time', 'id' => $field_id));
            foreach (array(1, 5, 10, 15, 30) as $m) {
                $label = $this->gettext(array('name' => 'nminutes', 'vars' => array('m' => $m)));
                $select->add($label, $m);
            }
            $select->add($this->gettext('wholesession'), 0);
            $p['blocks']['main']['options']['enigma_password_time'] = array(
                'title'   => html::label($field_id, $this->gettext('passwordtime')),
                'content' => $select->show(intval($this->rc->config->get('enigma_password_time'))),
            );
        }
        return $p;
    }
@@ -237,13 +344,16 @@
     */
    function preferences_save($p)
    {
/*
        if ($p['section'] == 'enigmasettings') {
            $a['prefs'] = array(
                'dummy' => rcube_utils::get_input_value('_dummy', rcube_utils::INPUT_POST),
        if ($p['section'] == 'enigma') {
            $p['prefs'] = array(
                'enigma_signatures' => (bool) rcube_utils::get_input_value('_enigma_signatures', rcube_utils::INPUT_POST),
                'enigma_decryption' => (bool) rcube_utils::get_input_value('_enigma_decryption', rcube_utils::INPUT_POST),
                'enigma_sign_all'      => intval(rcube_utils::get_input_value('_enigma_sign_all', rcube_utils::INPUT_POST)),
                'enigma_encrypt_all'   => intval(rcube_utils::get_input_value('_enigma_encrypt_all', rcube_utils::INPUT_POST)),
                'enigma_password_time' => intval(rcube_utils::get_input_value('_enigma_password_time', rcube_utils::INPUT_POST)),
            );
        }
*/
        return $p;
    }
@@ -313,10 +423,21 @@
    function password_handler()
    {
        $this->load_engine();
        $this->engine->password_handler();
    }
    /**
     * Handle message_ready hook (encryption/signing)
     */
    function message_ready($p)
    {
        $this->load_ui();
        return $this->ui->message_ready($p);
    }
    /**
     * Handler for refresh hook.
     */
    function refresh($p)