PyMailCGI also reuses parts of the mailtools module package and mailconfig.py
module we wrote in Chapter 13. The former of these is accessible to imports from
the PP4E package root, and the latter is largely copied by a local version in the
PyMailCgi directory so that it can differ between PyMailGUI and PyMailCGI. The
externs.py module is intended to hide these modules’ actual locations, in case
the install structure varies on some machines.
In fact, this system again demonstrates the powers of code reuse in a practical way. In
this edition, it gets a great deal of logic for free from the new mailtools package of
Chapter 13—message loading, sending, deleting, parsing, composing, decoding and
encoding, and attachments—even though that package’s modules were originally de-
veloped for the PyMailGUI program. When it came time to update PyMailCGI later,
tools for handling complex things such as attachments and message text searches were
already in place. See Chapter 13 for mailtools source code.
As usual, PyMailCGI also uses a variety of standard library modules: smtplib, poplib,
email., cgi, urllib., and the like. Thanks to the reuse of both custom and standard
library code, this system achieves much in a minimal amount of code. All told, Py-
MailCGI consists of just 846 lines of new code, including whitespace, comments, and
the top-level HTML file (see file linecounts.xls in this system’s source directory for
details; the prior edition’s version claimed to be some 835 new lines).
This compares favorably to the size of the PyMailGUI client-side “desktop” program
in Chapter 14, but most of this difference owes to the vastly more limited functionality
in PyMailCGI—there are no local save files, no transfer thread overlap, no message
caching, no inbox synchronization tests or recovery, no multiple-message selections,
no raw mail text views, and so on. Moreover, as the next section describes, PyMailCGI’s
Unicode policies are substantially more limited in this release, and although arbitrary
Figure 16-1. PyMailCGI contents
1232 | Chapter 16: The PyMailCGI Server