Reset $msg on each iteration, otherwise a message with eg no subject
[squirrelmail.git] / functions / imap_messages.php
index c321beb9240b47fa025c584ec2c23384100d5aef..5afd30303748093788828c281ad42c7d80e20386 100755 (executable)
@@ -534,11 +534,7 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $show_num=false,
     $messages = array();
     $read_list = array();
 
-    if (array_search('UID',$aFetchItems,true) !== false) {
-        $bUidFetch = false;
-    } else {
-        $bUidFetch = true;
-    }
+    $bUidFetch = ! in_array('UID', $aFetchItems, true);
 
     /* Get the small headers for each message in $msg_list */
     if ($show_num != '999999' && $show_num != '*' ) {
@@ -578,6 +574,7 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $show_num=false,
     $i = 0;
 
     foreach ($read_list as $r) {
+        $msg = array();
         // use unset because we do isset below
         $read = implode('',$r);
 
@@ -660,6 +657,7 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $show_num=false,
                 /* Now we can make a new header array with */
                 /* each element representing a headerline  */
                 $hdr = explode("\n" , $hdr);
+                $aReceived = array();
                 foreach ($hdr as $line) {
                     $pos = strpos($line, ':');
                     if ($pos > 0) {
@@ -682,16 +680,25 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $show_num=false,
                                     $type = substr($type, 0, $pos);
                                 }
                                 $type = explode("/", $type);
-                                if(!is_array($type)) {
+                                if(!is_array($type) || count($type) < 2) {
                                     $msg['TYPE0'] = 'text';
                                     $msg['TYPE1'] = 'plain';
+                                } else {
+                                    $msg['TYPE0'] = strtolower($type[0]);
+                                    $msg['TYPE1'] = strtolower($type[1]);
                                 }
                                 break;
+                            case 'received':
+                                $aReceived[] = $value;
+                                break;
                             default: break;
                             }
                         }
                     }
                 }
+                if (count($aReceived)) {
+                    $msg['RECEIVED'] = $aReceived;
+                }
                 break;
             default:
                 ++$i;