ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
POP3 Class Reference
+ Collaboration diagram for POP3:

Public Member Functions

 authorise ($host, $port=false, $timeout=false, $username='', $password='', $debug_level=0)
 Authenticate with a POP3 server. More...
 
 connect ($host, $port=false, $tval=30)
 Connect to a POP3 server. More...
 
 login ($username='', $password='')
 Log in to the POP3 server. More...
 
 disconnect ()
 Disconnect from the POP3 server. More...
 
 getErrors ()
 Get an array of error messages, if any. More...
 

Static Public Member Functions

static popBeforeSmtp ( $host, $port=false, $timeout=false, $username='', $password='', $debug_level=0)
 Simple static wrapper for all-in-one POP before SMTP. More...
 

Data Fields

 $Version = '5.2.22'
 
 $POP3_PORT = 110
 
 $POP3_TIMEOUT = 30
 
 $CRLF = "\r\n"
 
 $do_debug = 0
 
 $host
 
 $port
 
 $tval
 
 $username
 
 $password
 
const CRLF = "\r\n"
 Line break constant. More...
 

Protected Member Functions

 getResponse ($size=128)
 Get a response from the POP3 server. More...
 
 sendString ($string)
 Send raw data to the POP3 server. More...
 
 checkResponse ($string)
 Checks the POP3 server response. More...
 
 setError ($error)
 Add an error to the internal error store. More...
 
 catchWarning ($errno, $errstr, $errfile, $errline)
 POP3 connection error handler. More...
 

Protected Attributes

 $pop_conn
 
 $connected = false
 
 $errors = array()
 

Detailed Description

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

Member Function Documentation

◆ authorise()

POP3::authorise (   $host,
  $port = false,
  $timeout = false,
  $username = '',
  $password = '',
  $debug_level = 0 
)

Authenticate with a POP3 server.

A connect, login, disconnect sequence appropriate for POP-before SMTP authorisation. @access public

Parameters
string$hostThe hostname to connect to
integer | boolean$portThe port number to connect to
integer | boolean$timeoutThe timeout value
string$username
string$password
integer$debug_level
Returns
boolean

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

166 {
167 $this->host = $host;
168 // If no port value provided, use default
169 if (false === $port) {
170 $this->port = $this->POP3_PORT;
171 } else {
172 $this->port = (integer)$port;
173 }
174 // If no timeout value provided, use default
175 if (false === $timeout) {
176 $this->tval = $this->POP3_TIMEOUT;
177 } else {
178 $this->tval = (integer)$timeout;
179 }
180 $this->do_debug = $debug_level;
181 $this->username = $username;
182 $this->password = $password;
183 // Reset the error log
184 $this->errors = array();
185 // connect
186 $result = $this->connect($this->host, $this->port, $this->tval);
187 if ($result) {
188 $login_result = $this->login($this->username, $this->password);
189 if ($login_result) {
190 $this->disconnect();
191 return true;
192 }
193 }
194 // We need to disconnect regardless of whether the login succeeded
195 $this->disconnect();
196 return false;
197 }
$result
$POP3_TIMEOUT
Definition: class.pop3.php:51
login($username='', $password='')
Log in to the POP3 server.
Definition: class.pop3.php:266
disconnect()
Disconnect from the POP3 server.
Definition: class.pop3.php:296
connect($host, $port=false, $tval=30)
Connect to a POP3 server.
Definition: class.pop3.php:207
$username
Definition: class.pop3.php:95
$POP3_PORT
Definition: class.pop3.php:44

References $host, $password, $POP3_PORT, $POP3_TIMEOUT, $port, $result, $username, connect(), disconnect(), and login().

Referenced by popBeforeSmtp().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ catchWarning()

POP3::catchWarning (   $errno,
  $errstr,
  $errfile,
  $errline 
)
protected

POP3 connection error handler.

Parameters
integer$errno
string$errstr
string$errfile
integer$errline@access protected

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

398 {
399 $this->setError(array(
400 'error' => "Connecting to the POP3 server raised a PHP warning: ",
401 'errno' => $errno,
402 'errstr' => $errstr,
403 'errfile' => $errfile,
404 'errline' => $errline
405 ));
406 }
setError($error)
Add an error to the internal error store.
Definition: class.pop3.php:368

References setError().

+ Here is the call graph for this function:

◆ checkResponse()

POP3::checkResponse (   $string)
protected

Checks the POP3 server response.

Looks for for +OK or -ERR.

Parameters
string$string
Returns
boolean @access protected

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

349 {
350 if (substr($string, 0, 3) !== '+OK') {
351 $this->setError(array(
352 'error' => "Server reported an error: $string",
353 'errno' => 0,
354 'errstr' => ''
355 ));
356 return false;
357 } else {
358 return true;
359 }
360 }

References setError().

Referenced by connect(), and login().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ connect()

POP3::connect (   $host,
  $port = false,
  $tval = 30 
)

Connect to a POP3 server.

@access public

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

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

208 {
209 // Are we already connected?
210 if ($this->connected) {
211 return true;
212 }
213
214 //On Windows this will raise a PHP Warning error if the hostname doesn't exist.
215 //Rather than suppress it with @fsockopen, capture it cleanly instead
216 set_error_handler(array($this, 'catchWarning'));
217
218 if (false === $port) {
220 }
221
222 // connect to the POP3 server
223 $this->pop_conn = fsockopen(
224 $host, // POP3 Host
225 $port, // Port #
226 $errno, // Error Number
227 $errstr, // Error Message
228 $tval
229 ); // Timeout (seconds)
230 // Restore the error handler
231 restore_error_handler();
232
233 // Did we connect?
234 if (false === $this->pop_conn) {
235 // It would appear not...
236 $this->setError(array(
237 'error' => "Failed to connect to server $host on port $port",
238 'errno' => $errno,
239 'errstr' => $errstr
240 ));
241 return false;
242 }
243
244 // Increase the stream time-out
245 stream_set_timeout($this->pop_conn, $tval, 0);
246
247 // Get the POP3 server response
248 $pop3_response = $this->getResponse();
249 // Check for the +OK
250 if ($this->checkResponse($pop3_response)) {
251 // The connection is established and the POP3 server is talking
252 $this->connected = true;
253 return true;
254 }
255 return false;
256 }
getResponse($size=128)
Get a response from the POP3 server.
Definition: class.pop3.php:315
checkResponse($string)
Checks the POP3 server response.
Definition: class.pop3.php:348

References $host, $POP3_PORT, $port, $tval, checkResponse(), getResponse(), and setError().

Referenced by authorise().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ disconnect()

POP3::disconnect ( )

Disconnect from the POP3 server.

@access public

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

297 {
298 $this->sendString('QUIT');
299 //The QUIT command may cause the daemon to exit, which will kill our connection
300 //So ignore errors here
301 try {
302 @fclose($this->pop_conn);
303 } catch (Exception $e) {
304 //Do nothing
305 };
306 }
sendString($string)
Send raw data to the POP3 server.
Definition: class.pop3.php:330

References sendString().

Referenced by authorise().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getErrors()

POP3::getErrors ( )

Get an array of error messages, if any.

Returns
array

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

385 {
386 return $this->errors;
387 }

References $errors.

◆ getResponse()

POP3::getResponse (   $size = 128)
protected

Get a response from the POP3 server.

$size is the maximum number of bytes to retrieve

Parameters
integer$size
Returns
string @access protected

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

316 {
317 $response = fgets($this->pop_conn, $size);
318 if ($this->do_debug >= 1) {
319 echo "Server -> Client: $response";
320 }
321 return $response;
322 }
$size
Definition: RandomTest.php:79

References $size.

Referenced by connect(), and login().

+ Here is the caller graph for this function:

◆ login()

POP3::login (   $username = '',
  $password = '' 
)

Log in to the POP3 server.

Does not support APOP (RFC 2828, 4949). @access public

Parameters
string$username
string$password
Returns
boolean

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

267 {
268 if (!$this->connected) {
269 $this->setError('Not connected to POP3 server');
270 }
271 if (empty($username)) {
273 }
274 if (empty($password)) {
276 }
277
278 // Send the Username
279 $this->sendString("USER $username" . self::CRLF);
280 $pop3_response = $this->getResponse();
281 if ($this->checkResponse($pop3_response)) {
282 // Send the Password
283 $this->sendString("PASS $password" . self::CRLF);
284 $pop3_response = $this->getResponse();
285 if ($this->checkResponse($pop3_response)) {
286 return true;
287 }
288 }
289 return false;
290 }

References $password, $username, checkResponse(), getResponse(), sendString(), and setError().

Referenced by authorise().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ popBeforeSmtp()

static POP3::popBeforeSmtp (   $host,
  $port = false,
  $timeout = false,
  $username = '',
  $password = '',
  $debug_level = 0 
)
static

Simple static wrapper for all-in-one POP before SMTP.

Parameters
$host
integer | boolean$portThe port number to connect to
integer | boolean$timeoutThe timeout value
string$username
string$password
integer$debug_level
Returns
boolean

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

147 {
148 $pop = new POP3;
149 return $pop->authorise($host, $port, $timeout, $username, $password, $debug_level);
150 }
authorise($host, $port=false, $timeout=false, $username='', $password='', $debug_level=0)
Authenticate with a POP3 server.
Definition: class.pop3.php:165

References $host, $password, $port, $username, and authorise().

+ Here is the call graph for this function:

◆ sendString()

POP3::sendString (   $string)
protected

Send raw data to the POP3 server.

Parameters
string$string
Returns
integer @access protected

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

331 {
332 if ($this->pop_conn) {
333 if ($this->do_debug >= 2) { //Show client messages when debug >= 2
334 echo "Client -> Server: $string";
335 }
336 return fwrite($this->pop_conn, $string, strlen($string));
337 }
338 return 0;
339 }

Referenced by disconnect(), and login().

+ Here is the caller graph for this function:

◆ setError()

POP3::setError (   $error)
protected

Add an error to the internal error store.

Also display debug output if it's enabled.

Parameters
$error@access protected

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

369 {
370 $this->errors[] = $error;
371 if ($this->do_debug >= 1) {
372 echo '<pre>';
373 foreach ($this->errors as $error) {
374 print_r($error);
375 }
376 echo '</pre>';
377 }
378 }

Referenced by catchWarning(), checkResponse(), connect(), and login().

+ Here is the caller graph for this function:

Field Documentation

◆ $connected

POP3::$connected = false
protected

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

◆ $CRLF

POP3::$CRLF = "\r\n"

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

◆ $do_debug

POP3::$do_debug = 0

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

◆ $errors

POP3::$errors = array()
protected

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

Referenced by getErrors().

◆ $host

POP3::$host

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

Referenced by authorise(), connect(), and popBeforeSmtp().

◆ $password

POP3::$password

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

Referenced by authorise(), login(), and popBeforeSmtp().

◆ $POP3_PORT

POP3::$POP3_PORT = 110

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

Referenced by authorise(), and connect().

◆ $POP3_TIMEOUT

POP3::$POP3_TIMEOUT = 30

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

Referenced by authorise().

◆ $pop_conn

POP3::$pop_conn
protected

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

◆ $port

POP3::$port

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

Referenced by authorise(), connect(), and popBeforeSmtp().

◆ $tval

POP3::$tval

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

Referenced by connect().

◆ $username

POP3::$username

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

Referenced by authorise(), login(), and popBeforeSmtp().

◆ $Version

POP3::$Version = '5.2.22'

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

◆ CRLF

const POP3::CRLF = "\r\n"

Line break constant.

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


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