safe filename extension such as htmlcaveatimage/audio/video could be opened with the book' playfile pycould also do that if text viewer failswould start notepad on windows via startfilewebbrowser may handle most cases here toobut specific is better""def textpartencoding(fullfilename)"" map text part filename back to charset param in content-type header of part' messageso we can pass this on to the pyedit constructor for proper text displaywe could return the charset along with content-type from mailtools for text partsbut fewer changes are needed if this is handled as special case herepart content is saved in binary mode files by mailtools to avoid encoding issuesbut here the original part message is not directly availablewe need this mapping step to extract unicode encoding name if present ' pyedit now allows an explicit encoding name for file opensand resolves encoding on savessee for pyedit policiesit may ask user for an encoding if charset absent or failscaveatmove to mailtools mailparser to reuse for in pymailcgi""partname os path basename(fullfilenamefor (filenamecontypepartin self walknamedparts(self origmessage)if filename =partnamereturn part get_content_charset(none if not in header assert false'text part not foundshould never happen for (contypefullfilenamein partfilesmaintype contype split('/')[ extension os path splitext(fullfilename)[ basename os path basename(fullfilenameleft side not [- :strip dir html and xml textweb pagessome media if contype in ['text/html''text/xml']browseropened false if self askopen(appname'open "%sin browser?basename)trywebbrowser open_new('file://fullfilenamebrowseropened true exceptshowerror(appname'browser failedtrying editor'if not browseropened or not self skiptextonhtmlparttrytry pyedit to see encoding name and effect encoding textpartencoding(fullfilenametexteditor texteditormainpopup(parent=selfwintitle=% email part(encoding or '?')loadfirst=fullfilenameloadencode=encodingexceptshowerror(appname'error opening text viewer'text/plaintext/ -pythonetc eencodingmay fail the pymailgui client