/** * Connect to an IMAP server * * @param string Host to connect * @param string Username for IMAP account * @param string Password for IMAP account * @param number Port to connect to * @param string SSL schema (either ssl or tls) or null if plain connection * @return boolean TRUE on success, FALSE on failure * @access public */ function connect($host, $user, $pass, $port = 143, $use_ssl = null) { global $ICL_SSL, $ICL_PORT, $IMAP_USE_INTERNAL_DATE; // check for Open-SSL support in PHP build if ($use_ssl && extension_loaded('openssl')) { $ICL_SSL = $use_ssl == 'imaps' ? 'ssl' : $use_ssl; } else { if ($use_ssl) { raise_error(array('code' => 403, 'type' => 'imap', 'file' => __FILE__, 'message' => 'Open SSL not available;'), TRUE, FALSE); $port = 143; } } $ICL_PORT = $port; $IMAP_USE_INTERNAL_DATE = false; $attempt = 0; do { $data = rcmail::get_instance()->plugins->exec_hook('imap_connect', array('host' => $host, 'user' => $user, 'attempt' => ++$attempt)); if (!empty($data['pass'])) { $pass = $data['pass']; } $this->conn = iil_Connect($data['host'], $data['user'], $pass, $this->options); } while (!$this->conn && $data['retry']); $this->host = $data['host']; $this->user = $data['user']; $this->pass = $pass; $this->port = $port; $this->ssl = $use_ssl; // print trace messages if ($this->conn && $this->debug_level & 8) { console($this->conn->message); } else { if (!$this->conn && $GLOBALS['iil_error']) { $this->error_code = $GLOBALS['iil_errornum']; raise_error(array('code' => 403, 'type' => 'imap', 'message' => $GLOBALS['iil_error']), TRUE, FALSE); } } // get server properties if ($this->conn) { if (!empty($this->conn->rootdir)) { $this->set_rootdir($this->conn->rootdir); $this->root_ns = preg_replace('/[.\\/]$/', '', $this->conn->rootdir); } if (empty($this->delimiter)) { $this->get_hierarchy_delimiter(); } } return $this->conn ? TRUE : FALSE; }
/** * Connect to an IMAP server * * @param string Host to connect * @param string Username for IMAP account * @param string Password for IMAP account * @param number Port to connect to * @param string SSL schema (either ssl or tls) or null if plain connection * @return boolean TRUE on success, FALSE on failure * @access public */ function connect($host, $user, $pass, $port = 143, $use_ssl = null) { global $ICL_SSL, $ICL_PORT, $IMAP_USE_INTERNAL_DATE; // check for Open-SSL support in PHP build if ($use_ssl && in_array('openssl', get_loaded_extensions())) { $ICL_SSL = $use_ssl == 'imaps' ? 'ssl' : $use_ssl; } else { if ($use_ssl) { raise_error(array('code' => 403, 'type' => 'imap', 'file' => __FILE__, 'message' => 'Open SSL not available;'), TRUE, FALSE); $port = 143; } } $ICL_PORT = $port; $IMAP_USE_INTERNAL_DATE = false; $this->conn = iil_Connect($host, $user, $pass, $this->options); $this->host = $host; $this->user = $user; $this->pass = $pass; $this->port = $port; $this->ssl = $use_ssl; // print trace mesages if ($this->conn && $this->debug_level & 8) { console($this->conn->message); } else { if (!$this->conn && $GLOBALS['iil_error']) { $this->error_code = $GLOBALS['iil_errornum']; raise_error(array('code' => 403, 'type' => 'imap', 'message' => $GLOBALS['iil_error']), TRUE, FALSE); } } // get server properties if ($this->conn) { if (!empty($this->conn->delimiter)) { $this->delimiter = $this->conn->delimiter; } if (!empty($this->conn->rootdir)) { $this->set_rootdir($this->conn->rootdir); $this->root_ns = ereg_replace('[\\.\\/]$', '', $this->conn->rootdir); } } return $this->conn ? TRUE : FALSE; }