The class ezcMailPop3Transport implements functionality for handling POP3 mail servers.
The implementation supports most of the commands specified in:
The POP3 transport class allows developers to interface with a POP3 server.
Basic commands:
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? |
AUTH_APOP
= 2
|
APOP authorization. |
AUTH_PLAIN_TEXT
= 1
|
Plain text authorization. |
ezcMailPop3TransportOptions | read/write |
$options
Holds the options you can set to the POP3 transport. |
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. |
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. |
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:
Name | Type | Description |
---|---|---|
$server |
string | |
$port |
int | |
$options |
ezcMailPop3TransportOptions|array(string=>mixed) |
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 |
Destructs the POP3 transport object.
If there is an open connection to the POP3 server it is closed.
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:
Name | Type | Description |
---|---|---|
$user |
string | |
$password |
string | |
$method |
int |
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 |
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.
Name | Type | Description |
---|---|---|
$msgNum |
int |
Type | Description |
---|---|
ezcMailTransportException |
if there was no connection to the server or if not authenticated or if the server sent a negative response |
Disconnects the transport from the POP3 server.
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:
Name | Type | Description |
---|---|---|
$deleteFromServer |
bool |
Type | Description |
---|---|
ezcMailTransportException |
if there was no connection to the server or if not authenticated or if the server sent a negative response |
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:
Name | Type | Description |
---|---|---|
$number |
int | |
$deleteFromServer |
bool |
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 |
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:
Name | Type | Description |
---|---|---|
$offset |
int | |
$count |
int | |
$deleteFromServer |
bool |
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 |
Returns true if the response from the server is a positive one.
Name | Type | Description |
---|---|---|
$line |
string |
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:
Example:
Before calling this method, a connection to the POP3 server must be established and a user must be authenticated successfully.
Type | Description |
---|---|
ezcMailTransportException |
if there was no connection to the server or if not authenticated or if the server sent a negative response |
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:
Before calling this method, a connection to the POP3 server must be established and a user must be authenticated successfully.
Example:
Name | Type | Description |
---|---|---|
$msgNum |
int |
Type | Description |
---|---|
ezcMailTransportException |
if there was no connection to the server or if not authenticated or if the server sent a negative response |
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.
Type | Description |
---|---|
ezcMailTransportException |
if there was no connection to the server or if not authenticated or if the server sent a negative response |
Returns information about the messages on the server.
The information returned through the parameters is:
Example of returning the status of messages on the server:
After running the above code, $numMessages and $sizeMessages will be populated with values.
Name | Type | Description |
---|---|---|
&$numMessages |
int | |
&$sizeMessages |
int |
Type | Description |
---|---|
ezcMailTransportException |
if there was no connection to the server or if not authenticated or if the server sent a negative response |
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:
Name | Type | Description |
---|---|---|
$msgNum |
int | |
$numLines |
int |
Type | Description |
---|---|
ezcMailTransportException |
if there was no connection to the server or if not authenticated or if the server sent a negative response |