Of course, to script PyMailGUI on your own, you’ll need to be able to run it. PyMailGUI requires only a computer with some sort of Internet connectivity (a PC with a broadband or dial-up account will do) and an installed Python with the Tkinter extension enabled. The Windows port of Python has this capability, so Windows PC users should be able to run this program immediately by clicking its icon.
Two notes on running the system: first, you’ll want to change the file mailconfig.py in the program’s source directory to reflect your account’s parameters, if you wish to send or receive mail from a live server; more on this as we interact with the system.
Second, you can still experiment with the system without a live Internet connection—for a quick look at message view windows, use the main window’s Open buttons to open saved-mail files stored in the program’s SavedMail directory. In fact, the PyDemos launcher script at the top of the book’s examples directory forces PyMailGUI to open saved-mail files by passing filenames on the command line.
PyMailGUI is easily the largest program in this book, but it doesn’t introduce many library interfaces that we haven’t already seen in this book. For instance:
The PyMailGUI interface is built with Python’s Tkinter, using the familiar list-boxes, buttons, and text widgets we met earlier.
Python’semailpackage is applied to pull-out headers, text, and attachments of messages, and to compose the same.
Python’s POP and SMTP library modules are used to fetch, send, and delete mail over sockets.
Python threads, if installed in your Python interpreter, are put to work to avoid blocking during potentially overlapping, long-running mail operations.
We’re also going to reuse theTextEditorobject we wrote in Chapter 12 to view and compose messages, themailtools package’s tools we wrote in Chapter 14 to load and delete mail from the server, and themailconfigmodule strategy introduced in Chapter 14 to support end-user settings. PyMailGUI is largely an exercise in combining existing tools.
On the other hand, because this program is so long, we won’t exhaustively document all of its code. Instead, we’ll begin by describing how PyMailGUI works from an end user’s perspective—a brief demo of its windows in action. After that, we’ll list the system’s new source code modules without many additional comments, for further study.
Like most of the longer case studies in this book, this section assumes that you already know enough Python to make sense of the code on your own. If you’ve been reading this book linearly, you should also know enough about Tkinter, threads, and mail interfaces to understand the library tools applied here. If you get stuck, you may wish to brush up on the presentation of these topics earlier in the book.
New in This Edition
The 2.1 version of PyMailGUI presented in this third edition of the book is a complete rewrite of the 1.0 version of the prior edition. The main script in the second edition’s version was only some 500 lines long, and was really something of a toy or prototype, written mostly to serve as a book example. In this edition, PyMailGUI is a much more realistic and full-featured program that can be used for day-to-day email processing. It has grown to 2,200 source lines (3,800 including related modules that are reused). Among its new weapons are these:
MIME multipart mails with attachments may be both viewed and composed.
Mail transfers are no longer blocking, and may overlap in time.
Mail may be saved and processed offline from a local file.
Message parts may now be opened automatically within the GUI.
Multiple messages may be selected for processing in list windows.
Initial downloads fetch mail headers only; full mails are fetched on request.
View window headers and list window columns are configurable.
Deletions are performed immediately, not delayed until program exit.
Most server transfers report their progress in the GUI.
Long lines are intelligently wrapped in viewed and quoted text.
Fonts and colors in list and view windows may be configured by the user.
Authenticating SMTP mail-send servers that require login are supported.
Sent messages are saved in a local file, which may be opened in the GUI.
View windows intelligently pick a main text part to be displayed.
Already fetched mail headers and full mails are cached for speed.
Date strings and addresses in composed mails are formatted properly.
View windows now have quick-access buttons for attachments/parts (2.1).
Inbox out-of-sync errors are detected on deletes, and on index and mail loads (2.1).
Save-mail file loads and deletes are threaded, to avoid pauses for large files (2.1).
The last three items on this list were added in version 2.1; the rest were part of the 2.0 rewrite. Some of these changes were made simple by growth in standard library tools (e.g., support for attachments is straightforward with the newemailpackage), but most represent changes in PyMailGUI itself. There have also been a few genuine fixes: addresses are parsed more accurately, and date and time formats in sent mails are now standards conforming, because these tasks use new tools in theemail package.
Although there is still room for improvement (see the list at the end of this chapter), the program provides a full-featured interface, represents the most substantial example in this book, and serves to demonstrate a realistic application of the Python language. As its users often attest, Python may be fun to work with, but it’s also useful for writing practical and nontrivial software.
Please check back next week for the continuation of this article.