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

(yzsuai) #1

up a simple unformatted display of the mail’s raw text (its full text is downloaded in a
thread if it hasn’t yet been fetched and cached). Part of the raw version of the mail I
sent to myself in Figure 14-18 is shown in Figure 14-28; in this edition, raw text is
displayed in a PyEdit pop-up window (its prior scrolled-text display is still present as
an option, but PyEdit adds tools such as searching, saves, and so on).


This raw text display can be useful to see special mail headers not shown in the for-
matted view. For instance, the optional X-Mailer header in the raw text display iden-
tifies the program that transmitted a message; PyMailGUI adds it automatically, along
with standard headers like From and To. Other headers are added as the mail is trans-
mitted: the Received headers name machines that the message was routed through on
its way to our email server, and Content-Type is added and parsed by Python’s email
package in response to calls from PyMailGUI.


And really, the raw text form is all there is to an email message—it’s what is transferred
from machine to machine when mail is sent. The nicely formatted display of the GUI’s
view windows simply parses out and decodes components from the mail’s raw text
with standard Python tools, and places them in the associated fields of the display.
Notice the Base64 encoding text of the image file at the end of Figure 14-28, for ex-
ample; it’s created when sent, transferred over the Internet, and decoded when fetched
to recreate the image’s original bytes. Quite a feat, but largely automatic with the code
and libraries invoked.


Email Replies and Forwards and Recipient Options


In addition to reading and writing email, PyMailGUI also lets users forward and reply
to incoming email sent from others. These are both just composition operations, but
they quote the original text and prefill header lines as appropriate. To reply to an email,
select its entry in the main window’s list and click the Reply button. If I reply to the


Figure 14-27. A PDF part opened in PyMailGUI


A PyMailGUI Demo| 1043
Free download pdf