From e79bed1beca14cc40a0743eee920d1003d6a3e6e Mon Sep 17 00:00:00 2001 From: lkehresman Date: Thu, 22 Jun 2000 20:01:27 +0000 Subject: [PATCH] added debugging information and fixed a minor bug -- not reading in enough characters from the IMAP server for really large responses. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@553 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/mime.php | 53 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/functions/mime.php b/functions/mime.php index 379e77f5..e46b0e92 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -6,6 +6,7 @@ ** **/ + $debug_mime = false; $mime_php = true; if (!isset($i18n_php)) @@ -53,32 +54,36 @@ fully parsed into the standard "message" object format. **/ function mime_structure ($imap_stream, $header) { + global $debug_mime; sqimap_messages_flag ($imap_stream, $header->id, $header->id, "Seen"); $id = $header->id; fputs ($imap_stream, "a001 FETCH $id BODYSTRUCTURE\r\n"); - $read = sqimap_read_data ($imap_stream, "a001", true, $a, $b); - $read = strtolower($read[0]); + $read = fgets ($imap_stream, 10000); + $read = strtolower($read); - //echo $read."

"; + if ($debug_mime) echo "$read

"; // isolate the body structure and remove beginning and end parenthesis $read = trim(substr ($read, strpos($read, "bodystructure") + 13)); $read = trim(substr ($read, 0, -2)); $read = trim(substr ($read, 1)); + if ($debug_mime) echo "$read

"; + $msg = mime_parse_structure ($read); $msg->header = $header; return $msg; } function mime_parse_structure ($structure, $ent_id) { - //echo "START: mime_parse_structure()
"; + global $debug_mime; + if ($debug_mime) echo "START: mime_parse_structure()
"; $msg = new message(); if (substr($structure, 0, 1) == "(") { $ent_id = mime_new_element_level($ent_id); $start = $end = -1; do { - //echo "Found entity...
"; + if ($debug_mime) echo "Found entity...
"; $start = $end+1; $end = mime_match_parenthesis ($start, $structure); @@ -89,14 +94,14 @@ } while (substr($structure, $end+1, 1) == "("); } else { // parse the elements - //echo "
$structure
"; + if ($debug_mime) echo "
$structure
"; $msg->header = new msg_header(); $msg->header = mime_get_element (&$structure, $header); $msg->header->entity_id = $ent_id; - //echo "
"; + if ($debug_mime) echo "
"; } return $msg; - //echo "  END: mime_parse_structure()
"; + if ($debug_mime) echo "  END: mime_parse_structure()
"; } // Increments the element ID. An element id can look like any of @@ -129,6 +134,7 @@ } function mime_get_element (&$structure, $header) { + global $debug_mime; $elem_num = 1; while (strlen($structure) > 0) { @@ -165,30 +171,30 @@ } $structure = substr($structure, strlen($text)); } - //echo "$elem_num : $text
"; + if ($debug_mime) echo "$elem_num : $text
"; // This is where all the text parts get put into the header switch ($elem_num) { case 1: $header->type0 = $text; - //echo "type0 = $text
"; + if ($debug_mime) echo "type0 = $text
"; break; case 2: $header->type1 = $text; - //echo "type1 = $text
"; + if ($debug_mime) echo "type1 = $text
"; break; case 6: $header->encoding = $text; - //echo "encoding = $text
"; + if ($debug_mime) echo "encoding = $text
"; break; case 7: $header->size = $text; - //echo "size = $text
"; + if ($debug_mime) echo "size = $text
"; break; default: if ($header->type0 == "text" && $elem_num == 8) { $header->num_lines = $text; - //echo "num_lines = $text
"; + if ($debug_mime) echo "num_lines = $text
"; } break; } @@ -198,7 +204,7 @@ // loop through the additional properties and put those in the various headers for ($i=0; $i < count($properties); $i++) { $header->{$properties[$i]["name"]} = $properties[$i]["value"]; - //echo "".$properties[$i]["name"]." = " . $properties[$i]["value"] . "
"; + if ($debug_mime) echo "".$properties[$i]["name"]." = " . $properties[$i]["value"] . "
"; } return $header; } @@ -217,6 +223,7 @@ // $props[0]["name"] = "filename"; // $props[0]["value"] = "luke.tar.gz"; function mime_get_props ($props, $structure) { + global $debug_mime; while (strlen($structure) > 0) { $structure = trim($structure); $char = substr($structure, 0, 1); @@ -289,17 +296,11 @@ if (!$ent_id) $ent_id = 1; fputs ($imap_stream, "a001 FETCH $id BODY[$ent_id]\r\n"); - $read = sqimap_read_data ($imap_stream, "a001", true, $a, $b); - for ($i=1; $i < count($read)-1; $i++) { - // This fixes a bug in UW. UW doesn't return what would normall be - // expected from the BODY fetch command. It has an extra line at the - // end. So if the second from the last line is a ), then remove it. - if (trim($read[$i]) == ")" && $i == count($read)-2) { - continue; - } - $text .= $read[$i]; - } - return $text; + $topline = fgets ($imap_stream, 1024); + $size = substr ($topline, strpos($topline, "{")+1); + $size = substr ($size, 0, strpos($size, "}")); + $read = fread ($imap_stream, $size); + return $read; } /* -[ END MIME DECODING ]----------------------------------------------------------- */ -- 2.25.1