Enigma: Fix bug where signature/decryption info wasn't displayed for some messages

pull/322/head
Aleksander Machniak 9 years ago
parent 96d7f79a38
commit c1a518910a

@ -756,21 +756,17 @@ class enigma_ui
return $p;
}
$engine = $this->enigma->engine;
$part_id = $p['part']->mime_id;
$parent_id = preg_replace('/\.[0-9]+$/', '', $part_id);
$engine = $this->enigma->engine;
$part_id = $p['part']->mime_id;
// Decryption status
if (($status = $engine->decryptions[$part_id])
|| ($parent_id !== '' && ($status = $engine->decryptions[$parent_id]))
if (($found = $this->find_part_id($part_id, $engine->decryptions)) !== null
&& ($status = $engine->decryptions[$found])
) {
$attach_scripts = true;
// show the message only once
unset($engine->decryptions[$part_id]);
if ($parent_id !== '') {
unset($engine->decryptions[$parent_id]);
}
unset($engine->decryptions[$found]);
// display status info
$attrib['id'] = 'enigma-message';
@ -800,11 +796,14 @@ class enigma_ui
}
// 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';
@ -844,9 +843,6 @@ class enigma_ui
// $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) {
@ -1011,4 +1007,21 @@ class enigma_ui
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;
}
}
}
}

Loading…
Cancel
Save