Aleksander Machniak
2016-01-26 c1a518910aedd6fc622a6d36aa8e3deac943a215
plugins/enigma/lib/enigma_ui.php
@@ -760,11 +760,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';
@@ -794,10 +796,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->signed_parts)) !== null
            && ($sig = $engine->signatures[$engine->signed_parts[$found]])
        ) {
            $attach_scripts = true;
            // show the message only once
            unset($engine->signatures[$engine->signed_parts[$part_id]]);
            // display status info
            $attrib['id'] = 'enigma-message';
@@ -838,9 +843,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) {
@@ -999,6 +1001,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;
            }
        }
    }
}