Force the addition of a file suffix to attachments that lack a filename (helps forwar...
[squirrelmail.git] / class / mime / Message.class.php
index ae03ecd48e09ec6dca7290751cf52686366a4fad..b6d0f221ecd593da2edfea57ed45c901540a4230 100644 (file)
@@ -5,7 +5,7 @@
  *
  * This file contains functions needed to handle mime messages.
  *
- * @copyright 2003-2009 The SquirrelMail Project Team
+ * @copyright 2003-2010 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
@@ -161,9 +161,9 @@ class Message {
                       $name = $header->getParameter('name');
                       if(!trim($name)) {
                           if (!trim( $header->id )) {
-                              $filename = 'untitled-[' . $this->entity_id . ']' ;
+                              $filename = 'untitled-[' . $this->entity_id . ']' . '.' . strtolower($header->type1);
                           } else {
-                              $filename = 'cid: ' . $header->id;
+                              $filename = 'cid: ' . $header->id . '.' . strtolower($header->type1);
                           }
                       } else {
                           $filename = $name;
@@ -178,9 +178,9 @@ class Message {
                   $filename = $header->getParameter('name');
                   if (!trim($filename)) {
                       if (!trim( $header->id )) {
-                          $filename = 'untitled-[' . $this->entity_id . ']' ;
+                          $filename = 'untitled-[' . $this->entity_id . ']' . '.' . strtolower($header->type1);
                       } else {
-                          $filename = 'cid: ' . $header->id;
+                          $filename = 'cid: ' . $header->id . '.' . strtolower($header->type1);
                       }
                   }
               }
@@ -987,12 +987,14 @@ class Message {
         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, $strict);
+                if ( ! is_null($msg) ) {
+                    if (count($msg->entities) == 0) {
+                        $entity[] = $msg->entity_id;
+                    } else {
+                        $entity = $msg->findDisplayEntity($entity, $alt_order, $strict);
+                    }
+                    $found = true;
                 }
-                $found = true;
             } else if ($this->type1 == 'related') { /* RFC 2387 */
                 $msgs = $this->findRelatedEntity();
                 foreach ($msgs as $msg) {
@@ -1057,19 +1059,19 @@ class Message {
 
     /**
      * @param array $alt_order
-     * @return array
+     * @return entity
      */
     function findAlternativeEntity($alt_order) {
         /* If we are dealing with alternative parts then we  */
         /* choose the best viewable message supported by SM. */
         $best_view = 0;
-        $entity = array();
+        $entity = null;
         foreach($this->entities as $ent) {
             $type = $ent->header->type0 . '/' . $ent->header->type1;
             if ($type == 'multipart/related') {
                 $type = $ent->header->getParameter('type');
-            // Mozilla bug. Mozilla does not provide the parameter type.
-            if (!$type) $type = 'text/html';
+                // Mozilla bug. Mozilla does not provide the parameter type.
+                if (!$type) $type = 'text/html';
             }
             $altCount = count($alt_order);
             for ($j = $best_view; $j < $altCount; ++$j) {