Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Public Attributes | List of all members
POP3 Class Reference

Public Member Functions

 __construct ()
 Authorise ($host, $port=false, $tval=false, $username, $password, $debug_level=0)
 Connect ($host, $port=false, $tval=30)
 Login ($username= '', $password= '')
 Disconnect ()

Public Attributes

 $POP3_PORT = 110
 $POP3_TIMEOUT = 30
 $CRLF = "\r\n"
 $do_debug = 2
 $host
 $port
 $tval
 $username
 $password

Detailed Description

Definition at line 62 of file class.pop3.php.

Constructor & Destructor Documentation

POP3::__construct ( )

Constructor, sets the initial values public

Returns
POP3

Definition at line 130 of file class.pop3.php.

{
$this->pop_conn = 0;
$this->connected = false;
$this->error = null;
}

Member Function Documentation

POP3::Authorise (   $host,
  $port = false,
  $tval = false,
  $username,
  $password,
  $debug_level = 0 
)

Combination of public events - connect, login, disconnect public

Parameters
string$host
integer$port
integer$tval
string$username
string$password

Definition at line 145 of file class.pop3.php.

References Connect(), Disconnect(), and Login().

{
$this->host = $host;
// If no port value is passed, retrieve it
if ($port == false) {
$this->port = $this->POP3_PORT;
} else {
$this->port = $port;
}
// If no port value is passed, retrieve it
if ($tval == false) {
$this->tval = $this->POP3_TIMEOUT;
} else {
$this->tval = $tval;
}
$this->do_debug = $debug_level;
$this->username = $username;
$this->password = $password;
// Refresh the error log
$this->error = null;
// Connect
$result = $this->Connect($this->host, $this->port, $this->tval);
if ($result) {
$login_result = $this->Login($this->username, $this->password);
if ($login_result) {
$this->Disconnect();
return true;
}
}
// We need to disconnect regardless if the login succeeded
$this->Disconnect();
return false;
}
POP3::Connect (   $host,
  $port = false,
  $tval = 30 
)

Connect to the POP3 server public

Parameters
string$host
integer$port
integer$tval
Returns
boolean

Definition at line 197 of file class.pop3.php.

Referenced by Authorise().

{
// Are we already connected?
if ($this->connected) {
return true;
}
/*
On Windows this will raise a PHP Warning error if the hostname doesn't exist.
Rather than supress it with @fsockopen, let's capture it cleanly instead
*/
set_error_handler(array(&$this, 'catchWarning'));
// Connect to the POP3 server
$this->pop_conn = fsockopen($host, // POP3 Host
$port, // Port #
$errno, // Error Number
$errstr, // Error Message
$tval); // Timeout (seconds)
// Restore the error handler
restore_error_handler();
// 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;
}
}
POP3::Disconnect ( )

Disconnect from the POP3 server public

Definition at line 315 of file class.pop3.php.

Referenced by Authorise().

{
$this->sendString('QUIT');
fclose($this->pop_conn);
}
POP3::Login (   $username = '',
  $password = '' 
)

Login to the POP3 server (does not support APOP yet) public

Parameters
string$username
string$password
Returns
boolean

Definition at line 272 of file class.pop3.php.

Referenced by Authorise().

{
if ($this->connected == false) {
$this->error = 'Not connected to POP3 server';
if ($this->do_debug >= 1) {
$this->displayErrors();
}
}
if (empty($username)) {
$username = $this->username;
}
if (empty($password)) {
$password = $this->password;
}
$pop_username = "USER $username" . $this->CRLF;
$pop_password = "PASS $password" . $this->CRLF;
// Send the Username
$this->sendString($pop_username);
$pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) {
// Send the Password
$this->sendString($pop_password);
$pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) {
return true;
} else {
return false;
}
} else {
return false;
}
}

The documentation for this class was generated from the following file: