diff options
author | alecpl <alec@alec.pl> | 2009-12-03 10:59:38 +0000 |
---|---|---|
committer | alecpl <alec@alec.pl> | 2009-12-03 10:59:38 +0000 |
commit | 35b01b64f5cc9fe59d67f4f5abf01087d5221c13 (patch) | |
tree | d3b82d4b8d53e19c8981083e78da2f0d1249f4c2 | |
parent | 047f32a63a7fbf086f32ac03ca00dc5ad93fcd3c (diff) |
- added feof() checks before fgets/fread
-rw-r--r-- | program/lib/imap.inc | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/program/lib/imap.inc b/program/lib/imap.inc index 964d12d99..409c2622b 100644 --- a/program/lib/imap.inc +++ b/program/lib/imap.inc @@ -234,7 +234,7 @@ function iil_ReadLine($fp, $size=1024) { $line = ''; if (!$fp) { - return $line; + return NULL; } if (!$size) { @@ -242,6 +242,10 @@ function iil_ReadLine($fp, $size=1024) { } do { + if (feof($fp)) { + return $line ? $line : NULL; + } + $buffer = fgets($fp, $size); if ($buffer === false) { @@ -264,6 +268,8 @@ function iil_MultLine($fp, $line, $escape=false) { $bytes = $a[2][0]; while (strlen($out) < $bytes) { $line = iil_ReadBytes($fp, $bytes); + if ($line === NULL) + break; $out .= $line; } @@ -276,7 +282,8 @@ function iil_ReadBytes($fp, $bytes) { global $my_prefs; $data = ''; $len = 0; - do { + while ($len < $bytes && !feof($fp)) + { $d = fread($fp, $bytes-$len); if (!empty($my_prefs['debug_mode'])) write_log('imap', 'S: '. $d); @@ -286,7 +293,7 @@ function iil_ReadBytes($fp, $bytes) { break; //nothing was read -> exit to avoid apache lockups } $len = $data_len; - } while ($len < $bytes); + }; return $data; } @@ -716,7 +723,8 @@ function iil_Connect($host, $user, $password, $options=null) { function iil_Close(&$conn) { if (iil_PutLine($conn->fp, "I LOGOUT")) { - fgets($conn->fp, 1024); + if (!feof($conn->fp)) + fgets($conn->fp, 1024); fclose($conn->fp); $conn->fp = false; } |