text is ascii, and the Python 3.1 email package is partly broken;
"""
def actions(self):
return [ ('Open', self.onOpenMailFile),
('Write', self.onWriteMail),
(' ', None), # 3.0: separators
('View', self.onViewFormatMail),
('Reply', self.onReplyMail),
('Fwd', self.onFwdMail),
('Save', self.onSaveMailFile),
('Delete', self.onDeleteMail),
(' ', None),
('Quit', self.quit) ]
def init(self, filename):
caller: do loadMailFileThread next
PyMailCommon.init(self)
self.filename = filename
self.openFileBusy = threadtools.ThreadCounter() # one per window
def loadMailFileThread(self):
"""
load or reload file and update window index list;
called on Open, startup, and possibly on Send if
sent-mail file appended is currently open; there
is always a bogus first item after the text split;
alt: [self.parseHeaders(m) for m in self.msglist];
could pop up a busy dialog, but quick for small files;
2.1: this is now threaded--else runs < 1sec for N meg
files, but can pause GUI N seconds if very large file;
Save now uses addSavedMails to append msg lists for
speed, not this reload; still called from Send just
because msg text unavailable - requires refactoring;
delete threaded too: prevent open and delete overlap;
"""
if self.openFileBusy:
don't allow parallel open/delete changes
errmsg = 'Cannot load, file is busy:\n"%s"' % self.filename
showerror(appname, errmsg)
else:
#self.listBox.insert(END, 'loading...') # error if user clicks
savetitle = self.title() # set by window class
self.title(appname + ' - ' + 'Loading...')
self.openFileBusy.incr()
threadtools.startThread(
action = self.loadMailFile,
args = (),
context = (savetitle,),
onExit = self.onLoadMailFileExit,
onFail = self.onLoadMailFileFail)
def loadMailFile(self):
run in a thread while GUI is active
open, read, parser may all raise excs: caught in thread utility
1078 | Chapter 14: The PyMailGUI Client