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

(yzsuai) #1

this may trigger full text encoding on sends, but the main text is
also already in fully decoded form: could be in any Unicode scheme;
"""
quoted = '\n-----Original Message-----\n'
for hdr in ('From', 'To', 'Subject', 'Date'):
rawhdr = message.get(hdr, '?')
if hdr not in ('From', 'To'):
dechdr = self.decodeHeader(rawhdr) # full value
else:
dechdr = self.decodeAddrHeader(rawhdr) # name parts only
quoted += '%s: %s\n' % (hdr, dechdr)
quoted += '\n' + maintext
quoted = '\n' + quoted.replace('\n', '\n> ')
return quoted


########################


subclass requirements


########################


def getMessages(self, msgnums, after): # used by view,save,reply,fwd
after() # redef if cache, thread test


plus okayToQuit?, any unique actions


def getMessage(self, msgnum): assert False # used by many: full mail text
def headersMaps(self): assert False # fillIndex: hdr mappings list
def mailSize(self, msgnum): assert False # fillIndex: size of msgnum
def doDelete(self): assert False # onDeleteMail: delete button


###############################################################################


main window - when viewing messages in local save file (or sent-mail file)


###############################################################################


class PyMailFile(PyMailCommon):
"""
customize PyMailCommon for viewing saved-mail file offline;
mixed with a Tk, Toplevel, or Frame, adds main mail listbox;
maps load, fetch, delete actions to local text file storage;
file opens and deletes here run in threads for large files;


save and send not threaded, because only append to file; save
is disabled if source or target file busy with load/delete;
save disables load, delete, save just because it is not run
in a thread (blocks GUI);


TBD: may need thread and O/S file locks if saves ever do run in
threads: saves could disable other threads with openFileBusy, but
file may not be open in GUI; file locks not sufficient, because
GUI updated too; TBD: appends to sent-mail file may require O/S
locks: as is, user gets error pop up if sent during load/del;


3.0: mail save files are now Unicode text, encoded per an encoding
name setting in the mailconfig module; this may not support worst
case scenarios of unusual or mixed encodings, but most full mail


PyMailGUI Implementation| 1077
Free download pdf