| | |
| | | */ |
| | | private function key_export() |
| | | { |
| | | $this->rc->request_security_check(rcube_utils::INPUT_GET); |
| | | |
| | | $keys = rcube_utils::get_input_value('_keys', rcube_utils::INPUT_GPC); |
| | | $engine = $this->enigma->load_engine(); |
| | | $list = $keys == '*' ? $engine->list_keys() : explode(',', $keys); |
| | |
| | | 'height' => 32 |
| | | ), 'toolbar'); |
| | | |
| | | $locks = (array) $this->rc->config->get('enigma_options_lock'); |
| | | $menu = new html_table(array('cols' => 2)); |
| | | $chbox = new html_checkbox(array('value' => 1)); |
| | | |
| | | $menu->add(null, html::label(array('for' => 'enigmasignopt'), |
| | | rcube::Q($this->enigma->gettext('signmsg')))); |
| | | $menu->add(null, $chbox->show($this->rc->config->get('enigma_sign_all') ? 1 : 0, |
| | | array('name' => '_enigma_sign', 'id' => 'enigmasignopt'))); |
| | | array( |
| | | 'name' => '_enigma_sign', |
| | | 'id' => 'enigmasignopt', |
| | | 'disabled' => in_array('sign', $locks), |
| | | ))); |
| | | |
| | | $menu->add(null, html::label(array('for' => 'enigmaencryptopt'), |
| | | rcube::Q($this->enigma->gettext('encryptmsg')))); |
| | | $menu->add(null, $chbox->show($this->rc->config->get('enigma_encrypt_all') ? 1 : 0, |
| | | array('name' => '_enigma_encrypt', 'id' => 'enigmaencryptopt'))); |
| | | array( |
| | | 'name' => '_enigma_encrypt', |
| | | 'id' => 'enigmaencryptopt', |
| | | 'disabled' => in_array('encrypt', $locks), |
| | | ))); |
| | | |
| | | $menu->add(null, html::label(array('for' => 'enigmaattachpubkeyopt'), |
| | | rcube::Q($this->enigma->gettext('attachpubkeymsg')))); |
| | | $menu->add(null, $chbox->show($this->rc->config->get('enigma_attach_pubkey') ? 1 : 0, |
| | | array( |
| | | 'name' => '_enigma_attachpubkey', |
| | | 'id' => 'enigmaattachpubkeyopt', |
| | | 'disabled' => in_array('pubkey', $locks), |
| | | ))); |
| | | |
| | | $menu = html::div(array('id' => 'enigmamenu', 'class' => 'popupmenu'), $menu->show()); |
| | | |
| | |
| | | $part_id = $p['part']->mime_id; |
| | | |
| | | // Decryption status |
| | | if (isset($engine->decryptions[$part_id])) { |
| | | if (($found = $this->find_part_id($part_id, $engine->decryptions)) !== null |
| | | && ($status = $engine->decryptions[$found]) |
| | | ) { |
| | | $attach_scripts = true; |
| | | |
| | | // get decryption status |
| | | $status = $engine->decryptions[$part_id]; |
| | | // show the message only once |
| | | unset($engine->decryptions[$found]); |
| | | |
| | | // display status info |
| | | $attrib['id'] = 'enigma-message'; |
| | |
| | | $this->enigma->gettext('decryptnokey'))); |
| | | } |
| | | else if ($code == enigma_error::BADPASS) { |
| | | $msg = rcube::Q($this->enigma->gettext('decryptbadpass')); |
| | | $missing = $status->getData('missing'); |
| | | $label = 'decrypt' . (!empty($missing) ? 'no' : 'bad') . 'pass'; |
| | | $msg = rcube::Q($this->enigma->gettext($label)); |
| | | $this->password_prompt($status); |
| | | } |
| | | else { |
| | | $msg = rcube::Q($this->enigma->gettext('decrypterror')); |
| | | } |
| | | } |
| | | else if ($status === enigma_engine::ENCRYPTED_PARTIALLY) { |
| | | $attrib['class'] = 'enigmawarning'; |
| | | $msg = rcube::Q($this->enigma->gettext('decryptpartial')); |
| | | } |
| | | else { |
| | | $attrib['class'] = 'enigmanotice'; |
| | |
| | | } |
| | | |
| | | // Signature verification status |
| | | if (isset($engine->signed_parts[$part_id]) |
| | | && ($sig = $engine->signatures[$engine->signed_parts[$part_id]]) |
| | | if (($found = $this->find_part_id($part_id, $engine->signatures)) !== null |
| | | && ($sig = $engine->signatures[$found]) |
| | | ) { |
| | | $attach_scripts = true; |
| | | |
| | | // show the message only once |
| | | unset($engine->signatures[$found]); |
| | | |
| | | // display status info |
| | | $attrib['id'] = 'enigma-message'; |
| | |
| | | $msg = rcube::Q($msg); |
| | | } |
| | | else if ($sig->valid) { |
| | | $attrib['class'] = 'enigmanotice'; |
| | | $msg = rcube::Q(str_replace('$sender', $sender, $this->enigma->gettext('sigvalid'))); |
| | | $attrib['class'] = $sig->partial ? 'enigmawarning' : 'enigmanotice'; |
| | | $label = 'sigvalid' . ($sig->partial ? 'partial' : ''); |
| | | $msg = rcube::Q(str_replace('$sender', $sender, $this->enigma->gettext($label))); |
| | | } |
| | | else { |
| | | $attrib['class'] = 'enigmawarning'; |
| | |
| | | // $msg .= '<br /><pre>'.$sig->body.'</pre>'; |
| | | |
| | | $p['prefix'] .= html::div($attrib, $msg); |
| | | |
| | | // Display each signature message only once |
| | | unset($engine->signatures[$engine->signed_parts[$part_id]]); |
| | | } |
| | | |
| | | if ($attach_scripts) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Handle message_ready hook (encryption/signing) |
| | | * Handle message_ready hook (encryption/signing/attach public key) |
| | | */ |
| | | function message_ready($p) |
| | | { |
| | | $savedraft = !empty($_POST['_draft']) && empty($_GET['_saveonly']); |
| | | $savedraft = !empty($_POST['_draft']) && empty($_GET['_saveonly']); |
| | | $sign_enable = (bool) rcube_utils::get_input_value('_enigma_sign', rcube_utils::INPUT_POST); |
| | | $encrypt_enable = (bool) rcube_utils::get_input_value('_enigma_encrypt', rcube_utils::INPUT_POST); |
| | | $pubkey_enable = (bool) rcube_utils::get_input_value('_enigma_attachpubkey', rcube_utils::INPUT_POST); |
| | | $locks = (array) $this->rc->config->get('enigma_options_lock'); |
| | | |
| | | if (!$savedraft && rcube_utils::get_input_value('_enigma_sign', rcube_utils::INPUT_POST)) { |
| | | if (in_array('sign', $locks)) { |
| | | $sign_enable = (bool) $this->rc->config->get('enigma_sign_all'); |
| | | } |
| | | if (in_array('encrypt', $locks)) { |
| | | $encrypt_enable = (bool) $this->rc->config->get('enigma_encrypt_all'); |
| | | } |
| | | if (in_array('pubkey', $locks)) { |
| | | $pubkey_enable = (bool) $this->rc->config->get('enigma_attach_pubkey'); |
| | | } |
| | | |
| | | if (!$savedraft && $pubkey_enable) { |
| | | $this->enigma->load_engine(); |
| | | $this->enigma->engine->attach_public_key($p['message']); |
| | | } |
| | | |
| | | if (!$savedraft && $sign_enable) { |
| | | $this->enigma->load_engine(); |
| | | $status = $this->enigma->engine->sign_message($p['message']); |
| | | $mode = 'sign'; |
| | | } |
| | | |
| | | if ((!$status instanceof enigma_error) && rcube_utils::get_input_value('_enigma_encrypt', rcube_utils::INPUT_POST)) { |
| | | if ((!$status instanceof enigma_error) && $encrypt_enable) { |
| | | $this->enigma->load_engine(); |
| | | $status = $this->enigma->engine->encrypt_message($p['message'], null, $savedraft); |
| | | $mode = 'encrypt'; |
| | |
| | | $msg = 'enigma.' . $mode . 'nokey'; |
| | | } |
| | | else if ($code == enigma_error::BADPASS) { |
| | | $msg = 'enigma.' . $mode . 'badpass'; |
| | | $type = 'warning'; |
| | | |
| | | $this->password_prompt($status); |
| | | } |
| | | else { |
| | | $msg = 'enigma.' . $mode . 'error'; |
| | | } |
| | | |
| | | $this->rc->output->show_message($msg, $type ?: 'error', $vars); |
| | | if ($msg) { |
| | | $this->rc->output->show_message($msg, $type ?: 'error', $vars); |
| | | } |
| | | |
| | | $this->rc->output->send('iframe'); |
| | | } |
| | | |
| | | return $p; |
| | | } |
| | | |
| | | /** |
| | | /** |
| | | * Handler for message_compose_body hook |
| | | * Display error when the message cannot be encrypted |
| | | * and provide a way to try again with a password. |
| | |
| | | } |
| | | |
| | | $engine = $this->enigma->engine; |
| | | $locks = (array) $this->rc->config->get('enigma_options_lock'); |
| | | |
| | | // Decryption status |
| | | foreach ($engine->decryptions as $status) { |
| | |
| | | $this->rc->output->show_message($msg, 'error'); |
| | | } |
| | | |
| | | // Check sign/ecrypt options for signed/encrypted drafts |
| | | if (!in_array('encrypt', $locks)) { |
| | | $this->rc->output->set_env('enigma_force_encrypt', !empty($engine->decryptions)); |
| | | } |
| | | if (!in_array('sign', $locks)) { |
| | | $this->rc->output->set_env('enigma_force_sign', !empty($engine->signatures)); |
| | | } |
| | | |
| | | return $p; |
| | | } |
| | | |
| | | /** |
| | | * Check if the part or its parent exists in the array |
| | | * of decryptions/signatures. Returns found ID. |
| | | */ |
| | | private function find_part_id($part_id, $data) |
| | | { |
| | | $ids = explode('.', $part_id); |
| | | $i = 0; |
| | | $count = count($ids); |
| | | |
| | | while ($i < $count && strlen($part = implode('.', array_slice($ids, 0, ++$i)))) { |
| | | if (array_key_exists($part, $data)) { |
| | | return $part; |
| | | } |
| | | } |
| | | } |
| | | } |