Module: Interactive POP3 Mailbox Inspector
Credit: Xavier Defrang
Suppose you have a POP3 mailbox somewhere, perhaps on a slow connection, and need to examine messages, and perhaps mark them for deletion, in an interactive way. Perhaps you’re behind a slow Internet link and don’t want to wait for that funny 10-MB MPEG movie that you already received twice yesterday to be fully downloaded before you can read your mail. Or maybe there’s a peculiar malformed message that is hanging your MUA. This issue is best tackled interactively, but you need a helping script to let you examine some data about each message and determine which messages should be removed.
Instead of telneting to your POP server and trying to remember the
POP3 protocol commands (or hoping that the server implements
help), you can use the small script shown in Example 10-3 to inspect your mailbox and do some cleaning.
Basically, Python’s standard POP3 module,
poplib, remembers the protocol commands on your
behalf, and this script helps you use them appropriately.
Example 10-3 uses the
poplib module to connect to your mailbox. It
then prompts you about what to do with each undelivered message. You
can view the top of the message, leave it on the server, or mark it
for deletion. No particular tricks or hacks are used in this piece of
code: it’s a simple example of
poplib usage. In addition to being practically
useful in emergencies, it can show how poplib
works. The poplib.POP3 call returns an object that is ready for ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access