60 public function __construct($host, $port = 110, $crypto = null)
64 $this->_crypto = $crypto;
76 public static function newInstance($host, $port = 110, $crypto = null)
78 return new self($host, $port, $crypto);
88 $this->_connection = $connection;
99 $this->_transport = $smtp;
109 $this->_timeout = (int) $timeout;
120 $this->_username = $username;
131 $this->_password = $password;
142 if (isset($this->_connection))
144 $this->_connection->connect();
148 if (!isset($this->_socket))
150 if (!$socket = fsockopen(
151 $this->
_getHostString(), $this->_port, $errno, $errstr, $this->_timeout))
154 sprintf(
'Failed to connect to POP3 host [%s]: %s', $this->_host, $errstr)
157 $this->_socket = $socket;
159 if (
false === $greeting = fgets($this->_socket))
162 sprintf(
'Failed to connect to POP3 host [%s]', trim($greeting))
168 if ($this->_username)
170 $this->
_command(sprintf(
"USER %s\r\n", $this->_username));
171 $this->
_command(sprintf(
"PASS %s\r\n", $this->_password));
182 if (isset($this->_connection))
184 $this->_connection->disconnect();
189 if (!fclose($this->_socket))
192 sprintf(
'POP3 host [%s] connection could not be stopped', $this->_host)
195 $this->_socket = null;
206 if (isset($this->_transport))
243 if (!fwrite($this->_socket, $command))
246 sprintf(
'Failed to write command [%s] to POP3 host', trim($command))
250 if (
false === $response = fgets($this->_socket))
253 sprintf(
'Failed to read from POP3 host after command [%s]', trim($command))
264 if (substr($response, 0, 3) !=
'+OK')
267 sprintf(
'POP3 command failed [%s]', trim($response))
275 switch (strtolower($this->_crypto))
278 $host =
'ssl://' . $host;
282 $host =
'tls://' . $host;