Fixed bug I noticed when ONLY an attachment is sent (no text message), it
[squirrelmail.git] / functions / imap_messages.php
index c82e7a97167389419679946b56d2823cf7853368..32ab26e99fe74f5858638f50673308ff25d1dc1d 100755 (executable)
@@ -5,7 +5,7 @@
     **  This implements functions that manipulate messages 
     **/
 
-   if (!$mime_php) include "../functions/mime.php";
+   if (!isset($mime_php)) include "../functions/mime.php";
 
    /******************************************************************************
     **  Copies specified messages to specified folder
@@ -45,7 +45,8 @@
    }
         
    function sqimap_get_small_header ($imap_stream, $id, $sent) {
-      fputs ($imap_stream, "a001 FETCH $id BODY.PEEK[HEADER.FIELDS (Date To From Subject Message-Id X-Priority)]\r\n");
+
+      fputs ($imap_stream, "a001 FETCH $id BODY.PEEK[HEADER.FIELDS (Date To From Cc Subject Message-Id X-Priority)]\r\n");
       $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
 
       $subject = _("(no subject)");
@@ -65,6 +66,8 @@
             $priority = trim(substr($read[$i], 11));
          } else if (eregi ("^message-id:", $read[$i])) {
             $messageid = trim(substr($read[$i], 11));
+         } else if (eregi ("^cc:", $read[$i])) {
+            $cc = substr($read[$i], 3);
          } else if (eregi ("^date:", $read[$i])) {
             $date = substr($read[$i], 5);
          } else if (eregi ("^subject:", $read[$i])) {
       if ($sent == true)
          $header->from = $to;
       else   
-        $header->from = $from;
+         $header->from = $from;
 
       $header->date = $date;
       $header->subject = $subject;
       $header->to = $to;
       $header->priority = $priority;
       $header->message_id = $messageid;
+      $header->cc = $cc;
 
       return $header;
    }
     **  the documentation folder for more information about this array.
     ******************************************************************************/
    function sqimap_get_message ($imap_stream, $id, $mailbox) {
-      
       $header = sqimap_get_message_header($imap_stream, $id, $mailbox);
       $msg = sqimap_get_message_body($imap_stream, &$header);
       return $msg;
     **  Queries the IMAP server and gets all header information.
     ******************************************************************************/
    function sqimap_get_header ($imap_stream, $read) {
+      global $where, $what;
+
       $hdr = new msg_header();
       $i = 0;
       // Set up some defaults
             $hdr->subject = trim(substr($read[$i], 8, strlen($read[$i]) - 9));
             if (strlen(Chop($hdr->subject)) == 0)
                $hdr->subject = _("(no subject)");
+
+            if ($where == "SUBJECT") {
+               $hdr->subject = eregi_replace($what, "<b>\\0</b>", $hdr->subject);
+            }
             $i++;
          }
          /** CC **/
     ******************************************************************************/
    function sqimap_get_message_body ($imap_stream, &$header) {
       $id = $header->id;
-      //fputs ($imap_stream, "a001 FETCH $id:$id BODY[TEXT]\r\n");
-      //$read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
-       
-      $i = 0;
-      $j = 0;
-      while ($i < count($read)-1) {
-         if ( ($i != 0) ) {
-            $body[$j] = $read[$i];
-            $j++;
-         }
-         $i++;
-      }
-      return decodeMime($body, &$header);
+      return decodeMime($imap_stream, $body, &$header);
    }