Aleksander Machniak
2016-03-30 007c9ddcb0c49733522688c4d2364d1a4ab9ec8e
plugins/enigma/lib/enigma_ui.php
@@ -459,6 +459,8 @@
     */
    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);
@@ -760,11 +762,13 @@
        $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';
@@ -778,12 +782,18 @@
                        $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';
@@ -794,10 +804,13 @@
        }
        // 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';
@@ -812,8 +825,9 @@
                    $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';
@@ -838,9 +852,6 @@
//            $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) {
@@ -944,16 +955,16 @@
                $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');
        }
@@ -999,6 +1010,27 @@
            $this->rc->output->show_message($msg, 'error');
        }
        // Check sign/ecrypt options for signed/encrypted drafts
        $this->rc->output->set_env('enigma_force_encrypt', !empty($engine->decryptions));
        $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;
            }
        }
    }
}