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

(yzsuai) #1

load newly arrived, and forced reload after delete;
don't refetch viewed msgs if hdrs list same or extended;
retains cached msgs after a delete unless delete fails;
2.1: does quick check to see if msgnums still in sync
3.0: this is now subject to mailconfig.fetchlimit max;
"""
if forceReloads:
loadfrom = 1
self.msglist = [] # msg nums have changed
else:
loadfrom = len(self.msglist)+1 # continue from last load


only if loading newly arrived


if loadfrom != 1:
self.checkSynchError(self.allHdrs()) # raises except if bad


get all or newly arrived msgs


reply = self.downloadAllHeaders(progress, loadfrom)
headersList, msgSizes, loadedFull = reply


for (hdrs, size) in zip(headersList, msgSizes):
newmsg = MessageInfo(hdrs, size)
if loadedFull: # zip result may be empty
newmsg.fulltext = hdrs # got full msg if no 'top'
self.msglist.append(newmsg)


def getMessage(self, msgnum): # get raw msg text
cacheobj = self.msglist[msgnum-1] # add to cache if fetched
if not cacheobj.fulltext: # harmless if threaded
fulltext = self.downloadMessage(msgnum) # 3.0: simpler coding
cacheobj.fulltext = fulltext
return cacheobj.fulltext


def getMessages(self, msgnums, progress=None):
"""
prefetch full raw text of multiple messages, in thread;
2.1: does quick check to see if msgnums still in sync;
we can't get here unless the index list already loaded;
"""
self.checkSynchError(self.allHdrs()) # raises except if bad
nummsgs = len(msgnums) # adds messages to cache
for (ix, msgnum) in enumerate(msgnums): # some poss already there
if progress: progress(ix+1, nummsgs) # only connects if needed
self.getMessage(msgnum) # but may connect > once


def getSize(self, msgnum): # encapsulate cache struct
return self.msglist[msgnum-1].fullsize # it changed once already!


def isLoaded(self, msgnum):
return self.msglist[msgnum-1].fulltext


def allHdrs(self):
return [msg.hdrtext for msg in self.msglist]


def deleteMessages(self, msgnums, progress=None):


PyMailGUI Implementation| 1097
Free download pdf