/** * Logout from the IMAP server (see RFC 3501 [6.1.3]). */ public function logout() { if ($this->_isAuthenticated && $this->_connection->connected) { $this->_logout(); $this->_connection->close(); } $this->_connection = $this->_selected = null; $this->_isAuthenticated = false; $this->_mode = 0; }
/** */ protected function _connect($host, $port, $timeout, $secure, $retries = 0) { if ($retries || !$this->_params['debug']->debug) { $timer = null; } else { $url = new Horde_Imap_Client_Url(); $url->hostspec = $host; $url->port = $port; $url->protocol = $this->_protocol; $this->_params['debug']->info(sprintf('Connection to: %s', strval($url))); $timer = new Horde_Support_Timer(); $timer->push(); } parent::_connect($host, $port, $timeout, $secure, $retries); if ($timer) { $this->_params['debug']->info(sprintf('Server connection took %s seconds.', round($timer->pop(), 4))); } }
/** */ protected function _connect($host, $port, $timeout, $secure, $context, $retries = 0) { if ($retries || !$this->_params['debug']->debug) { $timer = null; } else { $url = $this->_protocol == 'imap' ? new Horde_Imap_Client_Url_Imap() : new Horde_Imap_Client_Url_Pop3(); $url->host = $host; $url->port = $port; $this->_params['debug']->info(sprintf('Connection to: %s', strval($url))); $timer = new Horde_Support_Timer(); $timer->push(); } try { parent::_connect($host, $port, $timeout, $secure, $context, $retries); } catch (Horde\Socket\Client\Exception $e) { $this->_params['debug']->info(sprintf('Connection failed: %s', $e->getMessage())); throw $e; } if ($timer) { $this->_params['debug']->info(sprintf('Server connection took %s seconds.', round($timer->pop(), 4))); } }
/** * Used to figure out which Sieve server the script will be run * on, and then open a GSSAPI authenticated socket to said server. * * @param string $username The username. * @param string $password The password. * @param string $hostspec The hostspec. * * @return TODO * @throws Ingo_Exception */ public function sivtestSocket($username, $password, $hostspec) { $command = ''; $error_return = null; if (Horde_String::lower($this->_params['logintype']) == 'gssapi' && isset($_SERVER['KRB5CCNAME'])) { $command .= 'KRB5CCNAME=' . $_SERVER['KRB5CCNAME'] . ' '; } $domain_socket = 'unix://' . $this->_params['socket']; $command .= $this->_params['command'] . ' -m ' . $this->_params['logintype'] . ' -u ' . $username . ' -a ' . $username . ' -w ' . $password . ' -p ' . $this->_params['port'] . ' -X ' . $this->_params['socket'] . ' ' . $hostspec; $conn_attempts = 0; while ($conn_attempts++ < 4) { $attempts = 0; if (!file_exists($this->_params['socket'])) { exec($command . ' > /dev/null 2>&1'); sleep(1); while (!file_exists($this->_params['socket'])) { usleep(200000); if ($attempts++ > 5) { $error_return = _("No socket after 10 seconds of trying"); continue 2; } } } try { $socket = new \Horde\Socket\Client($domain_socket, 0, 30); } catch (Horde_Exception $error_return) { break; } // We failed, break this connection. unlink($this->_params['socket']); } if ($error_return) { throw new Ingo_Exception($error_return); } try { $status = $socket->getStatus(); if ($status['eof']) { throw new Ingo_Exception(_("Failed to write to socket: (connection lost!)")); } $socket->write("CAPABILITY\r\n"); } catch (Horde_Exception $e) { throw new Ingo_Exception(sprintf(_("Failed to write to socket:"), $e->getMessage())); } try { $result = rtrim($socket->gets(), "\r\n"); } catch (Horde_Exception $e) { throw new Ingo_Exception(sprintf(_("Failed to read from socket:"), $e->getMessage())); } $socket->close(); if (preg_match('|^bye \\(referral "(sieve://)?([^"]+)|i', $result, $matches)) { $this->sivtestSocket($username, $password, $matches[2]); } else { exec($command . ' > /dev/null 2>&1'); sleep(1); } }