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

(yzsuai) #1

One caveat here: PyMailGUI can today display HTML in a web browser and extract
plain text from it, but it cannot display HTML directly in its own window and has no
support for editing it specially. These are enhancements that will have to await further
attention by other programmers who may find them useful.


Mail Content Internationalization Support


Our next advanced feature is something of an inevitable consequence of the Internet’s
success. As described earlier when summarizing version 3.0 changes, PyMailGUI fully
supports International character sets in mail content—both text part payloads and
email headers are decoded for display and encoded when sent, according to email,
MIME, and Unicode standards. This may be the most significant change in this version
of the program. Regrettably, capturing this in screenshots is a bit of a challenge and
you can get a better feel for how this pans out by running an Open on the following
included mail save file, viewing its messages in formatted and raw modes, starting
replies and forwards for them, and so on:


C:\...\PP4E\Internet\Email\PyMailGui\SavedMail\i18n-4E

To sample the flavor of this support here, Figure 14-40 shows the scene when this file
is opened, shown for variety here with one of the alternate account configurations
described the next section. This figure’s index list window and mail view windows
capture Russian and Chinese language messages sent to my email account (these were
unsolicited email of no particular significance, but suffice as reasonable test cases).
Notice how both message headers and text payload parts are decoded for display in
both the mail list window and the mail view windows.


Figure 14-41 shows portions of the raw text of the two fetched messages, obtained by
double-clicking their list entries (you can open these mails from the save file listed earlier
if you have trouble seeing their details as shown in this book). Notice how the body
text is encoded per both MIME and Unicode conventions—the headers at the top and
text at the bottom of these windows show the actual Base64 and quoted-printable
strings that must be decoded to achieve the nicely displayed output in Figure 14-40.


For the text parts, the information in the part’s header describes its content’s encoding
schemes. For instance, charset="gb2312" in the content type header identifies a Chinese
Unicode character set, and the transfer encoding header gives the part’s MIME encod-
ing type (e.g. base64).


The headers are encoded per i18n standards here as well—their content self-describes
their MIME and Unicode encodings. For example, the header prefix =?koi8-r?B means
Russian text, Base64 encoded. PyMailGUI is clever enough to decode both full headers
and the name fields of addresses for display, whether they are completely encoded (as
shown here) or contain just encoded substrings (as shown by other saved mails in the
version30-4E file in this example’s SavedMail directory).


A PyMailGUI Demo| 1055
Free download pdf