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

(yzsuai) #1

Also notice that the local file password option requires you to store your password
unencrypted in a file on the local client computer. This is convenient (you don’t need
to retype a password every time you check email), but it is not generally a good idea on
a machine you share with others, of course; leave this setting blank in mailconfig if you
prefer to always enter your password in a pop up.


Once PyMailGUI fetches your mail parameters and somehow obtains your password,
it will next attempt to pull down just the header text of all your incoming email from
your inbox on your POP email server. On subsequent loads, only newly arrived mails
are loaded, if any. To support obscenely large inboxes (like one of mine), the program
is also now clever enough to skip fetching headers for all but the last batch of messages,
whose size you can configure in mailconfig—they show up early in the mail list with
subject line “--mail skipped--”; see the 3.0 changes overview earlier for more details.


To save time, PyMailGUI fetches message header text only to populate the list window.
The full text of messages is fetched later only when a message is selected for viewing or
processing, and then only if the full text has not yet been fetched during this session.
PyMailGUI reuses the load-mail tools in the mailtools module of Chapter 13 to fetch
message header text, which in turn uses Python’s standard poplib module to retrieve
your email.


Threading Model


Now that we’re downloading mails, I need to explain the juggling act that PyMailGUI
performs to avoid becoming blocked and support operations that overlap in time. Ul-
timately, mail fetches run over sockets on relatively slow networks. While the download
is in progress, the rest of the GUI remains active—you may compose and send other
mails at the same time, for instance. To show its progress, the nonblocking dialog of
Figure 14-8 is displayed when the mail index is being fetched.


In general, all server transfers display such dialogs. Figure 14-9 shows the busy dialog
displayed while a full text download of five selected and uncached (not yet fetched)
mails is in progress, in response to a View action. After this download finishes, all five
pop up in individual view windows.


Such server transfers, and other long-running operations, are run in threads to avoid
blocking the GUI. They do not disable other actions from running in parallel, as long
as those actions would not conflict with a currently running thread. Multiple mail sends
and disjoint fetches can overlap in time, for instance, and can run in parallel with the


Figure 14-7. PyMailGUI password input dialog


A PyMailGUI Demo| 1027
Free download pdf