123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511 |
- <?php
-
-
-
-
- class enigma extends rcube_plugin
- {
- public $task = 'mail|settings';
- public $rc;
- public $engine;
- public $ui;
-
- private $env_loaded = false;
-
-
-
-
- function init()
- {
- $this->rc = rcube::get_instance();
-
- if ($this->rc->task == 'mail') {
-
- $this->add_hook('message_part_structure', array($this, 'part_structure'));
- $this->add_hook('message_part_body', array($this, 'part_body'));
- $this->add_hook('message_body_prefix', array($this, 'status_message'));
-
- $this->register_action('plugin.enigmaimport', array($this, 'import_file'));
-
-
- $this->load_config();
-
- $enabled = $this->rc->config->get('enigma_encryption', true);
-
-
- if ($this->rc->action == 'show' || $this->rc->action == 'preview' || $this->rc->action == 'print') {
- $this->add_hook('message_load', array($this, 'message_load'));
- $this->add_hook('template_object_messagebody', array($this, 'message_output'));
- }
-
- else if ($enabled && $this->rc->action == 'compose') {
- $this->add_hook('message_compose_body', array($this, 'message_compose'));
-
- $this->load_ui();
- $this->ui->init();
- }
-
- else if ($enabled && $this->rc->action == 'send') {
- $this->add_hook('message_ready', array($this, 'message_ready'));
- }
-
- $this->password_handler();
- }
- else if ($this->rc->task == 'settings') {
-
- $this->add_hook('settings_actions', array($this, 'settings_actions'));
- $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'));
-
-
- $this->register_action('plugin.enigmakeys', array($this, 'preferences_ui'));
-
-
- $this->load_ui();
-
- if (empty($_REQUEST['_framed']) || strpos($this->rc->action, 'plugin.enigma') === 0) {
- $this->ui->add_css();
- }
- }
-
- $this->add_hook('refresh', array($this, 'refresh'));
- }
-
-
-
- function load_env()
- {
- if ($this->env_loaded) {
- return;
- }
-
- $this->env_loaded = true;
-
-
- $include_path = $this->home . '/lib' . PATH_SEPARATOR;
- $include_path .= ini_get('include_path');
- set_include_path($include_path);
-
-
- $this->load_config();
-
-
- $this->add_texts('localization/');
- }
-
-
-
- function load_ui($all = false)
- {
- if (!$this->ui) {
-
- $this->load_env();
-
-
- $this->ui = new enigma_ui($this, $this->home);
- }
-
- if ($all) {
- $this->ui->add_css();
- $this->ui->add_js();
- }
- }
-
-
-
- function load_engine()
- {
- if ($this->engine) {
- return $this->engine;
- }
-
-
- $this->load_env();
-
- return $this->engine = new enigma_engine($this);
- }
-
-
-
- function part_structure($p)
- {
- $this->load_engine();
-
- return $this->engine->part_structure($p);
- }
-
-
-
- function part_body($p)
- {
- $this->load_engine();
-
- return $this->engine->part_body($p);
- }
-
-
-
- function settings_actions($args)
- {
-
- $this->add_texts('localization/');
-
-
- $args['actions'][] = array(
- 'action' => 'plugin.enigmakeys',
- 'class' => 'enigma keys',
- 'label' => 'enigmakeys',
- 'title' => 'enigmakeys',
- 'domain' => 'enigma',
- );
-
- return $args;
- }
-
-
-
- function preferences_sections_list($p)
- {
- $p['list']['enigma'] = array(
- 'id' => 'enigma', 'section' => $this->gettext('encryption'),
- );
-
- return $p;
- }
-
-
-
- function preferences_list($p)
- {
- 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_encryption'])) {
- if (!$p['current']) {
- $p['blocks']['main']['content'] = true;
- return $p;
- }
-
- $field_id = 'rcmfd_enigma_encryption';
- $input = new html_checkbox(array(
- 'name' => '_enigma_encryption',
- 'id' => $field_id,
- 'value' => 1,
- ));
-
- $p['blocks']['main']['options']['enigma_encryption'] = array(
- 'title' => html::label($field_id, $this->gettext('supportencryption')),
- 'content' => $input->show(intval($this->rc->config->get('enigma_encryption'))),
- );
- }
-
- 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_attach_pubkey'])) {
- if (!$p['current']) {
- $p['blocks']['main']['content'] = true;
- return $p;
- }
-
- $field_id = 'rcmfd_enigma_attach_pubkey';
- $input = new html_checkbox(array(
- 'name' => '_enigma_attach_pubkey',
- 'id' => $field_id,
- 'value' => 1,
- ));
-
- $p['blocks']['main']['options']['enigma_attach_pubkey'] = array(
- 'title' => html::label($field_id, $this->gettext('attachpubkeydefault')),
- 'content' => $input->show($this->rc->config->get('enigma_attach_pubkey') ? 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;
- }
-
-
-
- function preferences_save($p)
- {
- 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_encryption' => (bool) rcube_utils::get_input_value('_enigma_encryption', rcube_utils::INPUT_POST),
- 'enigma_sign_all' => (bool) rcube_utils::get_input_value('_enigma_sign_all', rcube_utils::INPUT_POST),
- 'enigma_encrypt_all' => (bool) rcube_utils::get_input_value('_enigma_encrypt_all', rcube_utils::INPUT_POST),
- 'enigma_attach_pubkey' => (bool) rcube_utils::get_input_value('_enigma_attach_pubkey', rcube_utils::INPUT_POST),
- 'enigma_password_time' => intval(rcube_utils::get_input_value('_enigma_password_time', rcube_utils::INPUT_POST)),
- );
- }
-
- return $p;
- }
-
-
-
- function preferences_ui()
- {
- $this->load_ui();
-
- $this->ui->init();
- }
-
-
-
- function status_message($p)
- {
- $this->load_ui();
-
- return $this->ui->status_message($p);
- }
-
-
-
- function message_load($p)
- {
- $this->load_ui();
-
- return $this->ui->message_load($p);
- }
-
-
-
- function message_output($p)
- {
- $this->load_ui();
-
- return $this->ui->message_output($p);
- }
-
-
-
- function import_file()
- {
- $this->load_ui();
-
- $this->ui->import_file();
- }
-
-
-
- function password_handler()
- {
- $this->load_engine();
-
- $this->engine->password_handler();
- }
-
-
-
- function message_ready($p)
- {
- $this->load_ui();
-
- return $this->ui->message_ready($p);
- }
-
-
-
- function message_compose($p)
- {
- $this->load_ui();
-
- return $this->ui->message_compose($p);
- }
-
-
-
- function refresh($p)
- {
-
-
- $this->load_engine();
-
- return $p;
- }
- }
|