could use tempfile module (just like the HTML main text
part display code in onView of the list window class);
"""
try:
savedir = self.tempPartDir
message = self.origMessage
(contype, savepath) = self.saveOnePart(savedir, partname, message)
except:
showerror(appname, 'Error while writing part file')
printStack(sys.exc_info())
else:
self.openParts([(contype, os.path.abspath(savepath))]) # reuse
def onParts(self):
"""
show message part/attachments in pop-up window;
uses same file naming scheme as save on Split;
if non-multipart, single part = full body text
"""
partnames = self.partsList(self.origMessage)
msg = '\n'.join(['Message parts:\n'] + partnames)
showinfo(appname, msg)
def onSplit(self):
"""
pop up save dir dialog and save all parts/attachments there;
if desired, pop up HTML and multimedia parts in web browser,
text in TextEditor, and well-known doc types on windows;
could show parts in View windows where embedded text editor
would provide a save button, but most are not readable text;
"""
savedir = self.partsDialog.show() # class attr: at prior dir
if savedir: # tk dir chooser, not file
try:
partfiles = self.saveParts(savedir, self.origMessage)
except:
showerror(appname, 'Error while writing part files')
printStack(sys.exc_info())
else:
if self.okayToOpenParts: self.openParts(partfiles)
def askOpen(self, appname, prompt):
if not self.verifyPartOpens:
return True
else:
return askyesno(appname, prompt) # pop-up dialog
def openParts(self, partfiles):
"""
auto-open well known and safe file types, but only if verified
by the user in a pop up; other types must be opened manually
from save dir; at this point, the named parts have been already
MIME-decoded and saved as raw bytes in binary-mode files, but text
parts may be in any Unicode encoding; PyEdit needs to know the
encoding to decode, webbrowsers may have to guess or be told;
PyMailGUI Implementation| 1089