浏览代码

mime_fetch_body reworked to fix a bug I found on my system. It also now
uses imap_read_data() instead of reading data directly.

Tyler Akins 24 年之前
父节点
当前提交
5fe67cc2db
共有 1 个文件被更改,包括 20 次插入2 次删除
  1. 20 2
      functions/mime.php

+ 20 - 2
functions/mime.php

@@ -362,13 +362,31 @@
       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";
    }