mime_fetch_body reworked to fix a bug I found on my system. It also now
[squirrelmail.git] / functions / mime.php
index 13a453a9ef89983746d790814344a98011d778c9..cab32d51ce4b147c194e4b686ee3934e3f98ad51 100644 (file)
       if (!$ent_id) $ent_id = 1;
 
       fputs ($imap_stream, "a001 FETCH $id BODY[$ent_id]\r\n");
-      $topline = fgets ($imap_stream, 1024);
+      $data = sqimap_read_data ($imap_stream, 'a001', true, $response, $message);
+      $topline = array_shift($data);
+      while (! ereg('\* [0-9]+ FETCH ', $topline) && data)
+          $topline = array_shift($data);
+      while ($data)
+          $wholemessage .= array_shift($data);
+
       if (ereg('\{([^\}]*)\}', $topline, $regs)) {
-         return fread ($imap_stream, $regs[1]);
+         return substr($wholemessage, 0, $regs[1]);
       }
       else if (ereg('"([^"]*)"', $topline, $regs)) {
          return $regs[1];
       }
+      
+      $str = "Body retrival error.  Please report this bug!\n";
+      $str .= "Response:  $response\n";
+      $str .= "Message:  $message\n";
+      $str .= "FETCH line:  $topline";
+      $str .= "---------------\n$wholemessage";
+      foreach ($data as $d)
+      {
+          $str .= htmlspecialchars($d) . "\n";
+      }
+      return $str;
+      
       return "Body retrival error, please report this bug!\n\nTop line is \"$topline\"\n";
    }