Added argument $strict to findDisplayEntity. When false (the default) it
authorindiri69 <indiri69@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sat, 24 Aug 2002 19:34:57 +0000 (19:34 +0000)
committerindiri69 <indiri69@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sat, 24 Aug 2002 19:34:57 +0000 (19:34 +0000)
assume 'text/plain', 'text/html', and 'text/message' are viewable.  When
true (strict mode), it will only treat the types passed as viewable.  This
means if you pass just 'text/html' in alt_order, then it will only return
those parts that are viewable 'text/html'.

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3447 7612ce4b-ef26-0410-bec9-ea0150e637f0

class/mime.class.php

index e6d9c3b..42c6762 100644 (file)
@@ -1212,62 +1212,77 @@ class message {
         }
     }
 
-    function findDisplayEntity($entity = array(), $alt_order = array('text/plain', 'text/html')) {
+    function findDisplayEntity($entity = array(), $alt_order = array('text/plain', 'text/html'), $strict=false) {
         $found = false;
-        $type = $this->type0.'/'.$this->type1;
-        if ($type == 'multipart/alternative') {
-            $msg = $this->findAlternativeEntity($alt_order);
-            if (count($msg->entities) == 0) {
-                $entity[] = $msg->entity_id;
-            } else {
-                $entity = $msg->findDisplayEntity($entity, $alt_order);
-            }
-            $found = true;
-        } else if ($type == 'multipart/related') {
-            $msgs = $this->findRelatedEntity();
-            foreach ($msgs as $msg) {
+        if ($this->type0 == 'multipart') {
+            if($this->type1 == 'alternative') {
+                $msg = $this->findAlternativeEntity($alt_order);
                 if (count($msg->entities) == 0) {
                     $entity[] = $msg->entity_id;
                 } else {
-                    $entity = $msg->findDisplayEntity($entity, $alt_order);
+                    $entity = $msg->findDisplayEntity($entity, $alt_order, $strict);
                 }
-            }
-            if (count($msgs) > 0) {
                 $found = true;
+            } else if ($this->type1 == 'related') { /* RFC 2387 */
+                $msgs = $this->findRelatedEntity();
+                foreach ($msgs as $msg) {
+                    if (count($msg->entities) == 0) {
+                        $entity[] = $msg->entity_id;
+                    } else {
+                        $entity = $msg->findDisplayEntity($entity, $alt_order, $strict);
+                    }
+                }
+                if (count($msgs) > 0) {
+                    $found = true;
+                }
+            } else { /* Treat as multipart/mixed */
+                foreach ($this->entities as $ent) {
+                    if(strtolower($ent->header->disposition->name) != 'attachment' &&
+                       ($ent->type0 != 'message' && $ent->type1 != 'rfc822'))
+                    {
+                        $entity = $ent->findDisplayEntity($entity, $alt_order, $strict);
+                        $found = true;
+                    }
+                }
             }
-        } else if (($this->type0 == 'text') &&
-                   (($this->type1 == 'plain') ||
-                    ($this->type1 == 'html')  ||
-                    ($this->type1 == 'message')) &&
-                   isset($this->entity_id)) {
-            if (count($this->entities) == 0) {
-                if (strtolower($this->header->disposition->name) != 'attachment') {
-                    $entity[] = $this->entity_id;
+        } else { /* If not multipart, then just compare with each entry from $alt_order */
+            $type = $this->type0.'/'.$this->type1;
+            foreach ($alt_order as $alt) {
+                if( ($alt == $type) && isset($this->entity_id) ) {
+                    if ( (count($this->entities) == 0) && 
+                         (strtolower($this->header->disposition->name) != 'attachment') )
+                    {
+                            $entity[] = $this->entity_id;
+                            $found = true;
+                    }
                 }
             }
         }
-        $i = 0;
-        if (!$found) {
+        if(!$found) {
             foreach ($this->entities as $ent) {
                 if((strtolower($ent->header->disposition->name) != 'attachment') &&
                    (($ent->type0 != 'message') && ($ent->type1 != 'rfc822'))) {
-                    $entity = $ent->findDisplayEntity($entity, $alt_order);
+                    $entity = $ent->findDisplayEntity($entity, $alt_order, $strict);
+                    $found = true;
+                }
+            }
+        }
+        if(!$strict && !$found) {
+            if ($this->type0 == 'text' &&
+                ($this->type1 == 'plain' ||
+                 $this->type1 == 'html'  ||
+                 $this->type1 == 'message') &&
+                isset($this->entity_id) )
+            {
+                if (count($this->entities) == 0) {
+                    if (strtolower($this->header->disposition->name) != 'attachment') {
+                        $entity[] = $this->entity_id;
+                    }
                 }
             }
         }
 
-        /* CAN THIS BE REMOVED? IF SO, DO IT!!! */
-        //while (isset($this->entities[$i]) && !$found &&
-        //        (strtolower($this->entities[$i]->header->disposition->name)
-        //         != 'attachment') &&
-        //        ($this->entities[$i]->type0 != 'message' &&
-        //         $this->entities[$i]->type1 != 'rfc822')
-        //     ) {
-        //    $entity = $this->entities[$i]->findDisplayEntity($entity, $alt_order);
-        //    ++$i;
-        //}
-
-        return ($entity);
+        return $entity;
     }
 
     function findAlternativeEntity($alt_order) {