Ejemplo n.º 1
0
 /**
  * Authenticate to IMAP with the given credentials
  */
 public static function connect_imap($username, $password, $host = null)
 {
     $rcmail = rcmail::get_instance();
     $imap = $rcmail->get_storage();
     if ($imap->is_connected()) {
         $imap->close();
         self::$imap_ready = false;
     }
     $imap_host = $host ?: $rcmail->config->get('default_host');
     $a_host = parse_url($imap_host);
     if ($a_host['host']) {
         $imap_host = $a_host['host'];
         $imap_ssl = isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl', 'imaps', 'tls'));
         $imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : 143);
     } else {
         $imap_port = 143;
         $imap_ssl = false;
     }
     if (!$imap->connect($imap_host, $username, $password, $imap_port, $imap_ssl)) {
         die("IMAP error: unable to authenticate with user " . TESTS_USER);
     }
     self::$imap_ready = true;
 }