From: Michael M Slusarz Date: Fri, 29 May 2009 02:35:03 +0000 (-0600) Subject: Fix usage of fgets() for very long lines. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=e47fea287ba5a7e2b0e439bb27fc73f050314ceb;p=horde.git Fix usage of fgets() for very long lines. e.g. the mailbox UID list with 50,000+ messages. --- diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Socket.php b/framework/Imap_Client/lib/Horde/Imap/Client/Socket.php index 45bb3a68e..058d90552 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Socket.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Socket.php @@ -3209,10 +3209,20 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base throw new Horde_Imap_Client_Exception('IMAP server closed the connection unexpectedly.', Horde_Imap_Client_Exception::IMAP_DISCONNECT); } + $data = ''; + if (is_null($len)) { - $data = fgets($this->_stream); + do { + /* Can't do a straight fgets() because extremely large lines + * will result in read errors. */ + if ($tmp = fgets($this->_stream, 8192)) { + $data .= $tmp; + if (!isset($tmp[8191]) || ($tmp[8191] == "\n")) { + break; + } + } + } while ($tmp !== false); } else { - $data = ''; while ($len && ($in = fread($this->_stream, min($len, 8192)))) { $data .= $in; $in_len = strlen($in);