-/* returns a $message object for a particular entity id */
-function getEntity ($message, $ent_id) {
- return $message->getEntity($ent_id);
-}
-
-/*
- * figures out what entity to display and returns the $message object
- * for that entity.
- */
-function findDisplayEntity ($msg, $textOnly = true, $entity = array() ) {
- global $show_html_default;
-
- $found = false;
- if ($msg) {
- $type = $msg->type0.'/'.$msg->type1;
- if ( $type == 'multipart/alternative') {
- $msg = findAlternativeEntity($msg, $textOnly);
- if (count($msg->entities) == 0) {
- $entity[] = $msg->entity_id;
- } else {
- $found = true;
- $entity =findDisplayEntity($msg,$textOnly, $entity);
- }
- } else if ( $type == 'multipart/related') {
- $msgs = findRelatedEntity($msg);
- for ($i = 0; $i < count($msgs); $i++) {
- $msg = $msgs[$i];
- if (count($msg->entities) == 0) {
- $entity[] = $msg->entity_id;
- } else {
- $found = true;
- $entity =findDisplayEntity($msg,$textOnly, $entity);
- }
- }
- } else if ( count($entity) == 0 &&
- $msg->type0 == 'text' &&
- ( $msg->type1 == 'plain' ||
- $msg->type1 == 'html' ) &&
- isset($msg->entity_id) ) {
- if (count($msg->entities) == 0) {
- $entity[] = $msg->entity_id;
- }
- }
- $i = 0;
- while ( isset($msg->entities[$i]) && count($entity) == 0 && !$found ) {
- $entity = findDisplayEntity($msg->entities[$i], $textOnly, $entity);
- $i++;
- }
- }
- if ( !isset($entity[0]) ) {
- $entity[]="";
- }
- return( $entity );
-}