3.4. Code and Code Explanation

With POP3 decided upon and the database schema provided, I will now continue with the code. First I will discuss the POP3Client class, and then the remaining files that work together to provide the mailing list service.

3.4.1. The POP3 Client

The code needed to connect and communicate with the POP3 service is a prime candidate for OOP structuring. As a class, it will be easy to reuse the code in future projects. Besides the necessary constructor and connect methods, if each publically exposed method corresponds to a POP3 command, then the class's interface becomes intuitive to use as well.

POP3 was designed to be simple from its inception. There are only a few commands required to access a user's maildrop directory and retrieve messages. Table 3-1 lists the minimum commands that need to be implemented for a functional client.

Table 3-1. POP3 Commands
CommandDescription
USER usernameProvides the username needed in order to log into the mail account on the server
PASS passwordProvides the password needed in order to log into the mail account on the server
STATRetrieves the mail box's drop listing; the response indicates the number of messages in the inbox and their aggregate size
LIST (message id)Retrieves a scan listing for all messages in the inbox (or for a particular message if an optional message id is provided); the response gives message ids and sizes
RETR message idRetrieves a specific message from the server
DELE message idMarks a message to be ...

Get PHP and MySQL®: Create-Modify-Reuse now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.