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

(yzsuai) #1

is fetched - mail text is always Unicode str from that point on;
this may change in a future Python/email: see Chapter 13 for details;


3.0 change: inherits the new mailconfig.fetchlimit feature of mailtools,
which can be used to limit the maximum number of most recent headers or
full mails (if no TOP) fetched on each load request; note that this
feature is independent of the loadfrom used here to limit loads to
newly-arrived mails only, though it is applied at the same time: at
most fetchlimit newly-arrived mails are loaded;


3.0 change: though unlikely, it's not impossible that a user may trigger a
new fetch of a message that is currently being fetched in a thread, simply
by clicking the same message again (msg fetches, but not full index loads,
may overlap with other fetches and sends); this seems to be thread safe here,
but can lead to redundant and possibly parallel downloads of the same mail
which are pointless and seem odd (selecting all mails and pressing View
twice downloads most messages twice!); fixed by keeping track of fetches in
progress in the main GUI thread so that this overlap is no longer possible:
a message being fetched disables any fetch request which it is part of, and
parallel fetches are still allowed as long as their targets do not intersect;
##############################################################################
"""


from PP4E.Internet.Email import mailtools
from popuputil import askPasswordWindow


class MessageInfo:
"""
an item in the mail cache list
"""
def init(self, hdrtext, size):
self.hdrtext = hdrtext # fulltext is cached msg
self.fullsize = size # hdrtext is just the hdrs
self.fulltext = None # fulltext=hdrtext if no TOP


class MessageCache(mailtools.MailFetcher):
"""
keep track of already loaded headers and messages;
inherits server transfer methods from MailFetcher;
useful in other apps: no GUI or thread assumptions;


3.0: raw mail text bytes are decoded to str to be
parsed with Py3.1's email pkg and saved to files;
uses the local mailconfig module's encoding setting;
decoding happens automatically in mailtools on fetch;
"""
def init(self):
mailtools.MailFetcher.init(self) # 3.0: inherits fetchEncoding
self.msglist = [] # 3.0: inherits fetchlimit


def loadHeaders(self, forceReloads, progress=None):
"""
three cases to handle here: the initial full load,


1096 | Chapter 14: The PyMailGUI Client

Free download pdf