Zeta Components Manual :: Docs For Class ezcMailPop3Transport
Mail::ezcMailPop3Transport
Class ezcMailPop3Transport
The class ezcMailPop3Transport implements functionality for handling POP3 mail servers.
The implementation supports most of the commands specified in:
- http://www.faqs.org/rfcs/rfc1939.html (POP3)
- http://www.faqs.org/rfcs/rfc1734.html (POP3 AUTH)
The POP3 transport class allows developers to interface with a POP3 server.
Basic commands:
- connect to a POP3 server (__construct())
- authenticate a user with a username and password (authenticate())
- disconnect from the POP3 server (disconnect())
- get the message numbers and sizes of all the messages (listMessages())
- get the message numbers and IDs of all the messages (listUniqueIdentifiers())
- get the headers of a certain message (top())
- delete a message (delete())
- create a set from all messages (fetchAll())
- create a set from a certain message (fetchByMessageNr())
- create a set from a range of messages (fetchFromOffset())
- get the status of messages on the server (status())
- issue a NOOP command to keep the connection alive (noop())
- // create a new POP3 transport object by specifying the server name, optional
- // port and optional SSL mode
- $options->ssl = true;
- // Authenticate to the POP3 server
- // issue commands to the POP3 server
- // for example get the headers of the first message, which can be
- // parsed with ezcMailVariableSet and ezcMailParser
- // see the above list of commands or consult the online documentation for
- // the full list of commands you can issue to an POP3 server and examples
- // disconnect from the POP3 server
See ezcMailPop3TransportOptions for options you can specify for POP3.
Source for this file: /Mail/src/transports/pop3/pop3_transport.php
Version: | //autogen// |
Todo: | ignore messages of a certain size? |
Todo: | // support for signing? |
Constants
AUTH_APOP
= 2
|
APOP authorization. |
AUTH_PLAIN_TEXT
= 1
|
Plain text authorization. |
Properties
ezcMailPop3TransportOptions | read/write |
$options
Holds the options you can set to the POP3 transport. |
Member Variables
protected ezcMailTransportConnection |
$connection
= null
The connection to the POP3 server. |
protected string |
$greeting
= null
Holds the initial greeting from the POP3 server when connecting. |
protected mixed |
$state
= self::STATE_NOT_CONNECTED
Holds the connection state. $var int STATE_NOT_CONNECTED, STATE_AUTHORIZATION, STATE_TRANSACTION or STATE_UPDATE. |
Method Summary
public ezcMailPop3Transport |
__construct(
$server
, [ $port
= null] , [ $options
= array()] )
Creates a new POP3 transport and connects to the $server at $port. |
public void |
__destruct(
)
Destructs the POP3 transport object. |
public void |
authenticate(
$user
, $password
, [ $method
= null] )
Authenticates the user to the POP3 server with $user and $password. |
public void |
delete(
$msgNum
)
Deletes the message with the message number $msgNum from the server. |
public void |
disconnect(
)
Disconnects the transport from the POP3 server. |
public ezcMailParserSet |
fetchAll(
[ $deleteFromServer
= false] )
Returns an ezcMailPop3Set with all the messages on the server. |
public ezcMailPop3Set |
fetchByMessageNr(
$number
, [ $deleteFromServer
= false] )
Returns an ezcMailPop3Set containing only the $number -th message from the server. |
public ezcMailPop3Set |
fetchFromOffset(
$offset
, [ $count
= 0] , [ $deleteFromServer
= false] )
Returns an ezcMailPop3Set with $count messages starting from $offset from the server. |
protected bool |
isPositiveResponse(
$line
)
Returns true if the response from the server is a positive one. |
public array(int) |
listMessages(
)
Returns an array of the message numbers on the server and the size of the messages in bytes. |
public array(string) |
listUniqueIdentifiers(
[ $msgNum
= null] )
Returns the unique identifiers for messages on the POP3 server. |
public void |
noop(
)
Sends a NOOP command to the server, use it to keep the connection alive. |
public void |
status(
&$numMessages
, &$sizeMessages
)
Returns information about the messages on the server. |
public string |
top(
$msgNum
, [ $numLines
= 0] )
Returns the headers and the $numLines first lines of the body of the mail with the message number $msgNum. |
Methods
__construct
Creates a new POP3 transport and connects to the $server at $port.
You can specify the $port if the POP3 server is not on the default port 995 (for SSL connections) or 110 (for plain connections). Use the $options parameter to specify an SSL connection.
For options you can specify for POP3 see ezcMailPop3TransportOptions.
Example of creating a POP3 transport:
- // replace with your POP3 server address
- // if you want to use SSL:
- $options->ssl = true;
Parameters:
Name | Type | Description |
---|---|---|
$server |
string | |
$port |
int | |
$options |
ezcMailPop3TransportOptions|array(string=>mixed) |
Exceptions:
Type | Description |
---|---|
ezcMailTransportException |
if it was not possible to connect to the server |
ezcBaseValueException |
if $options contains a property with a value not allowed |
ezcBaseExtensionNotFoundException |
if trying to use SSL and the extension openssl is not installed |
ezcBasePropertyNotFoundException |
if $options contains a property not defined |
__destruct
Destructs the POP3 transport object.
If there is an open connection to the POP3 server it is closed.
authenticate
Authenticates the user to the POP3 server with $user and $password.
You can choose the authentication method with the $method parameter. The default is to use plaintext username and password (specified in the ezcMailPop3TransportOptions class).
This method should be called directly after the construction of this object.
Example:
- // replace with your POP3 server address
- // replace the values with your username and password for the POP3 server
Parameters:
Name | Type | Description |
---|---|---|
$user |
string | |
$password |
string | |
$method |
int |
Exceptions:
Type | Description |
---|---|
ezcMailTransportException |
if there is no connection to the server or if already authenticated or if the authentication method is not accepted by the server or if the provided username/password combination did not work |
delete
Deletes the message with the message number $msgNum from the server.
The message number must be a valid identifier fetched with (example) listMessages().
Any future reference to the message-number associated with the message in a command generates an error.
Before calling this method, a connection to the POP3 server must be established and a user must be authenticated successfully.
Parameters:
Name | Type | Description |
---|---|---|
$msgNum |
int |
Exceptions:
Type | Description |
---|---|
ezcMailTransportException |
if there was no connection to the server or if not authenticated or if the server sent a negative response |
disconnect
Disconnects the transport from the POP3 server.
fetchAll
Returns an ezcMailPop3Set with all the messages on the server.
If $deleteFromServer is set to true the mail will be removed from the server after retrieval. If not it will be left.
Before calling this method, a connection to the POP3 server must be established and a user must be authenticated successfully.
Example:
- // parse $set with ezcMailParser
- $mails = $parser->parseMail( $set );
- foreach ( $mails as $mail )
- {
- // process $mail which is an ezcMail object
- }
Parameters:
Name | Type | Description |
---|---|---|
$deleteFromServer |
bool |
Exceptions:
Type | Description |
---|---|
ezcMailTransportException |
if there was no connection to the server or if not authenticated or if the server sent a negative response |
fetchByMessageNr
Returns an ezcMailPop3Set containing only the $number -th message from the server.
If $deleteFromServer is set to true the mail will be removed from the server after retrieval. If not it will be left.
Note: for POP3 the first message is 1 (so for $number = 0 the exception will be thrown).
Before calling this method, a connection to the POP3 server must be established and a user must be authenticated successfully.
Example:
- // $set can be parsed with ezcMailParser
Parameters:
Name | Type | Description |
---|---|---|
$number |
int | |
$deleteFromServer |
bool |
Exceptions:
Type | Description |
---|---|
ezcMailNoSuchMessageException |
if the message $number is out of range |
ezcMailTransportException |
if there was no connection to the server or if not authenticated or if the server sent a negative response |
fetchFromOffset
Returns an ezcMailPop3Set with $count messages starting from $offset from the server.
Fetches $count messages starting from the $offset and returns them as a ezcMailPop3Set. If $count is not specified or if it is 0, it fetches all messages starting from the $offset.
Before calling this method, a connection to the POP3 server must be established and a user must be authenticated successfully.
Example:
- // $set can be parsed with ezcMailParser
Parameters:
Name | Type | Description |
---|---|---|
$offset |
int | |
$count |
int | |
$deleteFromServer |
bool |
Exceptions:
Type | Description |
---|---|
ezcMailTransportException |
if there was no connection to the server or if not authenticated or if the server sent a negative response |
ezcMailInvalidLimitException |
if $count is negative |
ezcMailOffsetOutOfRangeException |
if $offset is outside of the existing range of messages |
isPositiveResponse
Returns true if the response from the server is a positive one.
Parameters:
Name | Type | Description |
---|---|---|
$line |
string |
listMessages
Returns an array of the message numbers on the server and the size of the messages in bytes.
The format of the returned array is:
- array( message_id => message_size );
Example:
- array( 2 => 1700, 5 => 1450, 6 => 21043 );
Before calling this method, a connection to the POP3 server must be established and a user must be authenticated successfully.
Exceptions:
Type | Description |
---|---|
ezcMailTransportException |
if there was no connection to the server or if not authenticated or if the server sent a negative response |
listUniqueIdentifiers
Returns the unique identifiers for messages on the POP3 server.
You can fetch the unique identifier for a specific message by providing the $msgNum parameter.
The unique identifier can be used to recognize mail from servers between requests. In contrast to the message numbers the unique numbers assigned to an email usually never changes.
Note: POP3 servers are not required to support this command and it may fail.
The format of the returned array is:
- array( message_num => unique_id );
Before calling this method, a connection to the POP3 server must be established and a user must be authenticated successfully.
Example:
- array( 1 => '000001fc4420e93a', 2 => '000001fd4420e93a' );
Parameters:
Name | Type | Description |
---|---|---|
$msgNum |
int |
Exceptions:
Type | Description |
---|---|
ezcMailTransportException |
if there was no connection to the server or if not authenticated or if the server sent a negative response |
noop
Sends a NOOP command to the server, use it to keep the connection alive.
Before calling this method, a connection to the POP3 server must be established and a user must be authenticated successfully.
Exceptions:
Type | Description |
---|---|
ezcMailTransportException |
if there was no connection to the server or if not authenticated or if the server sent a negative response |
status
Returns information about the messages on the server.
The information returned through the parameters is:
- $numMessages = number of messages
- $sizeMessages = sum of the messages sizes
Example of returning the status of messages on the server:
After running the above code, $numMessages and $sizeMessages will be populated with values.
Parameters:
Name | Type | Description |
---|---|---|
&$numMessages |
int | |
&$sizeMessages |
int |
Exceptions:
Type | Description |
---|---|
ezcMailTransportException |
if there was no connection to the server or if not authenticated or if the server sent a negative response |
top
Returns the headers and the $numLines first lines of the body of the mail with the message number $msgNum.
If the command failed or if it was not supported by the server an empty string is returned.
Note: POP3 servers are not required to support this command and it may fail.
Before calling this method, a connection to the POP3 server must be established and a user must be authenticated successfully.
Example of listing the mail headers of all the messages from the server:
- foreach ( $messages as $messageNr => $size )
- {
- $mail = $parser->parseMail( $set );
- $mail = $mail[0];
- echo "From: {$mail->from}, Subject: {$mail->subject}, Size: {$size}\n";
- }
Parameters:
Name | Type | Description |
---|---|---|
$msgNum |
int | |
$numLines |
int |
Exceptions:
Type | Description |
---|---|
ezcMailTransportException |
if there was no connection to the server or if not authenticated or if the server sent a negative response |