- fputs ($imap_stream, "a001 FETCH $id BODY[$ent_id]\r\n");
- $topline = fgets ($imap_stream, 1024);
- $size = substr ($topline, strpos($topline, "{")+1);
- $size = substr ($size, 0, strpos($size, "}"));
- $read = fread ($imap_stream, $size);
- return $read;
+ fputs ($imap_stream, sqimap_session_id() . " FETCH $id BODY[$ent_id]\r\n");
+ $data = sqimap_read_data ($imap_stream, sqimap_session_id(), true, $response, $message);
+ $topline = array_shift($data);
+ while (! ereg('\\* [0-9]+ FETCH ', $topline) && $data)
+ $topline = array_shift($data);
+ $wholemessage = implode('', $data);
+
+ if (ereg('\\{([^\\}]*)\\}', $topline, $regs)) {
+ return substr($wholemessage, 0, $regs[1]);
+ }
+ else if (ereg('"([^"]*)"', $topline, $regs)) {
+ return $regs[1];
+ }
+
+ $str = "Body retrieval error. Please report this bug!\n" .
+ "Response: $response\n" .
+ "Message: $message\n" .
+ "FETCH line: $topline" .
+ "---------------\n$wholemessage";
+ foreach ($data as $d) {
+ $str .= htmlspecialchars($d) . "\n";
+ }
+ return $str;
+ }
+
+ function mime_print_body_lines ($imap_stream, $id, $ent_id, $encoding) {
+ // do a bit of error correction. If we couldn't find the entity id, just guess
+ // that it is the first one. That is usually the case anyway.
+ if (!$ent_id) $ent_id = 1;
+ $sid = sqimap_session_id();
+ // Don't kill the connection if the browser is over a dialup
+ // and it would take over 30 seconds to download it.
+ set_time_limit(0);
+
+ fputs ($imap_stream, "$sid FETCH $id BODY[$ent_id]\r\n");
+ $cnt = 0;
+ $continue = true;
+ $read = fgets ($imap_stream,4096);
+ // This could be bad -- if the section has sqimap_session_id() . ' OK'
+ // or similar, it will kill the download.
+ while (!ereg("^".$sid." (OK|BAD|NO)(.*)$", $read, $regs)) {
+ if (trim($read) == ')==') {
+ $read1 = $read;
+ $read = fgets ($imap_stream,4096);
+ if (ereg("^".$sid." (OK|BAD|NO)(.*)$", $read, $regs)) {
+ return;
+ } else {
+ echo decodeBody($read1, $encoding) .
+ decodeBody($read, $encoding);
+ }
+ } else if ($cnt) {
+ echo decodeBody($read, $encoding);
+ }
+ $read = fgets ($imap_stream,4096);
+ $cnt++;
+ }