pages that let users read, reply to, forward, and delete existing email. Since the Send
function is the simplest, let’s start with its pages and scripts first.
The Message Composition Page
The root page Send function steps users through two other pages: one to edit a message
and one to confirm delivery. When you click on the Send link on the main page in
Figure 16-2, the Python CGI script in Example 16-3 runs on the web server.
Example 16-3. PP4E\Internet\Web\PyMailCgi\cgi-bin\onRootSendLink.py
#!/usr/bin/python
"""
################################################################################
On 'send' click in main root window: display composition page
################################################################################
"""
import commonhtml
from externs import mailconfig
commonhtml.editpage(kind='Write', headers={'From': mailconfig.myaddress})
No, this file wasn’t truncated; there’s not much to see in this script because all the
action has been encapsulated in the commonhtml and externs modules. All that we can
tell here is that the script calls something named editpage to generate a reply, passing
in something called myaddress for its “From” header.
That’s by design—by hiding details in shared utility modules we make top-level scripts
such as this much easier to read and write, avoid code redundancy, and achieve a
common look-and-feel to all our pages. There are no inputs to this script either; when
run, it produces a page for composing a new message, as shown in Figure 16-3.
Most of the composition page is self-explanatory—fill in headers and the main text of
the message (a “From” header and standard signature line are initialized from settings
in the mailconfig module, discussed further ahead). The Choose File buttons open file
selector dialogs, for picking an attachment. This page’s interface looks very different
from the PyMailGUI client program in Chapter 14, but it is functionally very similar.
Also notice the top and bottom of this page—for reasons explained in the next section,
they are going to look the same in all the pages of our system.
The Send Mail Script
As usual, the HTML of the edit page in Figure 16-3 names its handler script. When we
click its Send button, Example 16-4 runs on the server to process our inputs and send
the mail message.
1242 | Chapter 16: The PyMailCGI Server