52 public function __construct($host, $port = 110, $crypto = null)
56 $this->_crypto = $crypto;
68 public static function newInstance($host, $port = 110, $crypto = null)
70 return new self($host, $port, $crypto);
82 $this->_connection = $connection;
94 $this->_transport = $smtp;
106 $this->_timeout = (int) $timeout;
120 $this->_username = $username;
134 $this->_password = $password;
146 if (isset($this->_connection)) {
147 $this->_connection->connect();
149 if (!isset($this->_socket)) {
150 if (!$socket = fsockopen(
151 $this->
_getHostString(), $this->_port, $errno, $errstr, $this->_timeout)) {
153 sprintf(
'Failed to connect to POP3 host [%s]: %s', $this->_host, $errstr)
156 $this->_socket = $socket;
158 if (
false === $greeting = fgets($this->_socket)) {
160 sprintf(
'Failed to connect to POP3 host [%s]', trim($greeting))
166 if ($this->_username) {
167 $this->
_command(sprintf(
"USER %s\r\n", $this->_username));
168 $this->
_command(sprintf(
"PASS %s\r\n", $this->_password));
179 if (isset($this->_connection)) {
180 $this->_connection->disconnect();
183 if (!fclose($this->_socket)) {
185 sprintf(
'POP3 host [%s] connection could not be stopped', $this->_host)
188 $this->_socket = null;
199 if (isset($this->_transport)) {
232 if (!fwrite($this->_socket, $command)) {
234 sprintf(
'Failed to write command [%s] to POP3 host', trim($command))
238 if (
false ===
$response = fgets($this->_socket)) {
240 sprintf(
'Failed to read from POP3 host after command [%s]', trim($command))
253 sprintf(
'POP3 command failed [%s]', trim(
$response))
261 switch (strtolower($this->_crypto)) {
263 $host =
'ssl://'.$host;
267 $host =
'tls://'.$host;