From e47fea287ba5a7e2b0e439bb27fc73f050314ceb Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 28 May 2009 20:35:03 -0600 Subject: [PATCH] Fix usage of fgets() for very long lines. e.g. the mailbox UID list with 50,000+ messages. --- framework/Imap_Client/lib/Horde/Imap/Client/Socket.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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); -- 2.11.0