[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1
outside this book’s scope, would imply a radically different and more complex program
structure, and should probably not be necessitated by a regression in Python 3.X in any
event. A rewrite (PyMailRIA?) will have to await a final verdict on Python 3.X CGI
support fixes.

New in the Prior Edition (Version 2.0)


In the third edition, PyMailCGI was upgraded to use the new mailtools module pack-
age of Chapter 13, employ the PyCrypto package for passwords if it is installed, support
viewing and sending message attachments, and run more efficiently. All these are in-
herited by version 3.0 as well.


We’ll meet these new features along the way, but the last two of these merit a few words
up front. Attachments are supported in a simplistic but usable fashion and use existing
mailtools package code for much of their operation:



  • For viewing attachments, message parts are split off the message and saved in local
    files on the server. Message view pages are then augmented with hyperlinks point-
    ing to the temporary files; when clicked, they open in whatever way your web
    browser opens the selected part’s file type.

  • For sending attachments, we use the HTML upload techniques presented near the
    end of Chapter 15. Mail edit pages now have file-upload controls, to allow a max-
    imum of three attachments. Selected files are uploaded to the server by the browser
    with the rest of the page as usual, saved in temporary files on the server, and added
    to the outgoing mail from the local files on the server by mailtools. As described
    in the note in the preceding section, sent attachments can only be compatibly en-
    coded text in version 3.0, not binary, though this includes encodable HTML files.


Both schemes would fail for multiple simultaneous users, but since PyMailCGI’s
configuration file scheme (described later in this chapter) already limits it to a single
username, this is a reasonable constraint. The links to temporary files generated for
attachment viewing also apply only to the last message selected, but this works if the
page flow is followed normally. Improving this for a multiuser scenario, as well as
adding additional features such as PyMailGUI’s local file save and open options, are
left as exercises.


For efficiency, this version of PyMailCGI also avoids repeated exhaustive mail down-
loads. In the prior version, the full text of all messages in an inbox was downloaded
every time you visited the list page and every time you selected a single message to view.
In this version, the list page downloads only the header text portion of each message,
and only a single message’s full text is downloaded when one is selected for viewing.
In addition, the headers fetch limits added to mailtools in the fourth edition of this
book are applied automatically to limit download time (earlier mails outside the set’s
size are ignored).


The PyMailCGI Website | 1235
Free download pdf