From c1a518910aedd6fc622a6d36aa8e3deac943a215 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Tue, 26 Jan 2016 13:53:36 +0100 Subject: [PATCH] Enigma: Fix bug where signature/decryption info wasn't displayed for some messages --- plugins/enigma/lib/enigma_ui.php | 41 +++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/plugins/enigma/lib/enigma_ui.php b/plugins/enigma/lib/enigma_ui.php index e32dee20f..372adabfd 100644 --- a/plugins/enigma/lib/enigma_ui.php +++ b/plugins/enigma/lib/enigma_ui.php @@ -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 .= '
'.$sig->body.'
'; $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; + } + } + } }