Kyle Francis
2016-03-30 a9d399155d205ae41015d7d205c6dacd7ecfc0d2
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);
@@ -780,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';
@@ -796,13 +804,13 @@
        }
        // Signature verification status
        if (($found = $this->find_part_id($part_id, $engine->signed_parts)) !== null
            && ($sig = $engine->signatures[$engine->signed_parts[$found]])
        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[$engine->signed_parts[$part_id]]);
            unset($engine->signatures[$found]);
            // display status info
            $attrib['id'] = 'enigma-message';
@@ -817,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';
@@ -920,11 +929,15 @@
    }
    /**
     * 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']);
        if (!$savedraft && rcube_utils::get_input_value('_enigma_attachpubkey', rcube_utils::INPUT_POST)) {
            $p = $this->attach_public($p);
        }
        if (!$savedraft && rcube_utils::get_input_value('_enigma_sign', rcube_utils::INPUT_POST)) {
            $this->enigma->load_engine();
@@ -946,16 +959,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');
        }
@@ -963,6 +976,24 @@
    }
    /**
     * Add sender's public key (PGP).
     */
    function attach_public($p)
    {
        // get sender's PGP pubkey for attachment
        $this->enigma->load_engine();
        $key = $this->enigma->engine->list_keys($p['message']->headers()['From']);
        $keyID = $key[0]->subkeys[0]->get_short_id();
        $pubkey_armor = $this->enigma->engine->get_gpg_pubkey_for_attach($p['message']->headers()['From']);
        if(!$pubkey_armor instanceof enigma_error) {
            $p['message']->addAttachment($pubkey_armor, 'application/pgp-keys', "0x$keyID.asc", false);
        }
        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.