$id = $header->id;
fputs ($imap_stream, "a001 FETCH $id BODYSTRUCTURE\r\n");
$read = fgets ($imap_stream, 10000);
- $endline = fgets($imap_stream, 1024);
- $read = strtolower($read);
+ $response = substr($read, 0, 4);
+ while ($response != "a001") {
+ $bodystructure = $read;
+ $read = fgets ($imap_stream, 10000);
+ $response = substr($read, 0, 4);
+ }
+ $read = strtolower($bodystructure);
if ($debug_mime) echo "<tt>$read</tt><br><br>";
// isolate the body structure and remove beginning and end parenthesis
$replace = base64_decode($res[3]);
} else {
$replace = ereg_replace("_", " ", $res[3]);
+ // Convert lowercase Quoted Printable to uppercase for
+ // quoted_printable_decode to understand it.
+ while (ereg("(=([0-9][a-f])|([a-f][0-9]))", $replace, $res)) {
+ $replace = str_replace($res[1], strtoupper($res[1]), $replace);
+ }
$replace = quoted_printable_decode($replace);
}