attachments can be viewed, sending binary and some text attachments is not supported
in the current version because of a Python 3.1 issue.
In other words, PyMailCGI is really something of a prototype, designed to illustrate
web scripting and system design concepts in this book, and serve as a springboard for
future work. As is, it’s nowhere near as far along the software evolutionary scale as
PyMailGUI. Still, we’ll see that PyMailCGI’s code factoring and reuse of existing mod-
ules allow it to implement much in a surprisingly small amount of code.
New in This Fourth Edition (Version 3.0)
In this fourth edition, PyMailCGI has been ported to run under Python 3.X. In addition,
this version inherits and employs a variety of new features from the mailtools module,
including mail header decoding and encoding, main mail text encoding, the ability to
limit mail headers fetched, and more. Notably, there is new support for Unicode and
Internationalized character sets as follows:
- For display, both a mail’s main text and its headers are decoded prior to viewing,
per email, MIME, and Unicode standards; text is decoded per mail headers and
headers are decoded per their content. - For sends, a mail’s main text, text attachments, and headers are all encoded per
the same standards, using UTF-8 as the default encoding if required. - For replies and forwards, headers copied into the quoted message text are also
decoded for display.
Note that this version relies upon web browsers’ ability to display arbitrary kinds of
Unicode text. It does not emit any sort of “meta” tag to declare encodings in the HTML
reply pages generated for mail view and composition. For instance, a properly formed
HTML document can often declare its encoding this way:
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1251">
</HEAD>
Such headers are omitted here. This is in part due to the fact that the mail might have
arbitrary and even mixed types of text among is message and headers, which might also
clash with encoding in the HTML of the reply itself. Consider a mail index list page
that displays headers of multiple mails; because each mail’s Subject and From might
be encoding in a different character set (one Russian, one Chinese, and so on), a single
encoding declaration won’t suffice (though UTF-8’s generality can often come to the
rescue). Resolving such mixed character set cases is left to the browser, which may
ultimately require assistance from the user in the form of encoding choices. Such dis-
plays work in PyMailGUI because we pass decoded Unicode text to the tkinter Text
widget, which handles arbitrary Unicode code points well. In PyMailCGI, we’re largely
finessing this issue to keep this example short.
The PyMailCGI Website | 1233