os mkdir(savedirfullname os path join(savedirpartname(contypecontentself findonepart(partnamemessageif not isinstance(contentbytes) eneed bytes for rb content '(no content)decode= returns bytesopen(fullname'wb'write(contentbut some payloads none return (contypefullname enot str(contentdef partslist(selfmessage)"""return list of filenames for all parts of an already parsed messageusing same filename logic as savepartsbut do not store the part files here ""validparts self walknamedparts(messagereturn [filename for (filenamecontypepartin validpartsdef findonepart(selfpartnamemessage)""find and return part' contentgiven its nameintended to be used in conjunction with partslistwe could also mimetypes guess_type(partnameherewe could also avoid this search by saving in dict econtent may be str or bytes--convert as needed""for (filenamecontypepartin self walknamedparts(message)if filename =partnamecontent part get_payload(decode= does base ,qp,uu return (contypecontentmay be bytes text def decodedpayload(selfpartasstr=true)"" edecode text part bytes to unicode str for displayline wrapetc part is message(decode= undoes mime email encodings (base uuencodeqp)bytes decode(performs additional unicode text string decodingstries charset encoding name in message headers first (if presentand accurate)then tries platform defaults and few guesses before giving up with error string""payload part get_payload(decode= payload may be bytes if asstr and isinstance(payloadbytes)decode= returns bytes tries [enchdr part get_content_charset(try msg headers firstif enchdrtries +[enchdrtry headers first tries +[sys getdefaultencoding()same as bytes decode(tries +['latin ''utf 'try -bitincl ascii for trie in triestry utf (windows dflttrypayload payload decode(triegive it shotehbreak except (unicodeerrorlookuperror)lookuperrbad name pass elsethe mailtools utility package