function _connect(&$fp)
 {
     if (!empty($this->proxy_host) && !empty($this->proxy_port)) {
         $this->_isproxy = true;
         $host = $this->proxy_host;
         $port = $this->proxy_port;
     } else {
         $host = $this->host;
         if (empty($this->port)) {
             $port = 80;
         } else {
             $port = $this->port;
         }
     }
     $this->status = 0;
     // Mod: Added IDNA support
     list($fp, $errno, $errstr, $host) = fsockopen_idna($host, $port, $this->_fp_timeout);
     if ($fp) {
         // socket connection succeeded
         return true;
     } else {
         // socket connection failed
         $this->status = $errno;
         switch ($errno) {
             case -3:
                 $this->error = "socket creation failed (-3)";
             case -4:
                 $this->error = "dns lookup failure (-4)";
             case -5:
                 $this->error = "connection refused or timed out (-5)";
             default:
                 $this->error = "connection failed (" . $errno . ")";
         }
         return false;
     }
 }
  /**
   * Connect to the POP3 server
   * @access public
   * @param string $host
   * @param bool|int $port
   * @param integer $tval
   * @return boolean
   * Modified for Viscacha
   */
  public function Connect ($host, $port = false, $tval = 30) {
    //  Are we already connected?
    if ($this->connected) {
      return true;
    }

    list($this->pop_conn, $errno, $errstr, $host) = fsockopen_idna($host, $port, $tval);

    //  Does the Error Log now contain anything?
    if ($this->error && $this->do_debug >= 1) {
      $this->displayErrors();
    }

    //  Did we connect?
    if ($this->pop_conn == false) {
      //  It would appear not...
      $this->error = array(
        'error' => "Failed to connect to server $host on port $port",
        'errno' => $errno,
        'errstr' => $errstr
      );

      if ($this->do_debug >= 1) {
        $this->displayErrors();
      }

      return false;
    }

    //  Increase the stream time-out

    //  Check for PHP 4.3.0 or later
    if (version_compare(phpversion(), '5.0.0', 'ge')) {
      stream_set_timeout($this->pop_conn, $tval, 0);
    } else {
      //  Does not work on Windows
      if (substr(PHP_OS, 0, 3) !== 'WIN') {
        socket_set_timeout($this->pop_conn, $tval, 0);
      }
    }

    //  Get the POP3 server response
    $pop3_response = $this->getResponse();

    //  Check for the +OK
    if ($this->checkResponse($pop3_response)) {
      //  The connection is established and the POP3 server is talking
      $this->connected = true;
      return true;
    }
    return false;
  }
 /**
  * Connect to the server specified on the port specified.
  * If the port is not specified use the default SMTP_PORT.
  * If tval is specified then a connection will try and be
  * established with the server for that number of seconds.
  * If tval is not specified the default is 30 seconds to
  * try on the connection.
  *
  * SMTP CODE SUCCESS: 220
  * SMTP CODE FAILURE: 421
  * @access public
  * @return bool
  */
 function Connect($host, $port = 0, $tval = 30)
 {
     # set the error val to null so there is no confusion
     $this->error = null;
     # make sure we are __not__ connected
     if ($this->connected()) {
         # ok we are connected! what should we do?
         # for now we will just give an error saying we
         # are already connected
         $this->error = array("error" => "Already connected to a server");
         return false;
     }
     if (empty($port)) {
         $port = $this->SMTP_PORT;
     }
     // Mod: Added IDNA support
     #connect to the smtp server
     list($this->smtp_conn, $errno, $errstr, $host) = fsockopen_idna($host, $port, $tval);
     # verify we connected properly
     if (empty($this->smtp_conn)) {
         $this->error = array("error" => "Failed to connect to server", "errno" => $errno, "errstr" => $errstr);
         if ($this->do_debug >= 1) {
             echo "SMTP -> ERROR: " . $this->error["error"] . ": {$errstr} ({$errno})" . $this->CRLF;
         }
         return false;
     }
     # sometimes the SMTP server takes a little longer to respond
     # so we will give it a longer timeout for the first read
     // Windows still does not have support for this timeout function
     if (substr(PHP_OS, 0, 3) != "WIN") {
         socket_set_timeout($this->smtp_conn, $tval, 0);
     }
     # get any announcement stuff
     $announce = $this->get_lines();
     # set the timeout  of any socket functions at 1/10 of a second
     //if(function_exists("socket_set_timeout"))
     //   socket_set_timeout($this->smtp_conn, 0, 100000);
     if ($this->do_debug >= 2) {
         echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
     }
     return true;
 }
 function _data_prepare($mode = FTP_ASCII)
 {
     if (!$this->_settype($mode)) {
         return FALSE;
     }
     if ($this->_passive) {
         if (!$this->_exec("PASV", "pasv")) {
             $this->_data_close();
             return FALSE;
         }
         if (!$this->_checkCode()) {
             $this->_data_close();
             return FALSE;
         }
         $ip_port = explode(",", ereg_replace("^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*" . CRLF . "\$", "\\1", $this->_message));
         $this->_datahost = $ip_port[0] . "." . $ip_port[1] . "." . $ip_port[2] . "." . $ip_port[3];
         $this->_dataport = ((int) $ip_port[4] << 8) + (int) $ip_port[5];
         $this->SendMSG("Connecting to " . $this->_datahost . ":" . $this->_dataport);
         list($this->_ftp_data_sock, $errno, $errstr, $this->_datahost) = fsockopen_idna($this->_datahost, $this->_dataport, $this->_timeout);
         if (!$this->_ftp_data_sock) {
             $this->PushError("_data_prepare", "fsockopen fails (host: {$this->_datahost})", $errstr . " (" . $errno . ")");
             $this->_data_close();
             return FALSE;
         }
     } else {
         $this->SendMSG("Only passive connections available!");
         return FALSE;
     }
     return TRUE;
 }