Foundations of Python Network Programming

(WallPaper) #1
259

Chapter 14

POP


POP, the Post Office Protocol, is a simple protocol for downloading e-mail from a server. It is typically used through
an e-mail client like Thunderbird or Outlook. You can reread the first few sections of Chapter 13 if you want the big
picture of where e-mail clients and protocols like POP fit into the history of Internet e-mail.
If you are tempted to use POP, then you should consider using IMAP instead; Chapter 15 will explain the features
that IMAP provides that make it a far more solid foundation for remote e-mail access than the primitive operations
supported by POP.
The most common implementation of POP is version 3, commonly referred to as POP3. Because version 3 is so
dominant, the terms POP and POP3 are practically interchangeable today.
POP’s chief benefit—and also its biggest weakness—is its simplicity. If you simply need to access a remote
mailbox, download any new e-mail that has appeared, and have the choice of deleting the e-mail after the download,
then POP will be perfect for you. You will be able to accomplish this task quickly and without complex code.
But download and delete are pretty much all that POP is good for. It does not support multiple mailboxes on the
remote side nor does it provide any reliable, persistent message identification. This means that you cannot use POP as
a protocol for e-mail synchronization, where you leave the original copy of each e-mail message on the server while
making a copy to read locally, because when you return to the server later, you cannot easily tell which messages you
have already downloaded. If you need this feature, you should check out IMAP, which will be covered in Chapter 15.
The Python Standard Library provides the poplib module, which provides a convenient interface for using POP.
This chapter will explain how to use poplib to connect to a POP server, gather summary information about a mailbox,
download messages, and delete the originals from the server. Once you know how to complete these four tasks, you
will have covered all of the standard POP features!
Note that the Python Standard Library does not provide the ability to act as a POP server, but only as a client.
If you need to implement a server, you will need to find a third-party Python package that provides POP server
functionality.


POP Server Compatibility


POP servers are notoriously bad at following standards. Standards also simply do not exist for some POP behaviors,
leaving the details up to the authors of server software. So while basic operations will generally work fine, certain
behaviors do vary from server to server.
For instance, some servers will mark all of your messages as read whenever you connect to the server—whether
you download any of them or not! Other servers will mark a message as read only when it is downloaded. Some
servers never mark any messages as read at all. The standard itself seems to assume the latter behavior, but is not clear
either way. Keep these differences in mind as you read this chapter.
Figure 14-1 illustrates a very simple POP conversation driven from Python.

Free download pdf