return "Body retrival error, please report this bug!\n\nTop line is \"$topline\"\n";
}
+ 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;
+
+ fputs ($imap_stream, "a001 FETCH $id BODY[$ent_id]\r\n");
+ $cnt = 0;
+ $continue = true;
+ $read = fgets ($imap_stream,4096);
+ while (!ereg("^a001 (OK|BAD|NO)(.*)$", $read, $regs)) {
+ if (trim($read) == ")==") {
+ $read1 = $read;
+ $read = fgets ($imap_stream,4096);
+ if (ereg("^a001 (OK|BAD|NO)(.*)$", $read, $regs)) {
+ return;
+ } else {
+ echo decodeBody($read1, $encoding);
+ echo decodeBody($read, $encoding);
+ }
+ } else if ($cnt) {
+ echo decodeBody($read, $encoding);
+ }
+ $read = fgets ($imap_stream,4096);
+ $cnt++;
+ }
+ }
+
/* -[ END MIME DECODING ]----------------------------------------------------------- */
$message = getEntity($message, $passed_ent_id);
$header = $message->header;
- $body = mime_fetch_body($imapConnection, $passed_id, $passed_ent_id);
$charset = $header->charset;
$type0 = $header->type0;
if ($absolute_dl == "true") {
switch($type0) {
case "text":
+ $body = mime_fetch_body($imapConnection, $passed_id, $passed_ent_id);
$body = decodeBody($body, $header->encoding);
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-type: application/octet-stream; name=\"$filename\"");
echo trim($body);
break;
default:
- $body = decodeBody($body, $header->encoding);
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-type: application/octet-stream; name=\"$filename\"");
- echo $body;
+ mime_print_body_lines ($imapConnection, $passed_id, $passed_ent_id, $header->encoding);
break;
}
} else {
switch ($type0) {
case "text":
- if ($type1 == "text" || $type1 == "html") {
- $body = decodeBody($body, $header->encoding);
- include("../functions/page_header.php");
- viewText($color, $body, $passed_id, $passed_ent_id, $mailbox, $type1, $wrap_at);
+ if ($type1 == "plain" || $type1 == "html") {
+ $body = mime_fetch_body($imapConnection, $passed_id, $passed_ent_id);
+ $body = decodeBody($body, $header->encoding);
+ include("../functions/page_header.php");
+ viewText($color, $body, $passed_id, $passed_ent_id, $mailbox, $type1, $wrap_at);
} else {
- $body = decodeBody($body, $header->encoding);
- header("Content-type: $type0/$type1; name=\"$filename\"");
- header("Content-Disposition: attachment; filename=\"$filename\"");
- echo $body;
- }
- break;
+ $body = mime_fetch_body($imapConnection, $passed_id, $passed_ent_id);
+ $body = decodeBody($body, $header->encoding);
+ header("Content-type: $type0/$type1; name=\"$filename\"");
+ header("Content-Disposition: attachment; filename=\"$filename\"");
+ echo $body;
+ }
+ break;
case "message":
+ $body = mime_fetch_body($imapConnection, $passed_id, $passed_ent_id);
$body = decodeBody($body, $header->encoding);
include("../functions/page_header.php");
viewText($color, $body, $passed_id, $passed_ent_id, $mailbox, $type1, $wrap_at);
break;
default:
- $body = decodeBody($body, $header->encoding);
header("Content-type: $type0/$type1; name=\"$filename\"");
header("Content-Disposition: attachment; filename=\"$filename\"");
- echo $body;
+ mime_print_body_lines ($imapConnection, $passed_id, $passed_ent_id, $header->encoding);
break;
}
}