Example #1
0
 /**
  * Create the backend driver.
  *
  * @return mixed The backend driver.
  */
 public function createBackend()
 {
     $config = $this->getParams();
     $client = new rcube_imap_generic();
     if (isset($config['debug'])) {
         if ($config['debug'] == 'STDOUT') {
             $client->setDebug(true);
         } else {
             $this->_debug_log = fopen($config['debug'], 'a');
             $client->setDebug(true, array($this, 'debugLog'));
         }
     }
     $client->connect($config['host'], $config['username'], $config['password'], array('ssl_mode' => $config['secure'], 'port' => $config['port'], 'timeout' => 0, 'force_caps' => false));
     return $client;
 }
Example #2
0
 /**
  * Connect to an IMAP server
  *
  * @param  string   $host    Host to connect
  * @param  string   $user    Username for IMAP account
  * @param  string   $pass    Password for IMAP account
  * @param  integer  $port    Port to connect to
  * @param  string   $use_ssl 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)
 {
     // check for OpenSSL support in PHP build
     if ($use_ssl && extension_loaded('openssl')) {
         $this->options['ssl_mode'] = $use_ssl == 'imaps' ? 'ssl' : $use_ssl;
     } else {
         if ($use_ssl) {
             raise_error(array('code' => 403, 'type' => 'imap', 'file' => __FILE__, 'line' => __LINE__, 'message' => "OpenSSL not available"), true, false);
             $port = 143;
         }
     }
     $this->options['port'] = $port;
     if ($this->options['debug']) {
         $this->conn->setDebug(true, array($this, 'debug_handler'));
         $this->options['ident'] = array('name' => 'Roundcube Webmail', 'version' => RCMAIL_VERSION, 'php' => PHP_VERSION, 'os' => PHP_OS, 'command' => $_SERVER['REQUEST_URI']);
     }
     $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->connect($data['host'], $data['user'], $pass, $this->options);
     } while (!$this->conn->connected() && $data['retry']);
     $this->host = $data['host'];
     $this->user = $data['user'];
     $this->pass = $pass;
     $this->port = $port;
     $this->ssl = $use_ssl;
     if ($this->conn->connected()) {
         // get namespace and delimiter
         $this->set_env();
         return true;
     } else {
         if ($this->conn->error) {
             if ($pass && $user) {
                 $message = sprintf("Login failed for %s from %s. %s", $user, rcmail_remote_ip(), $this->conn->error);
                 raise_error(array('code' => 403, 'type' => 'imap', 'file' => __FILE__, 'line' => __LINE__, 'message' => $message), true, false);
             }
         }
     }
     return false;
 }
Example #3
0
 /**
  * Activate/deactivate debug mode
  *
  * @param boolean $dbg True if IMAP conversation should be logged
  */
 public function set_debug($dbg = true)
 {
     $this->options['debug'] = $dbg;
     $this->conn->setDebug($dbg, array($this, 'debug_handler'));
 }