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

(yzsuai) #1

If you look back to the last main window shot, you’ll notice that there is only one new
email now—PyMailGUI is smart enough to download only the one new message’s
header text and tack it onto the end of the loaded email list. Mail send operations
automatically save sent mails in a save file that you name in your configuration module;
use Open to view sent messages in offline mode and Delete to clean up the sent mail
file if it grows too large (you can also save from the sent-mail file to another file to copy
mails into other save files per category).


Viewing Email and Attachments


Now let’s view the mail message that was sent and received. PyMailGUI lets us view
email in formatted or raw mode. First, highlight (single-click) the mail you want to see
in the main window, and press the View button. After the full message text is down-
loaded (unless it is already cached), a formatted mail viewer window like that shown
in Figure 14-18 appears. If multiple messages are selected, the View button will down-
load all that are not already cached (i.e., that have not already been fetched) and will
pop up a view window for each selected. Like all long-running operations, full message
downloads are run in parallel threads to avoid blocking.


Figure 14-18. PyMailGUI view incoming mail window


Python’s email module is used to parse out header lines from the raw text of the email
message; their text is placed in the fields in the top right of the window. The message’s
main text is fetched from its body and stuffed into a new TextEditor object for display
at the window bottom. PyMailGUI uses heuristics to extract the main text of the mes-
sage to display, if there is one; it does not blindly show the entire raw text of the mail.
HTML-only mail is handled specially, but I’ll defer details on this until later in this
demo.


A PyMailGUI Demo| 1037
Free download pdf