Class mail_fetch

Description

POP3 client class

POP connection is opened when class is constructed. All command_* methods execute specific POP commands on server. Most of other methods should be used only internally. Only login() method is public. If command returns mixed content and you expect message text, ids or something else, make sure that it is not boolean false.

Basic use:

  1. create object with connection params, see mail_fetch method.
  2. check error buffer
  3. login($username,$password) - true = login successful, false = login error.
  4. command_stat() - get number of messages
  5. command_list() - get message ids, use command_uidl(), if you implement
'keep mess on server' functions. Make sure that you handle possible UIDL command errors. 6. command_retr($some_message_id) - get message contents 7. command_dele($some_message_id) - mark message for deletion 8. command_quit() - close connection. You must close connection in order to delete messages and remove mailbox lock.

Located in /plugins/mail_fetch/class.mail_fetch.php (line 50)


	
			
Variable Summary
 integer $auth
 stream $conn
 string $error
 string $greeting
 string $host
 integer $port
 string $response
 integer $timeout
 string $timestamp
 integer $tls
Method Summary
 mail_fetch mail_fetch ([array $aParams = array()])
 void check_php_version ([ $a = '0'], [ $b = '0'], [ $c = '0'])
 boolean check_response ()
 boolean command_apop (string $username, string $password)
 boolean command_auth_plain (string $user, string $pass)
 void command_capa ()
 boolean command_dele (integer $msg)
 mixed command_list ([integer $msg = ''])
 boolean command_noop ()
 boolean command_pass (string $password)
 void command_quit ()
 mixed command_retr (integer $msg)
 boolean command_rset ()
 mixed command_stat ()
 boolean command_stls ()
 string command_top (integer $msg, integer $n)
 mixed command_uidl ([integer $msg = ''])
 boolean command_user (string $username)
 boolean login (string $username, string $password)
 boolean open ()
 boolean set_error (string $error, [boolean $close_conn = false])
Variables
integer $auth = 1 (line 85)

Authentication type

Bitwise variable. If variable covers more than one authentication method, login() tries to use all of them until first successful auth.

  1. - user/pass (rfc1939, default)
  2. - apop (rfc1939, timestamp must be present in greeting)
  3. - apop or user/pass (1+2 bitwise value of two auth methods)
  4. - SASL PLAIN (rfc4616 + rfc5034). Supported since 1.1

array $capabilities = array() (line 115)

Capabilities (POP3EXT capa)

stream $conn = false (line 97)

Connection resource

string $error = '' (line 121)

Error message buffer

string $greeting = '' (line 103)

Server greeting

string $host = '' (line 55)

Server name

integer $port = 0 (line 62)

POP connection port.

Defaults to 110 on plain text connections and to 995 on TLS

string $response = '' (line 131)

Response buffer

Variable is used to store last positive POP server response checked in check_response() method. Used internally to handle mixed single and multiline command responses.

integer $timeout = 60 (line 91)

Connection timeout

string $timestamp = '' (line 109)

Timestamp (with <> or empty string)

integer $tls = 0 (line 72)

Connection type

  1. - plain text (default)
  2. - tls (php 4.3 and openssl extension requirement)
  3. - stls (stream_socket_enable_crypto() requirement. PHP 5.1.0, POP3 server with POP3EXT and STLS support)

Methods
Constructor mail_fetch (line 145)

Constructor function

parameter array keys 'host' - required string, address of server. ip or fqn 'port' - optional integer, port of server. 'tls' - optional integer, connection type 'timeout' - optional integer, connection timeout 'auth' - optional integer, used authentication mechanism. See description of class properties

mail_fetch mail_fetch ([array $aParams = array()])
  • array $aParams: connection params
check_php_version (line 262)

Standard SquirrelMail function copied to class in order to make class independent from SquirrelMail.

void check_php_version ([ $a = '0'], [ $b = '0'], [ $c = '0'])
  • $a
  • $b
  • $c
check_response (line 245)

Reads first response line and checks it for errors

  • return: true = success, false = failure, check error buffer
boolean check_response ()
command_apop (line 539)

APOP authentication

Command is optional and not required by rfc1939. APOP support requires plain text passwords stored on server and some servers don't support it. Standard qmail pop3d declares apop support without checking if checkpassword supports it.

  • return: true = success, false = failure.
boolean command_apop (string $username, string $password)
  • string $username
  • string $password
command_auth_plain (line 618)

SASL PLAIN authentication

Current implementation does not support alternative SASL authentication identities.

  • since: 1.1
boolean command_auth_plain (string $user, string $pass)
  • string $user
  • string $pass
command_capa (line 557)

Checks pop server capabilities

RFC2449. Fills capabilities array.

void command_capa ()
command_dele (line 408)
boolean command_dele (integer $msg)
  • integer $msg
command_list (line 346)

List mailbox messages

  • return: array with message ids (keys) and sizes (values) or boolean false
mixed command_list ([integer $msg = ''])
  • integer $msg
command_noop (line 417)

POP noop command

boolean command_noop ()
command_pass (line 523)

USER authentication (password command)

Command is optional and not required by rfc1939. Requires successful user command.

  • return: true = success, false = failure.
boolean command_pass (string $password)
  • string $password
command_quit (line 434)

Closes POP connection

void command_quit ()
command_retr (line 378)

Gets message text

  • return: rfc822 message (CRLF line endings) or boolean false
mixed command_retr (integer $msg)
  • integer $msg: message id
command_rset (line 426)

Resets message state

boolean command_rset ()
command_stat (line 330)

Gets mailbox status

array with 'count' and 'size' keys

  • return: array or boolean false
mixed command_stat ()
command_stls (line 583)

RFC 2595 POP STARTTLS support

boolean command_stls ()
command_top (line 450)

Gets message headers and $n of body lines.

Command is optional and not required by rfc1939

  • return: or boolean false
string command_top (integer $msg, integer $n)
  • integer $msg
  • integer $n
command_uidl (line 475)

Gets unique message ids

Command is optional and not required by rfc1939

  • return: array with message ids (keys) and unique ids (values) or boolean false
mixed command_uidl ([integer $msg = ''])
  • integer $msg: message id
command_user (line 510)

USER authentication (username command)

Command is optional and not required by rfc1939. If command is successful, pass command must be executed after it.

  • return: true = success, false = failure.
boolean command_user (string $username)
  • string $username
login (line 275)

Generic login wrapper

Connection is not closed on login error (unless POP server drops connection)

boolean login (string $username, string $password)
  • string $username
  • string $password
open (line 192)

Opens pop connection

Command handles TLS and STLS connection differences and fills capabilities array with RFC2449 CAPA data.

boolean open ()
set_error (line 315)

Sets error in error buffer and returns boolean false

  • return: false
boolean set_error (string $error, [boolean $close_conn = false])
  • string $error: Error message
  • boolean $close_conn: Do we have to close connection

Documentation generated on Sun, 22 Nov 2009 17:36:18 +0200 by phpDocumentor 1.4.3