// Thrown if server denies the network connection.
const SERVER_CONNECT = 11;
+ // Thrown if server response times out.
+ const SERVER_TIMEOUT = 12;
+
/**
* Define a callback function used to log the exception. Will be passed
* a single parameter - a copy of this object.
feof($this->_stream)) {
$this->_temp['logout'] = true;
$this->logout();
- throw new Horde_Imap_Client_Exception('IMAP Server closed the connection unexpectedly.', Horde_Imap_Client_Exception::IMAP_DISCONNECT);
+ if ($this->_debug) {
+ fwrite($this->_debug, '[ERROR: IMAP server closed the connection.]' . "\n");
+ }
+ throw new Horde_Imap_Client_Exception('IMAP server closed the connection unexpectedly.', Horde_Imap_Client_Exception::IMAP_DISCONNECT);
}
$ret = '';
}
} else {
if (empty($this->_temp['buffer_in'])) {
- $this->_temp['buffer_in'] = fread($this->_stream, 8192);
+ if (!($in = fread($this->_stream, 8192))) {
+ if ($this->_debug) {
+ fwrite($this->_debug, '[ERROR: IMAP response timed out.]' . "\n");
+ }
+ throw new Horde_Imap_Client_Exception('IMAP response timed out.', Horde_Imap_Client_Exception::SERVER_TIMEOUT);
+ }
+ $this->_temp['buffer_in'] = $in;
}
$ptr = &$this->_temp['buffer_in'];
- if ($ptr) {
- $pos = strpos($ptr, "\n");
- if ($pos === false) {
- $ret = $ptr;
- $ptr = '';
- return $ret . $this->_readData();
- }
- $ret = substr($ptr, 0, $pos + 1);
- $ptr = substr($ptr, $pos + 1);
- }
+ $pos = strpos($ptr, "\n");
+ if ($pos === false) {
+ $ret = $ptr;
+ $ptr = '';
+ return $ret . $this->_readData();
+ }
+ $ret = substr($ptr, 0, $pos + 1);
+ $ptr = substr($ptr, $pos + 1);
}
if ($this->_debug) {